public void StoreMetadata(AssetType type, string path, IAssetMetadata metadata) { var metaDataPath = GetMetadataFilePath(type, path); var data = JsonConvert.SerializeObject(metadata); File.WriteAllText(metaDataPath, data); }
public void StoreMetadata(AssetType type, string path, IAssetMetadata metadata) { var metaDataPath = GetMetadataFilePath(type, path); var data = JsonConvert.SerializeObject(metadata); File.WriteAllText(metaDataPath, data); }
public ScenarioAsset(string path, IAssetMetadata metadata, AssetWithImageCachedData cachedData) : base(path, metadata, cachedData, AssetType.Scenario) { if (cachedData == null) { throw new ArgumentNullException(nameof(cachedData)); } _cachedData = cachedData; }
protected Asset(string path, IAssetMetadata metadata, IAssetCachedData cachedData, AssetType type) { if (path == null) throw new ArgumentNullException(nameof(path)); if (cachedData == null) throw new ArgumentNullException(nameof(cachedData)); InstallationPath = path; _metadata = metadata; _cachedData = cachedData; Type = type; }
protected Asset(string path, IAssetMetadata metadata, IAssetCachedData cachedData, AssetType type) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (cachedData == null) { throw new ArgumentNullException(nameof(cachedData)); } InstallationPath = path; _metadata = metadata; _cachedData = cachedData; Type = type; }
public async Task<IAssetCachedData> GetData(AssetType type, IAssetMetadata metadata, string path) { var metaType = GetCachedDataType(type); var metaDataPath = GetCachedDataFilePath(type, path); if (!File.Exists(metaDataPath)) { var newInstance = await GenerateCachableData(type, metadata, path); StoreData(type, path, newInstance); return newInstance; } var data = File.ReadAllText(metaDataPath); return JsonConvert.DeserializeObject(data, metaType) as IAssetCachedData; }
public async Task <IAssetCachedData> GetData(AssetType type, IAssetMetadata metadata, string path) { var metaType = GetCachedDataType(type); var metaDataPath = GetCachedDataFilePath(type, path); if (!File.Exists(metaDataPath)) { var newInstance = await GenerateCachableData(type, metadata, path); StoreData(type, path, newInstance); return(newInstance); } var data = File.ReadAllText(metaDataPath); return(JsonConvert.DeserializeObject(data, metaType) as IAssetCachedData); }
public BlueprintAsset(string path, IAssetMetadata metadata, IAssetCachedData cachedData) : base(path, metadata, cachedData, AssetType.Blueprint) { }
public SavegameAsset(string path, IAssetMetadata metadata, AssetWithImageCachedData cachedData) : base(path, metadata, cachedData, AssetType.Savegame) { if (cachedData == null) throw new ArgumentNullException(nameof(cachedData)); _cachedData = cachedData; }
public BlueprintAsset(string path, IAssetMetadata metadata, IAssetCachedData cachedData) : base(path, metadata, cachedData, AssetType.Blueprint) { }
private async Task <IAssetCachedData> GenerateCachableData(AssetType type, IAssetMetadata metadata, string path) { try { switch (type) { case AssetType.Blueprint: var blueprint = BlueprintConverter.DeserializeFromFile(path); return(new AssetCachedData { Name = blueprint.Header.Name }); case AssetType.Mod: if (metadata?.Id == null) { return(new AssetWithImageCachedData()); } var asset = await _website.API.GetAsset(metadata.Id); using (var memoryStream = new MemoryStream()) { try { using (var image = await asset.Image.Data.Get()) { if (image == null) { return(new AssetWithImageCachedData { ImageBase64 = null }); } image.Save(memoryStream, ImageFormat.Png); return(new AssetWithImageCachedData { ImageBase64 = Convert.ToBase64String(memoryStream.ToArray()) }); } } catch (Exception e) { _log.WriteLine("Failed to load image!"); _log.WriteException(e); return(new AssetWithImageCachedData()); } } case AssetType.Savegame: var savegame = SavegameConverter.DeserializeFromFile(path); using (var stream = new MemoryStream()) { using (var thumbnail = savegame.Screenshot) { thumbnail.Save(stream, ImageFormat.Png); } return(new AssetWithImageCachedData { Name = savegame.Header.Name, ImageBase64 = Convert.ToBase64String(stream.ToArray()) }); } default: throw new Exception("Unsupported type"); } } catch (Exception e) { _log.WriteException(e); return(new AssetCachedData { Name = "Failed to open image for " + path }); } }
private async Task<IAssetCachedData> GenerateCachableData(AssetType type, IAssetMetadata metadata, string path) { try { switch (type) { case AssetType.Blueprint: var blueprint = BlueprintConverter.DeserializeFromFile(path); return new AssetCachedData { Name = blueprint.Header.Name }; case AssetType.Mod: if (metadata?.Id == null) return new AssetWithImageCachedData(); var asset = await _website.API.GetAsset(metadata.Id); using (var memoryStream = new MemoryStream()) { try { using (var image = await asset.Image.Data.Get()) { if (image == null) { return new AssetWithImageCachedData { ImageBase64 = null }; } image.Save(memoryStream, ImageFormat.Png); return new AssetWithImageCachedData { ImageBase64 = Convert.ToBase64String(memoryStream.ToArray()) }; } } catch (Exception e) { _log.WriteLine("Failed to load image!"); _log.WriteException(e); return new AssetWithImageCachedData(); } } case AssetType.Savegame: var savegame = SavegameConverter.DeserializeFromFile(path); using (var stream = new MemoryStream()) { using (var thumbnail = savegame.Screenshot) { thumbnail.Save(stream, ImageFormat.Png); } return new AssetWithImageCachedData { Name = savegame.Header.Name, ImageBase64 = Convert.ToBase64String(stream.ToArray()) }; } default: throw new Exception("Unsupported type"); } } catch (Exception e) { _log.WriteException(e); return new AssetCachedData { Name = "Failed to open image for " + path }; } }