Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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 };
            }
        }
Exemplo n.º 3
0
 public Task <bool> WriteFileAsync <T>(string key, T value, StorageStrategies location = StorageStrategies.Local) => _helper.WriteFileAsync <T>(key, value, location);
Exemplo n.º 4
0
 public Task <T> ReadFileAsync <T>(string key, StorageStrategies location = StorageStrategies.Local) => _helper.ReadFileAsync <T>(key, location);
Exemplo n.º 5
0
 public Task <bool> DeleteFileAsync(string key, StorageStrategies location = StorageStrategies.Local) => _helper.DeleteFileAsync(key, location);
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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());
            }
        }
Exemplo n.º 8
0
 public async Task<NagResponseInfo> GetResponse(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Load(nagId, location);
Exemplo n.º 9
0
 public async Task DeleteResponse(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Delete(nagId, location);
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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));
            }
        }
Exemplo n.º 12
0
 public async Task <NagResponseInfo> GetResponse(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Load(nagId, location);
Exemplo n.º 13
0
 public async Task <bool> ResponseExists(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Exists(nagId, location);
Exemplo n.º 14
0
 public async Task DeleteResponse(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Delete(nagId, location);
Exemplo n.º 15
0
 public static async void WriteFileFireAndForget <T>(string key, T value, StorageStrategies location)
 {
     await WriteFileAsync(key, value, location);
 }
Exemplo n.º 16
0
 /// <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;
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
 public async Task<bool> ResponseExists(string nagId, StorageStrategies location = StorageStrategies.Local) => await _nagHelper.Exists(nagId, location);
Exemplo n.º 19
0
 public FileService(StorageStrategies location) : this() => DefaultLocation = location;
Exemplo n.º 20
0
 /// <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);
 }
Exemplo n.º 21
0
 public Task <bool> FileExistsAsync(string key, StorageStrategies location = StorageStrategies.Local) => _helper.FileExistsAsync(key, location);
Exemplo n.º 22
0
 public static async void DeleteFileFireAndForget(string key, StorageStrategies location)
 {
     await DeleteFileAsync(key, location);
 }
Exemplo n.º 23
0
 public static async void WriteFileFireAndForget(string key, string body, StorageStrategies location)
 {
     await WriteFileAsync(key, body, location);
 }