/// <summary> /// Initiates one asynchronous report download. /// </summary> /// <param name="googleAdsService">The Google Ads service client.</param> /// <param name="customerId">The customer ID from which data is requested.</param> /// <param name="queryKey">The name of the query to be downloaded.</param> /// <param name="queryValue">The query for the download request.</param> /// <param name="responses">Collection of all successful report downloads.</param> /// <returns>The asynchronous operation.</returns> /// <exception cref="GoogleAdsException">Thrown if errors encountered in the execution of /// the request.</exception> private async Task <SearchStreamStream> DownloadReportAsync( GoogleAdsServiceClient googleAdsService, long customerId, string queryKey, string queryValue, ConcurrentBag <ReportDownload> responses) { try { // Issue an asynchronous download request. return(await googleAdsService.SearchStreamAsync( customerId.ToString(), queryValue, delegate(SearchGoogleAdsStreamResponse resp) { // Store the results. responses.Add(new ReportDownload() { CustomerId = customerId, QueryKey = queryKey, Response = resp }); } )); } catch (AggregateException ae) { Console.WriteLine($"Download failed for {queryKey} and CID {customerId}!"); GoogleAdsException gae = GoogleAdsException.FromTaskException(ae); if (gae != null) { Console.WriteLine($"Message: {gae.Message}"); Console.WriteLine($"Failure: {gae.Failure}"); Console.WriteLine($"Request ID: {gae.RequestId}"); throw gae; } throw; } }