Beispiel #1
0
        /// <summary>
        /// Uploads given content to a file in the Google Drive Cloud Storage.
        /// </summary>
        /// <param name="ll">current instance of List & Label</param>
        /// <param name="uploadParameters">requied parameters for Google Drive OAuth 2.0 upload.</param>
        /// <param name="clientSecretFilePath">The full path of client secret file.</param>
        public static void Upload(this Reporting.ListLabel ll, GoogleDriveUploadParameter uploadParameters, string clientSecretFilePath)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream(clientSecretFilePath, FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user2",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;

                Upload2GoogleDrive(credential, uploadParameters.UploadStream, uploadParameters.CloudFileName, uploadParameters.CloudPath, uploadParameters.ApplicationName, uploadParameters.MimeType);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Uploads given content to a file in the Google Drive Cloud Storage.
        /// </summary>
        /// <param name="ll">current instance of List & Label</param>
        /// <param name="uploadParameters">requied parameters for Google Drive OAuth 2.0 upload silently.</param>
        /// <param name="credentials">requied parameters for Google Drive OAuth 2.0 authentication.</param>
        public static void UploadSilently(this Reporting.ListLabel ll, GoogleDriveUploadParameter uploadParameters, GoogleDriveCredentials credentials)
        {
            var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = new ClientSecrets
                {
                    ClientId     = credentials.ClientId,
                    ClientSecret = credentials.ClientSecret
                },
                Scopes = Scopes
            });

            var accessToken = Reporting.DataProviders.GoogleDataProviderHelper.GetAuthToken(credentials.RefreshToken, credentials.ClientId, credentials.ClientSecret);

            var token = new TokenResponse
            {
                AccessToken  = accessToken,
                RefreshToken = credentials.RefreshToken
            };

            var credential = new UserCredential(flow, Environment.UserName, token);

            Upload2GoogleDrive(credential, uploadParameters.UploadStream, uploadParameters.CloudFileName, uploadParameters.CloudPath, uploadParameters.ApplicationName, uploadParameters.MimeType);
        }