示例#1
0
        async static Task <Response> GetStatus(string operation)
        {
            string uri = host + service + operation;

            Console.WriteLine("Calling " + uri + ".");
            PublishKB.Publish();
            return(await Get(uri));
        }
示例#2
0
        async static Task <Response> PostUpdateKB(string kb, string new_kb)
        {
            string uri = host + service + method + kb;

            Console.WriteLine("Calling " + uri + ".");
            PublishKB.Publish();
            return(await Patch(uri, new_kb));
        }
示例#3
0
        public async static void UpdateKB(string kb, string new_kb)
        {
            //if updatetable has't data then add it;
            UpdateTable updatetable = JsonConvert.DeserializeObject <UpdateTable>(new_kb);
            bool        acomplish   = await CotrollerTable.Query(updatetable.add.qnaList[0].questions[0],
                                                                 updatetable.add.qnaList[0].answer);

            if (acomplish)
            {
                CotrollerTable.Insert(updatetable.add.qnaList[0].questions[0],
                                      updatetable.add.qnaList[0].answer, updatetable.update.name);
            }

            var response = await PostUpdateKB(kb, new_kb);

            var operation = response.headers.GetValues("Location").First();

            Console.WriteLine(PrettyPrint(response.response));

            var done = false;

            while (true != done)
            {
                response = await GetStatus(operation);

                Console.WriteLine(PrettyPrint(response.response));

                var fields = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.response);

                String state = fields["operationState"];
                if (state.CompareTo("Running") == 0 || state.CompareTo("NotStarted") == 0)
                {
                    PublishKB.Publish();
                    var wait = response.headers.GetValues("Retry-After").First();
                    Console.WriteLine("Waiting " + wait + " seconds...");
                    Thread.Sleep(Int32.Parse(wait) * 1000);
                    PublishKB.Publish();
                }
                else
                {
                    Console.WriteLine("Press any key to continue.");
                    done = true;
                }
            }
        }
示例#4
0
        async static Task <Response> Patch(string uri, string body)
        {
            using (var client = new HttpClient())
                using (var request = new HttpRequestMessage())
                {
                    request.Method     = new HttpMethod("PATCH");
                    request.RequestUri = new Uri(uri);
                    request.Content    = new StringContent(body, Encoding.UTF8, "application/json");
                    request.Headers.Add("Ocp-Apim-Subscription-Key", key);

                    var response = await client.SendAsync(request);

                    var responseBody = await response.Content.ReadAsStringAsync();

                    PublishKB.Publish();
                    return(new Response(response.Headers, responseBody));
                }
        }
示例#5
0
        static string PrettyPrint(string s)

        {
            PublishKB.Publish();
            return(JsonConvert.SerializeObject(JsonConvert.DeserializeObject(s), Formatting.Indented));
        }