Пример #1
0
        public static Connection Create(GoogleDriveServiceAccountCredential serviceAccountCredential)
        {
            Connection connection = new Connection();

            connection.Connect(serviceAccountCredential);
            if (!connection.IsConnected())
            {
                throw new BusinessRuleException("Cannot connect to GoogleDrive service.");
            }
            return(connection);
        }
Пример #2
0
        private void Connect(GoogleDriveServiceAccountCredential serviceAccountCredential)
        {
            if (String.IsNullOrEmpty(serviceAccountCredential.Email))
            {
                throw new ArgumentNullException("serviceAccountCredential.Email", "Email wasn't specified.");
            }
            if (String.IsNullOrEmpty(serviceAccountCredential.PrivateKey))
            {
                throw new ArgumentNullException("serviceAccountCredential.PrivateKey", "privateKey wasn't specified.");
            }

            credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountCredential.Email)
            {
                Scopes = Connection.Scopes
            }.FromPrivateKey(serviceAccountCredential.PrivateKey));

            Service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = Connection.ApplicationName,
            });
        }