Exemplo n.º 1
0
        /// <summary>
        /// Run the HTTP call to get a list of similar products
        /// </summary>
        /// <param name="stream">Captured Image</param>
        /// <returns>The HTTP response for the call</returns>
        protected override async Task <HttpResponseMessage> Run(MemoryStream stream)
        {
            var strContent = new StreamContent(stream);

            strContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
            {
                FileName = "AnyNameWorks"
            };

            var content = new MultipartFormDataContent();

            content.Add(strContent);

            // Execute the REST API call.
            var result = await RequestAndRetry(() => CloudServiceClient.PostAsync(URI, content));

            result.EnsureSuccessStatusCode();
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Make the API call with supplied request contents and records telemetry event with time to complete api call and status code
        /// </summary>
        /// <param name="stream">MemoryStream to read the image byte array</param>
        /// <returns>String response from the API call</returns>
        protected override async Task <HttpResponseMessage> Run(MemoryStream stream)
        {
            var strContent = new StreamContent(stream);

            strContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
            {
                FileName = "AnyNameWorks"
            };

            var content = new MultipartFormDataContent();

            content.Add(strContent);

            HttpResponseMessage result    = null;
            Stopwatch           stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                // Execute the REST API call.
                result = await RequestAndRetry(() => CloudServiceClient.PostAsync(URI, content));

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

            return(result);
        }