private string ConvertToJSON(IBlueprintStorage blueprintStorage) { string json = JsonConvert.SerializeObject((Blueprint)blueprintStorage.Blueprint); blueprintStorage.Data = CryptoService.Encrypt(json, blueprintStorage.BlueprintRegistryItem.Key); return(JsonConvert.SerializeObject(blueprintStorage)); }
private void SyncSettingsFromBlueprintToStorageObjects(IBlueprintStorage blueprintStorage) { if (string.IsNullOrWhiteSpace(blueprintStorage.Blueprint.Name)) { blueprintStorage.Blueprint.Name = $"Id:{blueprintStorage.Id}"; } blueprintStorage.BlueprintRegistryItem.Name = blueprintStorage.Blueprint.Name; }
public async Task VerifySaveBlueprint() { IBlueprintLoaderService service = GetBlueprintLoaderService(out IAppSettings appSettings); IBlueprintStorage storage = GetBlueprintStorage("Test A"); Assert.True(await service.SaveBlueprint(storage)); // blueprint is expected to be added to registry list that is used to remember and load blueprints from Assert.Single(appSettings.BlueprintList); }
public async Task VerifyLoadBlueprint() { IBlueprintLoaderService service = GetBlueprintLoaderService(out IAppSettings appSettings); // First we need to save our test blueprint so we have something to load IBlueprintStorage storage = GetBlueprintStorage("Test A"); Assert.True(await service.SaveBlueprint(storage)); // Load first blueprint from list in app settings BlueprintStorage loaded = await service.LoadBlueprint(appSettings.BlueprintList[0].Id); Assert.Equal(storage.Id, loaded.BlueprintRegistryItem.Id); Assert.Equal(storage.Blueprint.Name, loaded.Blueprint.Name); }
public void OpenBlueprint(Guid blueprintId) { ChangeContentPage(Constants.ContentPage.Loading); IBlueprintStorage storage = LoaderService.LoadBlueprint(blueprintId).GetAwaiter().GetResult(); if (storage == null) { UpdateStatus($"Failed to open Blueprint!"); ChangeContentPage(Constants.ContentPage.Error); return; } ActiveBlueprintStorage = storage; ChangeContentPage(Constants.ContentPage.ViewBlueprint); ListManager.PrependRegistryItemToList((BlueprintRegistryItem)ActiveBlueprintStorage.BlueprintRegistryItem); OnLoadedBlueprint?.Invoke(this, ActiveBlueprintStorage.Blueprint); }
private Task <bool> SaveBlueprintToLocalFileSystem(IBlueprintStorage blueprintStorage) { if (string.IsNullOrWhiteSpace(blueprintStorage.BlueprintRegistryItem.Key)) { blueprintStorage.BlueprintRegistryItem.Key = Guid.NewGuid().ToString(); } if (!FileSystem.IsValidDirectory(blueprintStorage.BlueprintRegistryItem.FilePath)) { return(Task.FromResult(false)); } string fileJson = ConvertToJSON(blueprintStorage); RegistryItemListManager.PrependRegistryItemToList((BlueprintRegistryItem)blueprintStorage.BlueprintRegistryItem); FileSystem.SaveFileToDirectory(blueprintStorage.BlueprintRegistryItem.FilePath, fileJson); return(Task.FromResult(true)); }
public async Task <bool> SaveBlueprint(IBlueprintStorage blueprintStorage) { SyncSettingsFromBlueprintToStorageObjects(blueprintStorage); return(await SaveBlueprintToLocalFileSystem(blueprintStorage)); }