public virtual Task SearchStreamAsync( string customerId, string query, Action <SearchGoogleAdsStreamResponse> responseCallback, SummaryRowSetting summaryRowSetting = SummaryRowSetting.NoSummaryRow, CallSettings callSettings = null) { SearchStreamStream searchStream = this.SearchStream( new SearchGoogleAdsStreamRequest() { CustomerId = customerId.ToString(), Query = query, SummaryRowSetting = summaryRowSetting, }); // Issue a search request. Task t = Task.Run(async() => { while (await searchStream.ResponseStream.MoveNext(CancellationToken.None)) { SearchGoogleAdsStreamResponse resp = searchStream.ResponseStream.Current; responseCallback(resp); } }); return(t); }
/// <summary> /// Runs a streaming search query and returns all rows that matches the query. /// </summary> /// <param name="request">The search request.</param> /// <param name="responseCallback">The callback that will be called for each /// <see cref="SearchGoogleAdsStreamResponse"/> returned by the server.</param> /// <param name="callSettings">The call settings to customize this API call.</param> /// <returns>The search response task.</returns> /// <remarks>This method reads the response stream and invokes the callback for each /// <see cref="SearchGoogleAdsStreamResponse"/> object in the response, you cannot /// iterate further on the <see cref="SearchStreamStream"/> object to obtain results. You /// can however perform additional tasks like retrieving the trailing metadata. If you do /// not care about this additional information, it is fine to ignore the return value /// of this method.</remarks> public virtual Task <SearchStreamStream> SearchStreamAsync( SearchGoogleAdsStreamRequest request, Action <SearchGoogleAdsStreamResponse> responseCallback, CallSettings callSettings = null) { SearchStreamStream searchStream = this.SearchStream(request, callSettings); // Issue a search request. Task <SearchStreamStream> t = Task.Run(async() => { var responseStream = searchStream.GetResponseStream(); bool emptyResult = true; while (await responseStream.MoveNextAsync()) { emptyResult = false; SearchGoogleAdsStreamResponse resp = responseStream.Current; responseCallback(resp); } // Invoke the callback at least once to avoid confusion when there are no results // and no errors. if (emptyResult) { responseCallback(new SearchGoogleAdsStreamResponse()); } return(searchStream); }); return(t); }
public virtual Task <SearchStreamStream> SearchStreamAsync( string customerId, string query, Action <SearchGoogleAdsStreamResponse> responseCallback, SummaryRowSetting summaryRowSetting = SummaryRowSetting.NoSummaryRow, CallSettings callSettings = null) { SearchStreamStream searchStream = this.SearchStream( new SearchGoogleAdsStreamRequest() { CustomerId = customerId.ToString(), Query = query, SummaryRowSetting = summaryRowSetting, }); // Issue a search request. Task <SearchStreamStream> t = Task.Run(async() => { var responseStream = searchStream.GetResponseStream(); bool emptyResult = true; while (await responseStream.MoveNextAsync(CancellationToken.None)) { emptyResult = false; SearchGoogleAdsStreamResponse resp = responseStream.Current; responseCallback(resp); } // Invoke the callback at least once to avoid confusion when there are no results // and no errors. if (emptyResult) { responseCallback(new SearchGoogleAdsStreamResponse()); } return(searchStream); }); return(t); }