Пример #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.subscriptionKey.Text))
            {
                this.requestData.Text = "Please specify subscription key.";
                return;
            }
            if (string.IsNullOrEmpty(this.requestData.Text))
            {
                this.requestData.Text = "Please input request data.";
                return;
            }
            if (string.IsNullOrEmpty(this.urlBox.Text))
            {
                this.requestData.Text = "Please input url.";
                return;
            }

            var client = new AnomalyDetectionClient();

            try
            {
                var url   = this.urlBox.Text;
                var match = Regex.Match(url, "(?<BaseAddress>https?://[^/]+)(?<Url>/*.+)");
                if (match.Success)
                {
                    this.responseData.Clear();
                    SetRequestData();
                    var res = await client.Request(
                        match.Groups["BaseAddress"].Value,
                        match.Groups["Url"].Value,
                        this.subscriptionKey.Text,
                        this.requestData.Text);


                    if (this.radioButton1.Checked)
                    {
                        var response = JsonConvert.DeserializeObject <LResponse>(res);
                        this.responseData.Text = JsonConvert.SerializeObject(response, Formatting.Indented);
                    }
                    else
                    {
                        var response = JsonConvert.DeserializeObject <EResponse>(res);
                        this.responseData.Text = JsonConvert.SerializeObject(response, Formatting.Indented);
                    }
                    this.responseData.Text += "\n========== Response Evaluation ==========\n";
                    this.responseData.Text += "\nUsing the response to do anything you need.\n";
                    this.responseData.Text += "\n========== Evaluation Done ==========\n";
                }
                else
                {
                    this.responseData.Text = "Incorrect endpoint.";
                }
            }
            catch (Exception ex)
            {
                this.responseData.Text = ex.ToString();
            }
        }
Пример #2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.subscriptionKey.Text))
            {
                this.requestData.Text = "Please specify subscription key.";
                return;
            }
            if (string.IsNullOrEmpty(this.requestData.Text))
            {
                this.requestData.Text = "Please input request data.";
                return;
            }
            if (string.IsNullOrEmpty(this.urlBox.Text))
            {
                this.requestData.Text = "Please input url.";
                return;
            }

            var client = new AnomalyDetectionClient();

            try
            {
                var url  = this.urlBox.Text;
                var path = "anomalydetector/v1.0/timeseries/entire/detect";
                if (radioButton1.Checked)
                {
                    path = "anomalydetector/v1.0/timeseries/last/detect";
                }
                this.responseData.Clear();
                SetRequestData();
                var res = await client.Request(
                    url,
                    path,
                    this.subscriptionKey.Text,
                    this.requestData.Text);


                if (this.radioButton1.Checked)
                {
                    var response = JsonConvert.DeserializeObject <LResponse>(res);
                    this.responseData.Text = JsonConvert.SerializeObject(response, Formatting.Indented,
                                                                         new JsonSerializerSettings {
                        ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
                    });
                }
                else
                {
                    var response = JsonConvert.DeserializeObject <EResponse>(res);
                    this.responseData.Text = JsonConvert.SerializeObject(response, Formatting.Indented,
                                                                         new JsonSerializerSettings {
                        ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
                    });
                }
                this.responseData.Text += "\n========== Response Evaluation ==========\n";
                this.responseData.Text += "\nUsing the response to do anything you need.\n";
                this.responseData.Text += "\n========== Evaluation Done ==========\n";
            }
            catch (Exception ex)
            {
                this.responseData.Text = ex.ToString();
            }
        }