Esempio n. 1
0
 private void EnsureThatDriveFileIsAFolder(GoogleDriveFile folderToSynchronize)
 {
     if (folderToSynchronize.MimeType != GoogleDriveConstants.FolderMimeType)
     {
         throw new InvalidOperationException("GoogleDriveFile " + folderToSynchronize.Title + " is not a Folder.");
     }
 }
 private void EnsureThatDriveFileIsAFolder(GoogleDriveFile folderToSynchronize)
 {
     if (folderToSynchronize.MimeType != GoogleDriveConstants.FolderMimeType)
     {
         throw new InvalidOperationException("GoogleDriveFile " + folderToSynchronize.Title + " is not a Folder.");
     }
 }
Esempio n. 3
0
        private void SynchronizeContentOfFolder(GoogleDriveFile folderToSynchronize, string rootFolder, List <GoogleDriveFile> allDriveFiles)
        {
            string currentFolder = rootFolder + "\\" + folderToSynchronize.Title;

            Directory.CreateDirectory(currentFolder);

            var childDriveFiles = this.GetChildDriveFiles(folderToSynchronize, allDriveFiles);

            foreach (GoogleDriveFile childDriveFile in childDriveFiles)
            {
                allDriveFiles.Remove(childDriveFile);
            }

            foreach (GoogleDriveFile childDriveFile in childDriveFiles)
            {
                if (childDriveFile.MimeType == GoogleDriveConstants.FolderMimeType)
                {
                    this.SynchronizeContentOfFolder(
                        childDriveFile,
                        currentFolder,
                        allDriveFiles);
                }
                else
                {
                    this.driveFileDownloader.Download(childDriveFile, currentFolder);
                }
            }
        }
        private void SynchronizeContentOfFolder(GoogleDriveFile folderToSynchronize, string rootFolder, List<GoogleDriveFile> allDriveFiles)
        {
            string currentFolder = rootFolder + "\\" + folderToSynchronize.Title;
            Directory.CreateDirectory(currentFolder);

            var childDriveFiles = this.GetChildDriveFiles(folderToSynchronize, allDriveFiles);

            foreach (GoogleDriveFile childDriveFile in childDriveFiles)
            {
                allDriveFiles.Remove(childDriveFile);
            }

            foreach (GoogleDriveFile childDriveFile in childDriveFiles)
            {
                if (childDriveFile.MimeType == GoogleDriveConstants.FolderMimeType)
                {
                    this.SynchronizeContentOfFolder(
                        childDriveFile, 
                        currentFolder,
                        allDriveFiles);
                }
                else
                {
                    this.driveFileDownloader.Download(childDriveFile, currentFolder);
                }
            }
        }
Esempio n. 5
0
 public void SynchronizeFolder(GoogleDriveFile folderToSynchronize, string rootFolder)
 {
     this.EnsureThatDriveFileIsAFolder(folderToSynchronize);
     this.SynchronizeContentOfFolder(
         folderToSynchronize,
         rootFolder,
         this.filesGetter.GetDriveFiles(GoogleDriveConstants.AnyFileType).ToList());
 }
 public void SynchronizeFolder(GoogleDriveFile folderToSynchronize, string rootFolder)
 {
     this.EnsureThatDriveFileIsAFolder(folderToSynchronize);
     this.SynchronizeContentOfFolder(
         folderToSynchronize,
         rootFolder,
         this.filesGetter.GetDriveFiles(GoogleDriveConstants.AnyFileType).ToList());
 }
 public bool Download(GoogleDriveFile googleDriveFile, string targetFolder)
 {
     if (string.IsNullOrEmpty(googleDriveFile.DownloadUrl) == false)
     {
         try
         {
             var request = this.driveServiceProvider.GetService()
                 .HttpClient.GetByteArrayAsync(googleDriveFile.DownloadUrl);
             byte[] fileData = request.Result;
             System.IO.File.WriteAllBytes(targetFolder + "\\" + googleDriveFile.Title, fileData);
             return true;
         }
         catch (Exception e)
         {
             Console.WriteLine("An error occurred: " + e.Message);
             return false;
         }
     }
     else
     {
         // The file doesn't have any content stored on Drive.
         return false;
     }
 }
Esempio n. 8
0
 public bool Download(GoogleDriveFile googleDriveFile, string targetFolder)
 {
     if (string.IsNullOrEmpty(googleDriveFile.DownloadUrl) == false)
     {
         try
         {
             var request = this.driveServiceProvider.GetService()
                           .HttpClient.GetByteArrayAsync(googleDriveFile.DownloadUrl);
             byte[] fileData = request.Result;
             System.IO.File.WriteAllBytes(targetFolder + "\\" + googleDriveFile.Title, fileData);
             return(true);
         }
         catch (Exception e)
         {
             Console.WriteLine("An error occurred: " + e.Message);
             return(false);
         }
     }
     else
     {
         // The file doesn't have any content stored on Drive.
         return(false);
     }
 }
Esempio n. 9
0
 private bool DriveFileIsInFolder(GoogleDriveFile folderToSynchronize, GoogleDriveFile o)
 {
     return(o.Parents.Any() && o.Parents.Single().Id == folderToSynchronize.Id);
 }
Esempio n. 10
0
        private List <GoogleDriveFile> GetChildDriveFiles(GoogleDriveFile folderToSynchronize, List <GoogleDriveFile> allDriveFiles)
        {
            List <GoogleDriveFile> childDriveFiles = allDriveFiles.Where(o => this.DriveFileIsInFolder(folderToSynchronize, o)).ToList();

            return(childDriveFiles);
        }
 private bool DriveFileIsInFolder(GoogleDriveFile folderToSynchronize, GoogleDriveFile o)
 {
     return o.Parents.Any() && o.Parents.Single().Id == folderToSynchronize.Id;
 }
 private List<GoogleDriveFile> GetChildDriveFiles(GoogleDriveFile folderToSynchronize, List<GoogleDriveFile> allDriveFiles)
 {
     List<GoogleDriveFile> childDriveFiles = allDriveFiles.Where(o => this.DriveFileIsInFolder(folderToSynchronize, o)).ToList();
     return childDriveFiles;
 }