예제 #1
0
        public async Task <SpeakerProfilesResponse> GetProfilesAsync(VoiceProfileType profileType)
        {
            string speakerUrl = profileType == VoiceProfileType.TextIndependentVerification ? this.SPEAKER_VERIFICATION_URL : this.SPEAKER_IDENTIFICATION_URL;
            Uri    requestUri = new Uri($"{this.BaseServiceUrl}{speakerUrl}");

            return(await HttpClientUtility.GetAsync <SpeakerProfilesResponse>(requestUri, this.RequestHeaders));
        }
예제 #2
0
        public async Task <VideoIndexerSearchResult> SearchAsync(string query = "", string face = "")
        {
            if (string.IsNullOrEmpty(query) == true && string.IsNullOrEmpty(face) == true)
            {
                return(default(VideoIndexerSearchResult));
            }

            Dictionary <string, string> queryParams = new Dictionary <string, string>()
            {
                { "query", WebUtility.UrlEncode(query) },
                { "face", WebUtility.UrlEncode(face) },
            };

            IEnumerable <string> queryString = queryParams
                                               .Where(p => string.IsNullOrEmpty(p.Value) == false)
                                               .Select(p => p.Key + "=" + p.Value);

            string searchQuery = queryString.Count() == 1 ? queryString.FirstOrDefault() : string.Join("&", queryString);

            // Get request uri
            string searchUrl  = this.BaseServiceUrl + "?" + searchQuery;
            Uri    requestUri = new Uri(searchUrl);

            // Get response
            VideoIndexerSearchResult result = await HttpClientUtility.GetAsync <VideoIndexerSearchResult>(requestUri, this.RequestHeaders);

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Query LUIS service to obtain results
        /// </summary>
        public async Task <LUISResult> QueryAsync(string query)
        {
            if (string.IsNullOrEmpty(query) == true)
            {
                return(default(LUISResult));
            }

            query = WebUtility.UrlEncode(query);

            // Get request uri
            string requestUrl = this.BaseServiceUrl + "&verbose=true&timezoneOffset=0&q=" + query;
            Uri    requestUri = new Uri(requestUrl);

            LUISResult result = await HttpClientUtility.GetAsync <LUISResult>(requestUri, this.RequestHeaders);

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Search web pages with Bing service
        /// </summary>
        public async Task <BingWebSearchResult> SearchWebAsync(string query, int count = 10, int offset = 0, string market = "en-us", SafeSearch safeSearch = SafeSearch.Strict)
        {
            if (string.IsNullOrEmpty(query) == true)
            {
                return(default(BingWebSearchResult));
            }
            else if (query.Length > MAX_QUERY_LENGTH)
            {
                query = query.Substring(0, MAX_QUERY_LENGTH);
            }

            query = WebUtility.UrlEncode(query);

            // Get request uri
            string searchUrl  = string.Format(this.BaseServiceUrl + "search?q={0}&count={1}&offset={2}&mkt={3}&safesearch={4}", query, count, offset, market, safeSearch);
            Uri    requestUri = new Uri(searchUrl);

            // Get response
            BingWebSearchResult result = await HttpClientUtility.GetAsync <BingWebSearchResult>(requestUri, this.RequestHeaders);

            return(result);
        }
예제 #5
0
        private async void btnInitData_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var client = new HttpClientUtility().GetHttpClient(this.txtToken.Text.Trim());

                HttpResponseMessage response = await client.GetAsync("api/values");

                response.EnsureSuccessStatusCode();

                string content = await response.Content.ReadAsStringAsync();

                BaseViewModel model = JsonConvert.DeserializeObject <BaseViewModel>(content);

                this.dgUser.ItemsSource = model.data;
                this.lblTotal.Content   = "总条数:" + model.total;
            }
            catch (HttpRequestException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #6
0
        private async Task <HandwritingRecognitionResult> GetResultFromOperationResponse(HttpResponseMessage response)
        {
            // Process operation
            if (response.Headers.Contains(this.HEADER_OPLOC_KEY) == false)
            {
                throw new InvalidOperationException("No operation-location value returned from initial request.");
            }

            Uri opLocationUri = new Uri(response.Headers.GetValues(this.HEADER_OPLOC_KEY).First());

            HandwritingRecognitionOperationResult opResult = new HandwritingRecognitionOperationResult();

            int i = 0;

            while (i++ < HttpClientUtility.RETRY_COUNT)
            {
                // Get the operation result
                opResult = await HttpClientUtility.GetAsync <HandwritingRecognitionOperationResult>(opLocationUri, this.RequestHeaders);

                // Wait if operation is running or has not started
                if (opResult.Status == HandwritingRecognitionOperationResult.HandwritingRecognitionOperationStatus.NotStarted ||
                    opResult.Status == HandwritingRecognitionOperationResult.HandwritingRecognitionOperationStatus.Running)
                {
                    await Task.Delay(HttpClientUtility.RETRY_DELAY);
                }
                else
                {
                    break;
                }
            }

            if (opResult.Status != HandwritingRecognitionOperationResult.HandwritingRecognitionOperationStatus.Succeeded)
            {
                throw new Exception($"Handwriting recognition operation was not successful with status: {opResult.Status}");
            }

            return(opResult.Result);
        }
예제 #7
0
        private async Task <AnalyzeFormResult> GetResultFromResponse(HttpResponseMessage response)
        {
            // Process operation
            if (response.Headers.Contains(this.HEADER_OPERATION_LOCATION_KEY) == false)
            {
                throw new InvalidOperationException("No operation-location value returned from initial request.");
            }

            Uri locationUri = new Uri(response.Headers.GetValues(this.HEADER_OPERATION_LOCATION_KEY).First());

            var opResult = new AnalyzeResultResponse();

            int i = 0;

            while (i++ < RETRY_COUNT)
            {
                // Get the operation result
                opResult = await HttpClientUtility.GetAsync <AnalyzeResultResponse>(locationUri, this.RequestHeaders);

                // Wait if operation is running or has not started
                if (opResult.Status == "notStarted" || opResult.Status == "running")
                {
                    await Task.Delay(RETRY_DELAY);
                }
                else
                {
                    break;
                }
            }

            if (opResult.Status != "succeeded")
            {
                throw new Exception($"Form recognition operation was not successful with status: {opResult.Status}");
            }

            return(opResult.AnalyzeResult);
        }
예제 #8
0
        /// <summary>
        /// Get languages currently supported by Translator Text API
        /// </summary>
        /// <returns></returns>
        public async Task <SupportedLanguages> GetSupportedLanguagesAsync()
        {
            Uri requestUri = new Uri($"{this.BaseServiceUrl}/languages?{this.API_VERSION}");

            return(await HttpClientUtility.GetAsync <SupportedLanguages>(requestUri, this.RequestHeaders));
        }
예제 #9
0
        public async Task <ModelResultResponse> GetCustomModelAsync(Guid modelId)
        {
            Uri requestUri = new Uri($"{this.BaseServiceUrl}/custom/models/{modelId}");

            return(await HttpClientUtility.GetAsync <ModelResultResponse>(requestUri, this.RequestHeaders));
        }