Esempio n. 1
0
 public AccountFile(Account account, StorageFile storageFile, IEnumerable<DriveFile> driveFiles, AccountFile parent)
 {
     DriveFiles.AddRange(driveFiles);
     this.StorageFile = storageFile;
     Parent = parent;
     Account = account;
 }
Esempio n. 2
0
 public async Task<ICollection<AccountFile>> GetSubfoldersAsync(AccountFile folder, CancellationToken token)
 {
     IDictionary<string, DriveFileCollection> driveFiles = new Dictionary<string, DriveFileCollection>();
     foreach (var f in folder.DriveFiles)
     {
         PutFilesTo(await f.Drive.GetSubfoldersAsync(f, token), driveFiles);
     }
     return driveFiles.Values.Select(files => new AccountFile(this, Storage.GetFile(files), files, folder)).ToList();
 }
Esempio n. 3
0
File: Util.cs Progetto: fiftin/oblqo
        public static AccountFileStates GetFileState(AccountFile file)
        {
            AccountFileStates ret = 0;

            var nDrives = file.Account.Drives.Count;
            var nDrivesSyncronized =
                file.Account.Drives.Select(x => file.GetDriveFile(x)).Count(x => x != null);

            DriveFile inventoryFile;
            if (file.Account.Drives.InventoryDrive == null)
            {
                inventoryFile = null;
            }
            else
            {
                nDrives--;
                inventoryFile = file.GetDriveFile(file.Account.Drives.InventoryDrive);
                if (inventoryFile != null)
                {
                    nDrivesSyncronized--;
                }
            }
            
            if (nDrivesSyncronized != nDrives)
            {
                ret |= AccountFileStates.UnsyncronizedWithAllDrives;
            }

            if (file.Account.Drives.InventoryDrive != null)
            {
                if (inventoryFile == null)
                {
                    ret |= AccountFileStates.PlacedOnlyDrive;
                }
                else if (nDrivesSyncronized == 0)
                {
                    ret |= AccountFileStates.PlacedOnlyStorage;
                }
            }

            if (file.StorageFileId == null)
            {
                ret |= AccountFileStates.UnsyncronizedWithStorage;
            }
            else if (!file.HasValidStorageFileId)
            {
                ret |= AccountFileStates.Error;
            }
            return ret;
        }
Esempio n. 4
0
 public async Task <Image> GetThumbnailAsync(AccountFile file, CancellationToken token)
 {
     foreach (var drive in Drives)
     {
         try
         {
             return(await drive.GetThumbnailAsync(file.GetDriveFile(drive), token));
         }
         catch (Exception ex)
         {
             OnError(ex);
         }
     }
     throw new Exception("Can't download this file");
 }
Esempio n. 5
0
 public async Task<Image> GetThumbnailAsync(AccountFile file, CancellationToken token)
 {
     foreach (var drive in Drives)
     {
         try
         {
             return await drive.GetThumbnailAsync(file.GetDriveFile(drive), token);
         }
         catch (Exception ex)
         {
             OnError(ex);
         }
     }
     throw new Exception("Can't download this file");
 }
Esempio n. 6
0
        public async Task DownloadFileFromDriveAsync(AccountFile file, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token)
        {
            foreach (var drive in Drives)
            {
                try
                {
                    await drive.DownloadFileAsync(file.GetDriveFile(drive), destFolder, actionIfFileExists, token);

                    return;
                }
                catch (Exception ex)
                {
                    OnError(ex);
                }
            }
            throw new Exception("Can't download this file");
        }
Esempio n. 7
0
        public async Task DownloadFileFromDriveAsync(AccountFile file, Stream output, CancellationToken token)
        {
            foreach (var drive in Drives)
            {
                try
                {
                    await drive.DownloadFileAsync(file.GetDriveFile(drive), output, token);

                    return;
                }
                catch (Exception ex)
                {
                    OnError(ex);
                }
            }
            throw new Exception("Can't download this file");
        }
Esempio n. 8
0
        public virtual async Task <Image> GetImageAsync(AccountFile file, CancellationToken token)
        {
            foreach (var drive in Drives)
            {
                var f = file.GetDriveFile(drive);
                if (f == null)
                {
                    continue;
                }
                var image = await drive.GetImageAsync(f, token);

                if (image != null)
                {
                    return(image);
                }
            }
            return(null);
        }
Esempio n. 9
0
        public async Task <AccountFile> GetFileAsync(XElement fileXml, CancellationToken token)
        {
            var storageXml  = fileXml.Element("storageFile");
            var driveXmls   = fileXml.Element("driveFiles").Elements();
            var storageFile = storageXml == null ? null : await Storage.GetFileAsync(storageXml, token);

            List <DriveFile> driveFiles;
            var tasks =
                Drives.Select(
                    drive =>
            {
                var driveFileXml = driveXmls.SingleOrDefault(x => x.Attribute("driveId").Value == drive.Id);
                var ret          = driveFileXml == null ? null : drive.GetFileAsync(driveFileXml, token);
                return(ret);
            }).Where(x => x != null);

            driveFiles = new List <DriveFile>(await Task.WhenAll(tasks));
            var         parentXml = fileXml.Element("parent");
            AccountFile parent    = parentXml == null ? null : await GetFileAsync(parentXml, token);

            return(new AccountFile(this, storageFile, driveFiles, parent));
        }
Esempio n. 10
0
 public AccountFile(Account account, StorageFile storageFile, AccountFile parent)
 {
     this.StorageFile = storageFile;
     Parent = parent;
     Account = account;
 }
Esempio n. 11
0
 public virtual async Task<Image> GetImageAsync(AccountFile file, CancellationToken token)
 {
     foreach (var drive in Drives)
     {
         var f = file.GetDriveFile(drive);
         if (f == null)
         {
             continue;
         }
         var image = await drive.GetImageAsync(f, token);
         if (image != null)
         {
             return image;
         }
     }
     return null;
 }
Esempio n. 12
0
 private void AddNode(AccountFile file, TreeNode parentNode, string accountName)
 {
     var newNode = parentNode.Nodes.Add("", file.Name, FolderImageKey);
     newNode.SelectedImageKey = FolderImageKey;
     newNode.Tag = new NodeInfo(file, accountName);
     if (file.HasChildren)
         newNode.Nodes.Add("", "", "");
 }
Esempio n. 13
0
 public async Task<AccountFile> CreateFolderAsync(string folderName, AccountFile destFolder,
     CancellationToken token)
 {
     var storageDir =
         await
             Storage.CreateFolderAsync(folderName, destFolder.StorageFile,
                 token);
     var tasks = Drives.Select(drive => drive.CreateFolderAsync(folderName, destFolder.GetDriveFile(drive), token));
     return new AccountFile(this, storageDir, await Task.WhenAll(tasks), destFolder);
 }
Esempio n. 14
0
 public async Task DownloadFileFromStorageAsync(AccountFile file, Stream output, CancellationToken token, Action <TransferProgress> progressCallback)
 {
     await Storage.DownloadFileAsync(file.StorageFile, output, token, progressCallback);
 }
Esempio n. 15
0
 /// <summary>
 /// Download folder or file from storage (not from drive).
 /// </summary>
 /// <param name="destFolder">Path of folder whare to nest a downloaded file or folder.
 /// For example if <paramref name="file"/> is "/photo2010/egypt" and <paramref name="destFolder"/>
 /// is "d:/photos", then in "photos" folder will be created subfolder "egypt" with downloaded files.
 /// </param>
 public async Task DownloadFileFromStorageAsync(AccountFile file, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token, Action <TransferProgress> progressCallback)
 {
     await Storage.DownloadFileAsync(file.StorageFile, destFolder, actionIfFileExists, token, progressCallback);
 }
Esempio n. 16
0
 public async Task DeleteFolderAsync(AccountFile folder, CancellationToken token)
 {
     var tasks = Drives.Select(drive =>
     {
         var file = folder.GetDriveFile(drive);
         if (file == null)
         {
             return null;
         }
         return drive.DeleteFolderAsync(file, token);
     }).Where(x => x != null);
     await Task.WhenAll(tasks);
 }
Esempio n. 17
0
 /// <summary>
 /// Upload folder of file to storage and drive.
 /// </summary>
 public async Task<AccountFile> UploadFileAsync(string pathName, AccountFile destFolder, CancellationToken token, Action<TransferProgress> progressCallback)
 {
     var uploadedFile = await Storage.UploadFileAsync(pathName, destFolder.StorageFile, token, progressCallback);
     var tasks = Drives.Select(drive => drive.UploadFileAsync(pathName, destFolder.GetDriveFile(drive), uploadedFile.Id, token));
     var uploadedDriveFiles = await Task.WhenAll(tasks);
     return new AccountFile(this, uploadedFile, uploadedDriveFiles, destFolder);
 }
Esempio n. 18
0
 public AccountFile(Account account, StorageFile storageFile, IEnumerable <DriveFile> driveFiles, AccountFile parent)
 {
     DriveFiles.AddRange(driveFiles);
     this.StorageFile = storageFile;
     Parent           = parent;
     Account          = account;
 }
Esempio n. 19
0
 public async Task DownloadFileFromDriveAsync(AccountFile file, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token)
 {
     foreach (var drive in Drives)
     {
         try
         {
             await drive.DownloadFileAsync(file.GetDriveFile(drive), destFolder, actionIfFileExists, token);
             return;
         }
         catch (Exception ex)
         {
             OnError(ex);
         }
     }
     throw new Exception("Can't download this file");
 }
Esempio n. 20
0
 public async Task DownloadFileFromStorageAsync(AccountFile file, Stream output, CancellationToken token, Action<TransferProgress> progressCallback)
 {
     await Storage.DownloadFileAsync(file.StorageFile, output, token, progressCallback);
 }
Esempio n. 21
0
 /// <summary>
 /// Download folder or file from storage (not from drive).
 /// </summary>
 /// <param name="destFolder">Path of folder whare to nest a downloaded file or folder.
 /// For example if <paramref name="file"/> is "/photo2010/egypt" and <paramref name="destFolder"/> 
 /// is "d:/photos", then in "photos" folder will be created subfolder "egypt" with downloaded files.
 /// </param>
 public async Task DownloadFileFromStorageAsync(AccountFile file, string destFolder, ActionIfFileExists actionIfFileExists, CancellationToken token, Action<TransferProgress> progressCallback)
 {
     await Storage.DownloadFileAsync(file.StorageFile, destFolder, actionIfFileExists, token, progressCallback);
 }
Esempio n. 22
0
 public AccountFile(Account account, StorageFile storageFile, AccountFile parent)
 {
     this.StorageFile = storageFile;
     Parent           = parent;
     Account          = account;
 }
Esempio n. 23
0
 public async Task DownloadFileFromDriveAsync(AccountFile file, Stream output, CancellationToken token)
 {
     foreach (var drive in Drives)
     {
         try
         {
             await drive.DownloadFileAsync(file.GetDriveFile(drive), output, token);
             return;
         }
         catch (Exception ex)
         {
             OnError(ex);
         }
     }
     throw new Exception("Can't download this file");
 }