public async Task Persist(NagResponseInfo state, string nagId, StorageStrategies location) { if (state == null) throw new ArgumentNullException("state"); if (string.IsNullOrEmpty(nagId)) throw new ArgumentException("nagId cannot be null or empty", "nagId"); await _fileService.WriteFileAsync<NagResponseInfo>(GetFileName(nagId), state, location); }
public async Task<NagResponseInfo> Load(string nagId, StorageStrategies location) { if (string.IsNullOrEmpty(nagId)) throw new ArgumentException("nagId cannot be null or empty", "nagId"); try { if (await Exists(nagId, location)) { return await _fileService.ReadFileAsync<NagResponseInfo>(GetFileName(nagId), location); } return new NagResponseInfo() { NagId = nagId }; } catch { // if we are having trouble loading the response, suppress any nags // this should prevent nagging repeatedly because of an unknown error return new NagResponseInfo() { Suppress = true }; } }
public Task <bool> WriteFileAsync <T>(string key, T value, StorageStrategies location = StorageStrategies.Local) => _helper.WriteFileAsync <T>(key, value, location);
public Task <T> ReadFileAsync <T>(string key, StorageStrategies location = StorageStrategies.Local) => _helper.ReadFileAsync <T>(key, location);
public Task <bool> DeleteFileAsync(string key, StorageStrategies location = StorageStrategies.Local) => _helper.DeleteFileAsync(key, location);
private static async Task <IRandomAccessStream> CreateFileIAStreamAsync(string key, StorageStrategies location = StorageStrategies.Local, Windows.Storage.CreationCollisionOption option = Windows.Storage.CreationCollisionOption.OpenIfExists, FileAccessMode fileAccessMode = FileAccessMode.ReadWrite) { var _File = await CreateFileAsync(key, location, Windows.Storage.CreationCollisionOption.ReplaceExisting); if (_File != null) { return(await _File.OpenAsync(fileAccessMode)); } else { return(null); } }
private static async Task <Windows.Storage.StorageFile> CreateFileAsync(string key, StorageStrategies location = StorageStrategies.Local, Windows.Storage.CreationCollisionOption option = Windows.Storage.CreationCollisionOption.OpenIfExists) { switch (location) { case StorageStrategies.Local: return(await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(key, option)); case StorageStrategies.Roaming: return(await Windows.Storage.ApplicationData.Current.RoamingFolder.CreateFileAsync(key, option)); case StorageStrategies.Temporary: return(await Windows.Storage.ApplicationData.Current.TemporaryFolder.CreateFileAsync(key, option)); default: throw new NotSupportedException(location.ToString()); } }
public async Task<NagResponseInfo> GetResponse(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Load(nagId, location);
public async Task DeleteResponse(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Delete(nagId, location);
public async Task<bool> Exists(string nagId, StorageStrategies location) { if (string.IsNullOrEmpty(nagId)) throw new ArgumentException("nagId cannot be null or empty", "nagId"); return await _fileService.FileExistsAsync(string.Format(StateFileNameTemplate, nagId), location); }
public static async Task <StorageFolder> EnsureFolderExistsAsync(string path, StorageStrategies location = StorageStrategies.Local) { switch (location) { case StorageStrategies.Roaming: return(await EnsureFolderExistsAsync(path, ApplicationData.Current.RoamingFolder).ConfigureAwait(false)); case StorageStrategies.Temporary: return(await EnsureFolderExistsAsync(path, ApplicationData.Current.TemporaryFolder).ConfigureAwait(false)); default: return(await EnsureFolderExistsAsync(path, ApplicationData.Current.LocalFolder).ConfigureAwait(false)); } }
public async Task <NagResponseInfo> GetResponse(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Load(nagId, location);
public async Task <bool> ResponseExists(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Exists(nagId, location);
public static async void WriteFileFireAndForget <T>(string key, T value, StorageStrategies location) { await WriteFileAsync(key, value, location); }
/// <summary>Returns if a file is found in the specified storage strategy</summary> /// <param name="key">Path of the file in storage</param> /// <param name="location">Location storage strategy</param> /// <param name="path">Custom path for storage. Only accessible if rights have been granted</param> /// <returns>Boolean: true if found, false if not found</returns> public async Task <bool> FileExistsAsync(string key, StorageStrategies location = StorageStrategies.Local, string path = null) => (await GetIfFileExistsAsync(key, location, path)) != null;
public async Task Delete(string nagId, StorageStrategies location) { if (string.IsNullOrEmpty(nagId)) throw new ArgumentException("nagId cannot be null or empty", "nagId"); await _fileService.DeleteFileAsync(GetFileName(nagId), location); }
public async Task<bool> ResponseExists(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Exists(nagId, location);
public FileService(StorageStrategies location) : this() => DefaultLocation = location;
/// <summary>Returns if a file is found in the specified storage strategy</summary> /// <param name="key">Path of the file in storage</param> /// <param name="location">Location storage strategy</param> /// <returns>Boolean: true if found, false if not found</returns> public static async Task <bool> FileExistsAsync(string key, StorageStrategies location = StorageStrategies.Local) { return((await GetIfFileExistsAsync(key, location)) != null); }
public Task <bool> FileExistsAsync(string key, StorageStrategies location = StorageStrategies.Local) => _helper.FileExistsAsync(key, location);
public static async void DeleteFileFireAndForget(string key, StorageStrategies location) { await DeleteFileAsync(key, location); }
public static async void WriteFileFireAndForget(string key, string body, StorageStrategies location) { await WriteFileAsync(key, body, location); }