예제 #1
0
        public async Task DeleteFile(FolderQuery query, string filename)
        {
            var folder = await GetFolder(query);

            var file = await folder.GetFileAsync(filename);

            await file.DeleteAsync();
        }
예제 #2
0
        public async Task <Stream?> GetStreamAsync(FolderQuery query, string filename, FileAccess access)
        {
            var folder = await GetFolder(query);

            return(access switch
            {
                FileAccess.Read => await folder.OpenStreamForReadAsync(filename),
                FileAccess.Write => await folder.OpenStreamForWriteAsync(filename, CreationCollisionOption.ReplaceExisting),
                _ => null,
            });
 public Task <Stream?> GetStreamAsync(FolderQuery query, string filename, FileAccess access)
 {
     if (access == FileAccess.Read)
     {
         return(Task.FromResult((Stream?)new FileStream(FullFileName(query, filename), FileMode.Open, access)));
     }
     else
     {
         return(Task.FromResult((Stream?)new FileStream(FullFileName(query, filename), FileMode.Create, access)));
     }
 }
예제 #4
0
 private async Task <StorageFolder> GetFolder(FolderQuery query)
 {
     if (string.IsNullOrEmpty(query.SubFolder))
     {
         return(folder !);
     }
     else
     {
         return(await folder !.CreateFolderAsync(query.SubFolder, CreationCollisionOption.OpenIfExists));
     }
 }
        private string FolderPath(FolderQuery query)
        {
            string folder;

            if (string.IsNullOrEmpty(query.SubFolder))
            {
                folder = DataPath;
            }
            else
            {
                folder = Path.Combine(DataPath, query.SubFolder);
            }

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            return(folder);
        }
예제 #6
0
        public async Task <string[]> GetFiles(FolderQuery query)
        {
            var folder = await GetFolder(query);


            var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { query.Extension })
            {
                FolderDepth = FolderDepth.Shallow
            };
            var queryResult = folder.CreateFileQueryWithOptions(queryOptions);

            var files = await queryResult.GetFilesAsync();

            var result = new string[files.Count];

            for (int i = 0; i < result.Length; ++i)
            {
                result[i] = files[i].Name;
            }
            return(result);
        }
예제 #7
0
 protected FileDataStore(FolderQuery folder, IDataSerializer <T> dataSerializer)
 {
     Folder = folder;
     this.dataSerializer = dataSerializer;
 }
 public Task <bool> FileExists(FolderQuery query, string filename)
 {
     return(Task.FromResult(File.Exists(FullFileName(query, filename))));
 }
        public Task <string[]> GetFiles(FolderQuery query)
        {
            var path = FolderPath(query);

            return(Task.FromResult(Directory.GetFiles(path, $"*{query.Extension}", SearchOption.TopDirectoryOnly)));
        }
 public Task DeleteFile(FolderQuery query, string filename)
 {
     return(Task.Run(() => File.Delete(FullFileName(query, filename))));
 }
 private string FullFileName(FolderQuery query, string filename)
 {
     return(Path.Combine(FolderPath(query), filename));
 }