예제 #1
0
        /// <summary>
        /// Run the API call and get the response message and records telemetry event with time to complete api call and status code
        /// </summary>
        /// <param name="entityNameStream">Name of entity to be used for the call</param>
        /// <returns>The HttpResponseMessage containing the Json result</returns>
        protected async Task <HttpResponseMessage> Run(string entityName)
        {
            // Construct the uri to perform Bing Entity Search
            RequestParams = "mkt=en-us&q=" + System.Net.WebUtility.UrlEncode(entityName);
            BuildURI();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            HttpResponseMessage response = null;

            try
            {
                // Execute the REST API GET call asynchronously
                response = await RequestAndRetry(() => CloudServiceClient.GetAsync(URI));

                response.EnsureSuccessStatusCode();
            }
            finally
            {
                stopwatch.Stop();
                string responseStatusCode = Telemetry.PropertyValue.NoResponse;
                if (response != null)
                {
                    responseStatusCode = response.StatusCode.ToString();
                }
                Telemetry.ApplicationLogger.Instance.SubmitApiCallEvent(Telemetry.EventName.CompleteApiCall, Telemetry.EventName.EntitySearchApi, stopwatch.ElapsedMilliseconds, responseStatusCode);
            }

            return(response);
        }
예제 #2
0
        /// <summary>
        /// Run the API call and get the response message and records telemetry event with time to complete api call and status code
        /// </summary>
        /// <param name="entityName">Name of entity to be used for the call</param>
        /// <returns>The HttpResponseMessage containing the Json result</returns>
        protected async Task <HttpResponseMessage> Run(string entityName)
        {
            //<add-endpoint-params-here>

            HttpResponseMessage response = null;

            // Execute the REST API GET call asynchronously and
            // await for non-blocking API call to Bing Entity Search
            response = await RequestAndRetry(() => CloudServiceClient.GetAsync(URI));

            response.EnsureSuccessStatusCode();

            return(response);
        }
        /// <summary>
        /// Run the API call and get the response message and records telemetry event with time to complete api call and status code
        /// </summary>
        /// <param name="entityName">Name of entity to be used for the call</param>
        /// <returns>The HttpResponseMessage containing the Json result</returns>
        protected async Task <HttpResponseMessage> Run(string entityName)
        {
            RequestParams = "q=" + System.Net.WebUtility.UrlEncode(entityName);
            BuildURI();

            HttpResponseMessage response = null;

            // Execute the REST API GET call asynchronously and
            // await for non-blocking API call to Bing Entity Search
            response = await RequestAndRetry(() => CloudServiceClient.GetAsync(URI));

            response.EnsureSuccessStatusCode();

            return(response);
        }
예제 #4
0
        /// <summary>
        /// Run the API call and get the response message and records telemetry event with time to complete api call and status code
        /// </summary>
        /// <param name="ocrResult">OCR results to be used for the call</param>
        /// <returns>The HttpResponseMessage containing the Json result</returns>
        protected async Task <HttpResponseMessage> Run(string ocrResult)
        {
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            queryString["q"] = ocrResult;
            // These optional request parameters are set to their default values
            queryString["timezoneOffset"] = "0";
            queryString["verbose"]        = "false";
            queryString["spellCheck"]     = "false";
            queryString["staging"]        = "false";

            RequestParams = queryString.ToString();
            BuildURI();

            HttpResponseMessage response = await RequestAndRetry(() => CloudServiceClient.GetAsync(URI));

            response.EnsureSuccessStatusCode();

            return(response);
        }
예제 #5
0
        /// Run the stream asynchronously, return the HttpResonseMessage and records telemetry event with time to complete api call and status code
        /// </summary>
        /// <param name="stream">Captured Image</param>
        /// <returns>ResponseMessage of the API request/call</returns>
        protected override async Task <HttpResponseMessage> Run(MemoryStream stream)
        {
            var result = await base.Run(stream);

            if (!result.IsSuccessStatusCode)
            {
                return(null);
            }

            string operationLocation     = result.Headers.GetValues("Operation-Location").FirstOrDefault();
            HttpResponseMessage response = await RequestAndRetry(() => CloudServiceClient.GetAsync(operationLocation));

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                // Pass the exception to the next level
                throw e;
            }
            finally{
                stopwatch.Stop();
                string responseStatusCode = Telemetry.PropertyValue.NoResponse;
                if (result != null)
                {
                    responseStatusCode = result.StatusCode.ToString();
                }
                Telemetry.ApplicationLogger.Instance.SubmitApiCallEvent(Telemetry.EventName.CompleteApiCall, Telemetry.EventName.HandWrittenTextApi, stopwatch.ElapsedMilliseconds, responseStatusCode);
            }

            return(response);
        }