Beispiel #1
0
 public static async Task DeleteAsync(this IDiskIOHelper ioHelper, IEntryModel[] entryModels, CancellationToken ct)
 {
     foreach (var em in entryModels)
     {
         await ioHelper.DeleteAsync(em, ct);
     }
 }
Beispiel #2
0
        public static async Task <string> WriteToCacheAsync(this IDiskIOHelper ioHelper, IEntryModel entry, CancellationToken ct, bool force = false)
        {
            var mapping = ioHelper.Mapper[entry];

            if (!mapping.IsCached || force)
            {
                if (entry.IsDirectory)
                {
                    System.IO.Directory.CreateDirectory(mapping.IOPath);
                    var listing = await entry.Profile.ListAsync(entry, ct).ConfigureAwait(false);

                    foreach (var subEntry in listing)
                    {
                        await WriteToCacheAsync(ioHelper, subEntry, ct, force).ConfigureAwait(false);
                    }
                }
                else
                {
                    using (var srcStream = await ioHelper.OpenStreamAsync(entry.FullPath,
                                                                          FileExplorer.Defines.FileAccess.Read, ct))
                        using (var outputStream = System.IO.File.OpenWrite(mapping.IOPath))
                            await StreamUtils.CopyStreamAsync(srcStream, outputStream).ConfigureAwait(false);
                }
            }

            return(mapping.IOPath);
        }
Beispiel #3
0
        public static async Task <Stream> OpenStreamAsync(this IDiskIOHelper ioHelper, string fullPath,
                                                          FileExplorer.Defines.FileAccess access, CancellationToken ct)
        {
            IEntryModel entryModel = await ioHelper.Profile.ParseAsync(fullPath);

            ct.ThrowIfCancellationRequested();
            if (entryModel == null)
            {
                if (access == FileExplorer.Defines.FileAccess.Write)
                {
                    entryModel = await ioHelper.CreateAsync(fullPath, false, ct);
                }
                else
                {
                    throw new IOException("File not found.");
                }
            }
            ct.ThrowIfCancellationRequested();
            return(await ioHelper.OpenStreamAsync(entryModel, access, ct));
        }