Exemple #1
0
        /// <summary>Snippet for SearchStream</summary>
        public async Task SearchStreamRequestObject()
        {
            // Snippet: SearchStream(SearchGoogleAdsStreamRequest, CallSettings)
            // Create client
            GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.Create();
            // Initialize request argument(s)
            SearchGoogleAdsStreamRequest request = new SearchGoogleAdsStreamRequest
            {
                CustomerId        = "",
                Query             = "",
                SummaryRowSetting = SummaryRowSettingEnum.Types.SummaryRowSetting.Unspecified,
            };

            // Make the request, returning a streaming response
            GoogleAdsServiceClient.SearchStreamStream response = googleAdsServiceClient.SearchStream(request);

            // Read streaming responses from server until complete
            // Note that C# 8 code can use await foreach
            AsyncResponseStream <SearchGoogleAdsStreamResponse> responseStream = response.GetResponseStream();

            while (await responseStream.MoveNextAsync())
            {
                SearchGoogleAdsStreamResponse responseItem = responseStream.Current;
                // Do something with streamed response
            }
            // The response stream has completed
            // End snippet
        }
        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);
        }
Exemple #4
0
        /// <summary>Snippet for SearchStream</summary>
        /// <remarks>
        /// This snippet has been automatically generated for illustrative purposes only.
        /// It may require modifications to work in your environment.
        /// </remarks>
        public async Task SearchStream()
        {
            // Create client
            GoogleAdsServiceClient googleAdsServiceClient = GoogleAdsServiceClient.Create();
            // Initialize request argument(s)
            string customerId = "";
            string query      = "";

            // Make the request, returning a streaming response
            GoogleAdsServiceClient.SearchStreamStream response = googleAdsServiceClient.SearchStream(customerId, query);

            // Read streaming responses from server until complete
            // Note that C# 8 code can use await foreach
            AsyncResponseStream <SearchGoogleAdsStreamResponse> responseStream = response.GetResponseStream();

            while (await responseStream.MoveNextAsync())
            {
                SearchGoogleAdsStreamResponse responseItem = responseStream.Current;
                // Do something with streamed response
            }
            // The response stream has completed
        }
Exemple #5
0
        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);
        }