/// <summary> /// Fetches and prints all the results from running the mutate job. /// </summary> /// <param name="mutateJobService">The mutate job service.</param> /// <param name="mutateJobResourceName">The resource name of mutate job to get its results.</param> private static void FetchAndPrintResults(MutateJobServiceClient mutateJobService, string mutateJobResourceName) { Console.WriteLine($"Mutate job with resource name '{mutateJobResourceName}' has " + $"finished. Now, printing its results..."); ListMutateJobResultsRequest request = new ListMutateJobResultsRequest() { ResourceName = mutateJobResourceName, PageSize = PAGE_SIZE, }; ListMutateJobResultsResponse resp = new ListMutateJobResultsResponse(); // Gets all the results from running mutate job and prints their information. foreach (MutateJobResult mutateJobResult in mutateJobService.ListMutateJobResults(request)) { if (!mutateJobResult.IsFailed) { Console.WriteLine($"Mutate job result #{mutateJobResult.OperationIndex} is " + $"successful and response is of type " + $"'{mutateJobResult.MutateOperationResponse.ResponseCase}'."); } else { Console.WriteLine($"Mutate job result #{mutateJobResult.OperationIndex} " + $"failed with error message {mutateJobResult.Status.Message}."); foreach (GoogleAdsError error in mutateJobResult.Failure.Errors) { Console.WriteLine($"Error found: {error}."); } } } }
/// <summary> /// Requests the API to run the mutate job for executing all uploaded mutate job /// operations. /// </summary> /// <param name="mutateJobService">The mutate job service client.</param> /// <param name="mutateJobResourceName">The resource name of mutate job to be run.</param> /// <returns>The operation response from running mutate job.</returns> private Operation <Empty, MutateJobMetadata> RunMutateJob( MutateJobServiceClient mutateJobService, string mutateJobResourceName) { Operation <Empty, MutateJobMetadata> operationResponse = mutateJobService.RunMutateJob(mutateJobResourceName); Console.WriteLine($"Mutate job with resource name '{mutateJobResourceName}' has been " + $"executed."); return(operationResponse); }
/// <summary> /// Creates the mutate job. /// </summary> /// <param name="mutateJobService">The mutate job service.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>The resource name of the created mutate job.</returns> private static string CreateMutateJob(MutateJobServiceClient mutateJobService, long customerId) { string mutateJobResourceName = mutateJobService.CreateMutateJob(customerId.ToString()).ResourceName; Console.WriteLine($"Created a mutate job with resource name: " + $"'{mutateJobResourceName}'."); return(mutateJobResourceName); }
/// <summary> /// Adds all mutate job operations to the mutate job. As this is the first time for this /// mutate job, the sequence token is not set. The response will contain the next sequence /// token that you can use to upload more operations in the future. /// </summary> /// <param name="mutateJobService">The mutate job service.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="mutateJobResourceName">The resource name of mutate job to which the mutate /// job operations will be added. /// </param> private static void AddAllMutateJobOperations(MutateJobServiceClient mutateJobService, long customerId, string mutateJobResourceName) { AddMutateJobOperationsResponse response = mutateJobService.AddMutateJobOperations( new AddMutateJobOperationsRequest() { ResourceName = mutateJobResourceName, MutateOperations = { BuildAllOperations(customerId) } }); Console.WriteLine($"{response.TotalOperations} mutate operations have been added" + $" so far."); // You can use this next sequence token for calling AddMutateJobOperations() next time. Console.WriteLine($"Next sequence token for adding next operations is " + $"'{response.NextSequenceToken}'."); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> public void Run(GoogleAdsClient client, long customerId) { // Gets the MutateJobService. MutateJobServiceClient mutateJobService = client.GetService(Services.V3.MutateJobService); try { string mutateJobResourceName = CreateMutateJob(mutateJobService, customerId); AddAllMutateJobOperations(mutateJobService, customerId, mutateJobResourceName); Operation <Empty, MutateJobMetadata> operationResponse = RunMutateJob(mutateJobService, mutateJobResourceName); PollMutateJob(operationResponse); FetchAndPrintResults(mutateJobService, mutateJobResourceName); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }