public void TestExport()
 {
     string projectId = Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID");
     Options options = new Options();
     var args = new[] { "-p", projectId, "-o", $"gs://{projectId}/test_table.csv" };
     Assert.IsTrue(Parser.Default.ParseArguments(args, options));
     var job = Program.ExportTable(options);
     Assert.AreEqual("DONE", job.Status.State);
 }
 public BookDetailLookup(string projectId, ILoggerFactory loggerFactory,
     Options options = null)
 {
     options = options ?? new Options();
     _loggerFactory = loggerFactory;
     _topicPath = $"projects/{projectId}/topics/{options.TopicName}";
     _subscriptionPath = $"projects/{projectId}/subscriptions/{options.SubscriptionName}";
     var credentials = Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync()
         .Result;
     credentials = credentials.CreateScoped(new[] { PubsubService.Scope.Pubsub });
     _pubsub = new PubsubService(new BaseClientService.Initializer()
     {
         HttpClientInitializer = credentials,
     });
 }
 public BookDetailLookup(string projectId, Options options = null)
 {
     options = options ?? new Options();
     // [START pubsubpaths]
     _topicPath = $"projects/{projectId}/topics/{options.TopicName}";
     _subscriptionPath = $"projects/{projectId}/subscriptions/{options.SubscriptionName}";
     // [END pubsubpaths]
     var credentials = Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync()
         .Result;
     if (credentials.IsCreateScopedRequired)
     {
         credentials = credentials.CreateScoped(new[] { PubsubService.Scope.Pubsub });
     }
     _pubsub = new PubsubService(new BaseClientService.Initializer()
     {
         HttpClientInitializer = credentials,
     });
 }
Example #4
0
 static void Main(string[] args)
 {
     var options = new Options();
     if (Parser.Default.ParseArguments(args, options))
     {
         var response = ExportTable(options);
         Console.WriteLine($"Job {response.JobReference.JobId} created with status { response.Status.State }.");
     }
     else
     {
         Console.WriteLine(options.GetUsage());
     }
     Console.WriteLine("Press any key...");
     Console.ReadKey();
 }
Example #5
0
 // [START ExportTable]
 public static Job ExportTable(Options options)
 {
     var bigquery = CreateAuthorizedClient();
     var jobId = Guid.NewGuid().ToString();
     var request = new JobsResource.InsertRequest(bigquery, new Job
     {
         Configuration = new JobConfiguration
         {
             Extract = new JobConfigurationExtract
             {
                 SourceTable = new TableReference
                 {
                     ProjectId = options.ProjectId,
                     DatasetId = options.DatasetId,
                     TableId = options.TableId,
                 },
                 DestinationUris = new[] { options.CloudStoragePath },
                 DestinationFormat = options.ExportFormat,
                 Compression = options.Compression
             }
         },
         JobReference = new JobReference
         {
             ProjectId = options.ProjectId,
             JobId = jobId,
         }
     }, options.ProjectId);
     return request.Execute();
 }