Example #1
0
 public async Task <DriveFile> UploadFileAsync(string pathName, DriveFile destFolder, string storageFileId, CancellationToken token)
 {
     using (var stream = File.OpenRead(pathName))
     {
         return(await UploadFileAsync(stream, Path.GetFileName(pathName), destFolder, storageFileId, token));
     }
 }
Example #2
0
 public override async Task<DriveFile> UploadFileAsync(Stream fileStream, string fileName, DriveFile destFolder, string storageFileId, CancellationToken token)
 {
     var file = new MockDriveFile(this, fileName, false);
     file.content = new byte[fileStream.Length];
     fileStream.Read(file.content, 0, (int)fileStream.Length);
     MockDriveFile folder = (MockDriveFile)destFolder;
     folder.Add(file);
     return file;
 }
Example #3
0
 private static string GetFileName(DriveFile file, bool isLantinOnlySupport)
 {
     if (file == null)
     {
         return(null);
     }
     if (isLantinOnlySupport)
     {
         return(file.Name.Unidecode());
     }
     return(file.Name);
 }
Example #4
0
 public virtual async Task <Image> GetImageAsync(DriveFile file, CancellationToken token)
 {
     using (var stream = await ReadFileAsync(file, token))
     {
         try
         {
             return(await Task.Run(() => Image.FromStream(stream)));
         }
         catch (Exception)
         {
             throw new BadImageFormatException();
         }
     }
 }
Example #5
0
        private void PutFileTo(DriveFile file, IDictionary <string, DriveFileCollection> fileCollections)
        {
            DriveFileCollection collection;

            if (file.StorageFileId == null)
            {
                if (!TryFindFileByName(file.Name, file.Drive.IsLantinOnlySupport, fileCollections.Values, out collection))
                {
                    collection = new DriveFileCollection();
                    fileCollections.Add(file.StorageFileId ?? Guid.NewGuid().ToString(), collection);
                }
            }
            else if (!fileCollections.TryGetValue(file.StorageFileId, out collection))
            {
                collection = new DriveFileCollection();
                fileCollections.Add(file.StorageFileId ?? Guid.NewGuid().ToString(), collection);
            }
            collection.Add(file);
        }
Example #6
0
 internal bool DeleteFileRecursive(DriveFile driveFile)
 {
     var y = files.FirstOrDefault(x => x.Name == driveFile.Name);
     if (y != null)
     {
         return files.Remove(y);
     }
     else
     {
         foreach (var x in files.Where(x=>x.IsFolder && x.files.Count > 0))
         {
             if (x.DeleteFileRecursive(driveFile))
             {
                 return true;
             }
         }
         return false;
     }
 }
Example #7
0
 public abstract Task DeleteFolderAsync(DriveFile driveFolder, CancellationToken token);
Example #8
0
 public override async Task DeleteFolderAsync(DriveFile driveFolder, CancellationToken token)
 {
     rootFolder.DeleteFileRecursive(driveFolder);
 }
Example #9
0
 public abstract Task<ICollection<DriveFile>> GetSubfoldersAsync(DriveFile folder, CancellationToken token);
Example #10
0
 public abstract Task<Image> GetThumbnailAsync(DriveFile file, CancellationToken token);
Example #11
0
 public abstract Task<DriveFile> UploadFileAsync(Stream fileStream, string fileName, DriveFile destFolder, string storageFileId, CancellationToken token);
Example #12
0
 public override Task<System.Drawing.Image> GetThumbnailAsync(DriveFile file, CancellationToken token)
 {
     throw new NotImplementedException();
 }
Example #13
0
 private static string GetFileName(DriveFile file, bool isLantinOnlySupport)
 {
     if (file == null)
     {
         return null;
     }
     if (isLantinOnlySupport)
     {
         return file.Name.Unidecode();
     }
     return file.Name;
 }
Example #14
0
 public override async Task DownloadFileAsync(DriveFile driveFile, Stream output, CancellationToken token)
 {
     await output.WriteAsync(((MockDriveFile)driveFile).content, 0, ((MockDriveFile)driveFile).content.Length);
 }
Example #15
0
 public abstract Task DownloadFileAsync(DriveFile driveFile, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token);
Example #16
0
 public abstract Task EnumerateFilesRecursive(DriveFile driveFolder, Action <DriveFile> action, CancellationToken token);
Example #17
0
 public override async Task DownloadFileAsync(DriveFile driveFile, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token)
 {
     throw new NotImplementedException();
 }
Example #18
0
 public override async Task EnumerateFilesRecursive(DriveFile driveFolder, Action<DriveFile> action, CancellationToken token)
 {
     throw new NotImplementedException();
 }
Example #19
0
 public override async Task<Stream> ReadFileAsync(DriveFile file, CancellationToken token)
 {
     return new MemoryStream(((MockDriveFile)file).content);
 }
Example #20
0
 public abstract Task EnumerateFilesRecursive(DriveFile driveFolder, Action<DriveFile> action, CancellationToken token);
Example #21
0
 private void PutFileTo(DriveFile file, IDictionary<string, DriveFileCollection> fileCollections)
 {
     DriveFileCollection collection;
     if (file.StorageFileId == null)
     {
         if (!TryFindFileByName(file.Name, file.Drive.IsLantinOnlySupport, fileCollections.Values, out collection))
         {
             collection = new DriveFileCollection();
             fileCollections.Add(file.StorageFileId ?? Guid.NewGuid().ToString(), collection);
         }
     }
     else if (!fileCollections.TryGetValue(file.StorageFileId, out collection))
     {
         collection = new DriveFileCollection();
         fileCollections.Add(file.StorageFileId ?? Guid.NewGuid().ToString(), collection);
     }
     collection.Add(file);
 }
Example #22
0
 public abstract Task DownloadFileAsync(DriveFile driveFile, Stream output, CancellationToken token);
Example #23
0
 public abstract Task DownloadFileAsync(DriveFile driveFile, Stream output, CancellationToken token);
Example #24
0
 public override async Task<ICollection<DriveFile>> GetSubfoldersAsync(DriveFile folder, CancellationToken token)
 {
     return ((MockDriveFile)folder).files.Where(x => x.IsFolder).Cast<DriveFile>().ToList();
 }
Example #25
0
 public virtual async Task<Image> GetImageAsync(DriveFile file, CancellationToken token)
 {
     using (var stream = await ReadFileAsync(file, token))
     {
         try
         {
             return await Task.Run(() => Image.FromStream(stream));
         }
         catch(Exception)
         {
             throw new BadImageFormatException();
         }
     }
 }
Example #26
0
 public abstract Task <DriveFile> UploadFileAsync(Stream fileStream, string fileName, DriveFile destFolder, string storageFileId, CancellationToken token);
Example #27
0
 public abstract Task DownloadFileAsync(DriveFile driveFile, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token);
Example #28
0
 public abstract Task <Stream> ReadFileAsync(DriveFile file, CancellationToken token);
Example #29
0
 public async Task<DriveFile> UploadFileAsync(string pathName, DriveFile destFolder, string storageFileId, CancellationToken token)
 {
     using (var stream = File.OpenRead(pathName))
     {
         return await UploadFileAsync(stream, Path.GetFileName(pathName), destFolder, storageFileId, token);
     }
 }
Example #30
0
 public abstract Task <Image> GetThumbnailAsync(DriveFile file, CancellationToken token);
Example #31
0
 public abstract Task<Stream> ReadFileAsync(DriveFile file, CancellationToken token);
Example #32
0
 public abstract Task <DriveFile> CreateFolderAsync(string folderName, DriveFile destFolder, CancellationToken token);
Example #33
0
 public abstract Task<DriveFile> CreateFolderAsync(string folderName, DriveFile destFolder, CancellationToken token);
Example #34
0
 public abstract Task <ICollection <DriveFile> > GetSubfoldersAsync(DriveFile folder, CancellationToken token);
Example #35
0
 public abstract Task DeleteFolderAsync(DriveFile driveFolder, CancellationToken token);
Example #36
0
 public override async Task<DriveFile> CreateFolderAsync(string folderName, DriveFile destFolder, 
     CancellationToken token)
 {
     return ((MockDriveFile)destFolder).CreateFolder(folderName);
 }