Пример #1
0
        /// <summary>
        /// Synchronize files with Google Drive
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CmdDriveUpload_Click(object sender, EventArgs e)
        {
            // Change label to display that the upload is in progress
            lblDriveLastUploaded.Text = @"Upload in progres...";

            var filesList = new List <string>();

            foreach (var fileItem in checkedListDownloadUploadFiles.CheckedItems)
            {
                filesList.Add(Path.Combine(_settingsManager.Settings.ResourceFolderPath, fileItem.ToString().ToLower() + ".json"));
            }

            var driveManager = new GoogleDriveManager();

            for (var i = 0; i < filesList.Count; i++)
            {
                // Update label
                lblDriveLastUploaded.Text = @"Upload in progress... (" + (i + 1) + @"/" + filesList.Count + @")";

                Google.Apis.Drive.v3.Data.File responseFile;

                // save response file id to settings to find the file later
                switch (i)
                {
                case 0:
                    responseFile = await driveManager.UploadFile(filesList[i], ResourceType.Vacancies);

                    _settingsManager.SetGoogleDriveVacanciesFileId(responseFile.Id);
                    break;

                case 1:
                    responseFile = await driveManager.UploadFile(filesList[i], ResourceType.Blacklist);

                    _settingsManager.SetGoogleDriveBlacklistFileId(responseFile.Id);
                    break;

                case 2:
                    responseFile = await driveManager.UploadFile(filesList[i], ResourceType.Done);

                    _settingsManager.SetGoogleDriveDoneFileId(responseFile.Id);
                    break;

                case 3:
                    responseFile = await driveManager.UploadFile(filesList[i], ResourceType.Companies);

                    _settingsManager.SetGoogleDriveCompaniesFileId(responseFile.Id);
                    break;

                default:
                    break;
                }
            }

            _settingsManager.SetLastDriveUpload(DateTime.Now);
            UpdateLastDriveUploadLabel();
        }