/// <summary> /// Gets the appropriate <see cref="global::Windows.Storage.StorageFolder"/> for the requested /// <see cref="Wygwam.Windows.Storage.StorageType"/>. /// </summary> /// <param name="storageType">The requested storage type.</param> /// <returns>The <see cref="global::Windows.Storage.StorageFolder"/> for the requested /// <see cref="Wygwam.Windows.Storage.StorageType"/>.</returns> private static async Task <StorageFolder> GetDataFolder(Storage.StorageType storageType, string path) { var directory = Path.GetDirectoryName(path); if (string.IsNullOrEmpty(directory) || directory.Equals("\\") || directory.Equals("/") || directory.Equals("//")) { return(ApplicationData.Current.LocalFolder); } StorageFolder folder = await GetDataFolder(storageType, directory); var folders = await folder.GetFoldersAsync(); string folderName = Path.GetFileName(directory); var tmpFolder = (from f in folders where string.Equals(f.Name, folderName, StringComparison.InvariantCultureIgnoreCase) select f).FirstOrDefault(); if (tmpFolder == null) { tmpFolder = await folder.CreateFolderAsync(folderName); } return(tmpFolder); }
/// <summary> /// Gets the appropriate <see cref="global::Windows.Storage.ApplicationDataContainer"/> for the requested /// <see cref="Wygwam.Windows.Storage.StorageType"/>. /// </summary> /// <param name="storageType">The requested storage type.</param> /// <returns>The <see cref="global::Windows.Storage.ApplicationDataContainer"/> for the requested /// <see cref="Wygwam.Windows.Storage.StorageType"/>.</returns> private static ApplicationDataContainer GetSettingsContainer(Storage.StorageType storageType) { switch (storageType) { case Wygwam.Windows.Storage.StorageType.Roaming: return(ApplicationData.Current.RoamingSettings); case Wygwam.Windows.Storage.StorageType.Temp: case Wygwam.Windows.Storage.StorageType.Local: default: return(ApplicationData.Current.LocalSettings); } }
public static void OnHeadFolderCreated(Scope scope) { API_Proxy_BackendConsole apiKrios = scope.GetApiKrios(); TenantKrios tenant = scope.Get <TenantKrios>("tenant"); Pool p = scope.Get <Pool>("pool"); //Get uem storage type. Storage.StorageType storageProdType = Storage.StorageType.Get(apiKrios, Storage.StorageType.UemType); //Instantiate a storage named "UEM" with the template storageProdType. Storage storageUem = new Storage(tenant.Id, p.Id, storageProdType, "UEM"); scope.GetEventChannel().WaitOn(storageUem.Create(apiKrios), scope, OnUemStorageCreated); }
/// <summary> /// Called when <see cref="M:LoadSettingAsync{T}"/> is executed to load data from the settings container. /// </summary> /// <typeparam name="T">The type of the stored value.</typeparam> /// <param name="key">The string that was used as a key for the desired value.</param> /// <param name="storageType">Defines the desired storage type. Not all implementations support all storage types.</param> /// <returns>The value associated to the specified key.</returns> protected override Task <T> OnLoadSettingAsync <T>(string key, Storage.StorageType storageType) { return(Task.Run <T>(() => { var store = GetSettingsContainer(storageType); if (!store.Contains(key)) { return default(T); } return (T)store[key]; })); }
/// <summary> /// Called when <see cref="M:RemoveSettingAsync" /> is executed to delete a value from the settings container. /// </summary> /// <param name="key">The string that identifies the value to delete.</param> /// <param name="storageType">Defines the desired storage type. Not all implementations support all storage types.</param> /// <returns> /// <c>true</c> if the value was successfully deleted. /// </returns> protected override Task <bool> OnRemoveSettingAsync(string key, Storage.StorageType storageType) { return(Task.Run <bool>(() => { var store = GetSettingsContainer(storageType); if (store.Contains(key)) { return store.Remove(key); } return false; })); }
/// <summary> /// Gets the appropriate <see cref="global::Windows.Storage.StorageFolder"/> for the requested /// <see cref="Wygwam.Windows.Storage.StorageType"/>. /// </summary> /// <param name="storageType">The requested storage type.</param> /// <returns>The <see cref="global::Windows.Storage.StorageFolder"/> for the requested /// <see cref="Wygwam.Windows.Storage.StorageType"/>.</returns> private static StorageFolder GetDataFolder(Storage.StorageType storageType) { switch (storageType) { case Wygwam.Windows.Storage.StorageType.Roaming: return(ApplicationData.Current.RoamingFolder); case Wygwam.Windows.Storage.StorageType.Temp: return(ApplicationData.Current.TemporaryFolder); case Wygwam.Windows.Storage.StorageType.Local: default: return(ApplicationData.Current.LocalFolder); } }
/// <summary> /// Called when <see cref="M:DeleteDataAsync" /> is executed to delete an object from persistent storage. /// </summary> /// <param name="path">The string that identifies where the object is stored.</param> /// <param name="storageType">Defines the desired storage type. Not all implementations support all storage types.</param> /// <returns> /// <c>true</c> if the object was successfully deleted. /// </returns> protected override async Task <bool> OnDeleteDataAsync(string path, Storage.StorageType storageType) { try { var file = await(await GetDataFolder(storageType, path)).GetItemAsync(Path.GetFileName(path)); await file.DeleteAsync(); return(true); } catch { } return(false); }
public static void OnUserADKomodoCreated(Scope scope) { API_Proxy_BackendConsole apiKrios = scope.GetApiKrios(); UserADKomodo createdUser = scope.GetCreatedResource <UserADKomodo>(); scope.Add("createdUser", createdUser); TenantKrios tenant = scope.Get <TenantKrios>("tenant"); Pool p = scope.Get <Pool>("pool"); //Get production storage type. StorageTypes are templates of Storage. Storage.StorageType storageProdType = Storage.StorageType.Get(apiKrios, Storage.StorageType.ProdType); //Instantiate a storage named "Production" with the template storageProdType. Storage storageProd = new Storage(tenant.Id, p.Id, storageProdType, "Production"); scope.GetEventChannel().WaitOn(storageProd.Create(apiKrios), scope, OnStorageCreated); }
/// <summary> /// Called when <see cref="M:SaveSettingAsync" /> is executed to store data in the settings container. /// </summary> /// <param name="key">The string to use as a key for the element to save.</param> /// <param name="data">The object that will be saved.</param> /// <param name="storageType">Defines the desired storage type. Not all implementations support all storage types.</param> /// <returns> /// <c>true</c> if the value was successfully stored. /// </returns> protected override Task <bool> OnSaveSettingAsync(string key, object data, Storage.StorageType storageType) { return(Task.Run <bool>(() => { if (null == data) { return false; } var store = GetSettingsContainer(storageType); if (store.Contains(key)) { store[key] = data; } else { store.Add(key, data); } return true; })); }
/// <summary> /// Gets the appropriate <see cref="global::Windows.Storage.ApplicationDataContainer"/> for the requested /// <see cref="Wygwam.Windows.Storage.StorageType"/>. /// </summary> /// <param name="storageType">The requested storage type.</param> /// <returns>The <see cref="global::Windows.Storage.ApplicationDataContainer"/> for the requested /// <see cref="Wygwam.Windows.Storage.StorageType"/>.</returns> private static IsolatedStorageSettings GetSettingsContainer(Storage.StorageType storageType) { return(IsolatedStorageSettings.ApplicationSettings); }
/// <summary> /// Called when <see cref="M:GetDataFoldersAsync" /> is executed to retrieve a list of subfolders from persistent storage. /// </summary> /// <param name="path">The path of the parent folder.</param> /// <param name="storageType">Defines the desired storage type. Not all implementations support all storage types.</param> /// <returns> /// A list of the names of the subfolders contained in the requested folder. /// </returns> protected override async Task <IEnumerable <string> > OnGetDataFoldersAsync(string path, Storage.StorageType storageType) { var folder = await(await GetDataFolder(storageType, path)).GetFolderAsync(Path.GetFileName(path)); return((await folder.GetFoldersAsync()).Select(f => f.Name)); }
/// <summary> /// Called when <see cref="M:LoadDataAsync"/> is executed to load an object from persistent storage. /// </summary> /// <typeparam name="T">The type of the stored value.</typeparam> /// <param name="path">The string that identifies where the object is stored.</param> /// <param name="serializer">The implementation of <see cref="Wygwam.Windows.Storage.IDataSerializer"/> that will be used to deserialize the specified object.</param> /// <param name="storageType">Defines the desired storage type. Not all implementations support all storage types.</param> /// <returns> /// <c>true</c> if the object was successfully retrieved. /// </returns> protected override async Task <T> OnLoadDataAsync <T>(string path, Wygwam.Windows.Storage.IDataSerializer serializer, Storage.StorageType storageType) { try { var file = await(await GetDataFolder(storageType, path)).GetFileAsync(Path.GetFileName(path)); using (var inStream = await file.OpenSequentialReadAsync()) { return(serializer.Deserialize <T>(inStream.AsStreamForRead())); } } catch { return(default(T)); } }
/// <summary> /// Called when <see cref="M:SaveDataAsync" /> is executed to store an object in persistent storage. /// </summary> /// <param name="path">The string that identifies where the object will be stored.</param> /// <param name="data">The object that will be serialized and stored.</param> /// <param name="serializer">The implementation of <see cref="Wygwam.Windows.Storage.IDataSerializer" /> that will be used to serialize the specified object.</param> /// <param name="storageType">Defines the desired storage type. Not all implementations support all storage types.</param> /// <returns> /// <c>true</c> if the object was successfully persisted. /// </returns> protected override async Task <bool> OnSaveDataAsync(string path, object data, Wygwam.Windows.Storage.IDataSerializer serializer, Storage.StorageType storageType) { try { var file = await(await GetDataFolder(storageType, path)).CreateFileAsync(Path.GetFileName(path), _defaultCollisionPolicy); using (var fileStream = await file.OpenStreamForWriteAsync()) { serializer.Serialize(fileStream, data); await fileStream.FlushAsync(); } return(true); } catch { } return(false); }