Пример #1
0
        /// <summary>
        /// It collect the downloadable files into param  GDDownloader variable and
        /// it collect the unnecessary files into global deletableFiles variable.
        /// </summary>
        /// <param name="downloader"></param>
        /// <param name="localFolder"></param>
        /// <param name="parentId"></param>
        private void CollectDownSynchronizerData(GDDownloader downloader, string localFolder, string parentId)
        {
            List <string> unnecessaryFiles = getLocalFiles(localFolder);
            IEnumerable <Google.Apis.Drive.v3.Data.File> files = getGDFiles(parentId);

            foreach (Google.Apis.Drive.v3.Data.File file in files)
            {
                if (file.MimeType == "application/vnd.google-apps.folder")
                {
                    string folderPath = localFolder + "\\" + file.Name;
                    unnecessaryFiles.Remove(folderPath);
                    CollectDownSynchronizerData(downloader, folderPath, file.Id);
                }
                else
                {
                    if (file.FileExtension == "zip")
                    {
                        string fileName = localFolder + "\\" + file.Name.Substring(0, file.Name.Length - 4);

                        if (unnecessaryFiles.Contains(fileName) && System.IO.File.GetLastWriteTime(fileName) >= file.ModifiedTime.Value)
                        {
                            unnecessaryFiles.Remove(fileName);
                        }
                        else
                        {
                            downloader.Add(new DownloadableFile(file, localFolder));
                        }
                    }
                }
            }

            AddToDeletableFile(unnecessaryFiles);
        }
Пример #2
0
        /// <summary>
        /// It downloads the files, which is needed and deletes the unnecessary files.
        /// It doesn't delete those, which were added to ExceptionFiles.
        /// </summary>
        /// <param name="localFolder"></param>
        /// <param name="driveFolder"></param>
        /// <param name="password">Password of zip files.</param>
        public override void Sync(string localFolder, string driveFolder, string password)
        {
            if (string.IsNullOrEmpty(localFolder))
            {
                throw new ArgumentNullException("localFolder");
            }
            if (string.IsNullOrEmpty(driveFolder))
            {
                throw new ArgumentNullException("driveFolder");
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }

            string parentId = ConvertGDFolderToGDParentId(driveFolder);

            if (parentId == null)
            {
                throw new Exception("NotExistPath");
            }

            localFolder += "\\" + GetFileName(driveFolder);

            GDDownloader downloader = new GDDownloader(Service);

            downloader.StreamStatusEvent += CatchStatus;

            CollectDownSynchronizerData(downloader, localFolder, parentId);

            CallFullSizeEvent(downloader.StreamdableBytes);

            DeleteFiles();

            try
            {
                foreach (string file in downloader.StartStream())
                {
                    UnZipFile(file, password);
                }
            }
            catch (Exception e)
            {
                DeleteZipFiles(localFolder);
                throw e;
            }
        }