示例#1
0
        public async Task <PersonDto[]> RecognizePersonsAsync(Stream picture)
        {
            using (var streamContent = new StreamContent(picture))
                using (var formData = new MultipartFormDataContent())
                {
                    // Creates uri from configuration
                    var uri = new Uri($"{ApiBasePath}/{PersonsRecognitionQuery}");

                    // Adds content to multipart form data
                    formData.Add(streamContent, "file", $"{Guid.NewGuid()}.jpg");

                    // Get authorization token
                    string token = (await TokenManagerService.GetToken()).AccessToken;

                    _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    HttpResponseMessage resp = await _httpClient.PostAsync(uri, formData);

                    if (resp.IsSuccessStatusCode)
                    {
                        var test = JsonConvert.DeserializeObject <PersonDto[]>(await resp.Content.ReadAsStringAsync());
                        return(test);
                    }

                    var error = JsonConvert.DeserializeObject <WebServiceError>(await resp.Content.ReadAsStringAsync());
                    Debug.WriteLine($"WebServiceError : {error.HttpStatus} - {error.ErrorCode} : {error.ErrorMessage}");
                    return(null);
                }
        }
示例#2
0
        public async Task UpdatePersonInformation(PersonUpdateDto personUpdateDto)
        {
            // Creates uri from configuration
            var uri = new Uri($"{ApiBasePath}/{PersonUpdateInformationQuery}");

            Debug.WriteLine("Debug: " + uri);

            // Get authorization token
            string token = (await TokenManagerService.GetToken()).AccessToken;

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            var content = new StringContent(JsonConvert.SerializeObject(personUpdateDto), Encoding.UTF8, "application/json");

            HttpResponseMessage resp = await _httpClient.PostAsync(uri, content);

            if (!resp.IsSuccessStatusCode)
            {
                var error = JsonConvert.DeserializeObject <WebServiceError>(await resp.Content.ReadAsStringAsync());
                Debug.WriteLine($"WebServiceError : {error.HttpStatus} - {error.ErrorCode} : {error.ErrorMessage}");
            }
        }