Ejemplo n.º 1
0
        private async void CreateAPersonGroup()
        {
            var client      = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", GeneralConstants.OxfordAPIKey);

            var uri = GeneralConstants.str_API_URL + "/face/v1.0/persongroups/" + textBox_PersonGroupId.Text + "?" + queryString;

            HttpResponseMessage response;

            // Request body
            PersonGroup personGroup1 = new PersonGroup
            {
                name     = textBox_PersonGroupName.Text,
                userData = textBox_PersonGroupUserData.Text
            };
            string json = JsonConvert.SerializeObject(personGroup1, Formatting.Indented);

            byte[] byteData = Encoding.UTF8.GetBytes(json);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                response = await client.PutAsync(uri, content);

                textBox_CreateAPersonGroupResult.Text = response.StatusCode.ToString();
            }
        }
Ejemplo n.º 2
0
 private async Task UpdatePersonGroupAsync(PersonGroup group)
 {
     if (await CheckGroupRequestRate())
     {
         _lastGroupRequestTime = DateTime.Now;
         try
         {
             await _client.UpdatePersonGroupAsync(group.PersonGroupId, group.Name, group.UserData);
         }
         catch (ClientException ce)
         {
             Debug.WriteLine(ce.Message);
         }
     }
 }
Ejemplo n.º 3
0
        async void CreateaPersonGroupAsync()
        {
            var client      = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", GeneralConstants.OxfordAPIKey);

            var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/persongroups/" + textBox_PersonGroupId.Text + "?" + queryString;

            HttpResponseMessage response;

            // Request body
            PersonGroup personGroup1 = new PersonGroup
            {
                name     = textBox_PersonGroupName.Text,
                userData = textBox_PersonGroupUserData.Text
            };
            string json = JsonConvert.SerializeObject(personGroup1, Formatting.Indented);

            byte[] byteData = Encoding.UTF8.GetBytes(json);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                response = await client.PutAsync(uri, content);

                json = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    textBox_Output.Text = "Create " + textBox_PersonGroupId.Text + " successfully";
                }
                else
                {
                    textBox_Output.Text = JsonHelper.ConvertJsontoReadableString(json);
                }
            }
        }