Пример #1
0
 private async Task<DFileInfo> localFileOperationAsync(DFileInfo destinationFolder, bool move)
 {
     if (destinationFolder == null)
         throw new NullReferenceException(ExceptionMessage.IsNullOrInvalid("destinationFolder"));
     if (destinationFolder.IsReadOnly)
         throw new InvalidOperationException(ExceptionMessage.ReadOnly);
     if (!destinationFolder.IsDirectory)
         throw new InvalidOperationException("Destination is not a folder. Impossible to move/copy to a file.");
     if (this.Provider == destinationFolder.Provider)
     {
         if (move)
         {
             return await Provider.MoveAsync(this, destinationFolder);
         }
         else
         {
             return await Provider.CopyAsync(this, destinationFolder);
         }
     }
     else
     {
         if (this.IsDirectory)
             throw new InvalidOperationException("Copying or moving folders between providers is not supported.");
         Stream thisFile = await this.GetDownloadStreamAsync();
         var file = await destinationFolder.CreateFileAsync(this.Name, thisFile, CancellationToken.None);
         if (move) await this.DeleteAsync();
         return file;
     }
 }