protected override void Execute(NativeActivityContext context)
        {
            string serviceAccountEmail = ServiceAccountEmail.Get(context);
            string keyPath             = KeyPath.Get(context);
            string password            = Password.Get(context);

            var certificate = new X509Certificate2(@keyPath, password, X509KeyStorageFlags.Exportable);

            ServiceAccountCredential credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                Scopes = new[] { SheetsService.Scope.Spreadsheets }
            }.FromCertificate(certificate));

            // Create the service.
            var sheetService = new SheetsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = "UiPath Robot",
            });

            var googleSheetProperty = new GoogleSheetProperty()
            {
                SheetsService = sheetService,
                SpreadsheetId = SpreadsheetId.Get(context)
            };

            if (Body != null)
            {
                context.ScheduleAction <GoogleSheetProperty>(Body, googleSheetProperty, OnCompleted, OnFaulted);
            }
        }
Esempio n. 2
0
        protected override void Execute(NativeActivityContext context)
        {
            string spreadsheetId = SpreadsheetId.Get(context);
            GoogleSheetProperty googleSheetProperty;

            switch (AuthenticationType)
            {
            case GoogleAuthenticationType.ApiKey:
                string apiKey = ApiKey.Get(context);
                googleSheetProperty = GoogleSheetProperty.Create(apiKey, spreadsheetId);
                break;

            case GoogleAuthenticationType.OAuth2User:
                string credentialID     = CredentialID.Get(context);
                string credentialSecret = CredentialSecret.Get(context);
                googleSheetProperty = Task.Run(async() =>
                {
                    return(await GoogleSheetProperty.Create(credentialID, credentialSecret, spreadsheetId));
                }).Result;
                break;

            case GoogleAuthenticationType.OAuth2ServiceAccount:
                string serviceAccountEmail = ServiceAccountEmail.Get(context);
                string keyPath             = KeyPath.Get(context);
                string password            = Password.Get(context);
                googleSheetProperty = GoogleSheetProperty.Create(keyPath, password, serviceAccountEmail, spreadsheetId);
                break;

            default:
                googleSheetProperty = GoogleSheetProperty.Create("wrongkey", spreadsheetId);
                break;
            }

            if (Body != null)
            {
                context.ScheduleAction <GoogleSheetProperty>(Body, googleSheetProperty, OnCompleted, OnFaulted);
            }
        }