public static async Task <bool> UpdateResource(this Endpoint endpoint, ResourceLocations resources)
        {
            using (var httpClient = new HttpClient())
            {
                var uri = string.Format(CultureInfo.InvariantCulture, UpdateResourceUriFormat, endpoint.WorkspaceId, endpoint.WebServiceId, endpoint.Name);
                httpClient.DefaultRequestHeaders.Authorization = GetAuthorizationHeaderAsync(endpoint.PrimaryKey);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var request = new HttpRequestMessage(new HttpMethod("PATCH"), uri);
                request.Content = new ObjectContent(typeof(ResourceLocations), resources, new JsonMediaTypeFormatter());
                var response = await httpClient.SendAsync(request).ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                return(false);
            }
        }
示例#2
0
        static async Task InvokeRetrainModel()
        {
            var resourceLocations = new ResourceLocations()
            {
                Resources = new ResourceLocation[]
                {
                    new ResourceLocation()
                    {
                        Name     = "Iris Classification [trained model]",
                        Location = new AzureBlobDataReference()
                        {
                            BaseLocation     = "",
                            RelativeLocation = "",
                            SasBlobToken     = ""
                        }
                    }
                }
            };

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ConfigurationManager.AppSettings["UpdateApiKey"]);
                using (HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("PATCH"), ConfigurationManager.AppSettings["UpdateClientUrl"]))
                {
                    request.Content = new StringContent(JsonConvert.SerializeObject(resourceLocations), System.Text.Encoding.UTF8, "application/json");

                    HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);

                    if (response.IsSuccessStatusCode)
                    {
                        string result = await response.Content.ReadAsStringAsync();

                        Console.WriteLine("Result: {0}", result);
                        Console.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine("Failed with status code: {0}", response.StatusCode);
                    }
                }
            }
        }