Skip to content

Commit

Permalink
Internal use of new conversion methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kf6kjg committed Nov 22, 2017
1 parent 5bd4112 commit dd3e42c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
35 changes: 2 additions & 33 deletions Source/Chattel/AssetServerWHIP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ namespace Chattel {
internal class AssetServerWHIP : IAssetServer {
private static readonly ILog LOG = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

// Unix-epoch starts at January 1st 1970, 00:00:00 UTC. And all our times in the server are (or at least should be) in UTC.
private static readonly DateTime UNIX_EPOCH = DateTime.ParseExact("1970-01-01 00:00:00 +0", "yyyy-MM-dd hh:mm:ss z", DateTimeFormatInfo.InvariantInfo).ToUniversalTime();

public string Host { get; private set; }
public int Port { get; private set; }
public string Password { get; private set; }
Expand Down Expand Up @@ -90,32 +87,12 @@ public StratusAsset RequestAssetSync(UUID assetID) {
return null;
}

return new StratusAsset {
Id = assetID.Guid,
Type = (sbyte)whipAsset.Type,
Local = whipAsset.Local,
Temporary = whipAsset.Temporary,
CreateTime = UnixToUTCDateTime(whipAsset.CreateTime),
Name = whipAsset.Name,
Description = whipAsset.Description,
Data = whipAsset.Data,
};
return StratusAsset.FromWHIPAsset(whipAsset);
}

public void StoreAssetSync(StratusAsset asset) {
var whipAsset = new Asset(
asset.Id.ToString(),
(byte)asset.Type,
asset.Local,
asset.Temporary,
(int)UTCDateTimeToEpoch(asset.CreateTime), // At some point this'll need to be corrected to a 64bit timestamp...
asset.Name,
asset.Description,
asset.Data
);

try {
_provider.PutAsset(whipAsset);
_provider.PutAsset(StratusAsset.ToWHIPAsset(asset));
}
catch (AssetServerError e) {
LOG.Error($"[WHIP_SERVER] [{_serverHandle}] Error sending asset to server.", e);
Expand All @@ -126,13 +103,5 @@ public void StoreAssetSync(StratusAsset asset) {
throw new AssetWriteException(asset.Id, e);
}
}

private static DateTime UnixToUTCDateTime(long seconds) {
return UNIX_EPOCH.AddSeconds(seconds);
}

private static long UTCDateTimeToEpoch(DateTime timestamp) {
return (long)(timestamp.Subtract(UNIX_EPOCH)).TotalSeconds;
}
}
}
2 changes: 1 addition & 1 deletion Source/Chattel/CloudFilesProvider/StratusAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static StratusAsset FromWHIPAsset(Whip.Client.Asset whipAsset) {
};
}

public static Whip.Client.Asset FromWHIPAsset(StratusAsset asset) {
public static Whip.Client.Asset ToWHIPAsset(StratusAsset asset) {
return new Whip.Client.Asset(
asset.Id.ToString(),
(byte)asset.Type,
Expand Down

0 comments on commit dd3e42c

Please sign in to comment.