Example #1
0
        private void DataGrid1_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DataGrid1.SelectedItem is ApiPath)
            {
                _apiDoc.BaseUri = TbBaseUri.Text;
                ApiPath apiPath = DataGrid1.SelectedItem as ApiPath;
                //string resMsg = WebApiHelper.GetString(path.GetUrl());
                //TbResult.Text = string.Format("path:\n{0}\nResult:\n{1}\n", path, resMsg);

                string url = apiPath.GetUrl();
                if (string.IsNullOrEmpty(url))
                {
                    TbResult.Text = string.Format("path:\n{0}\nStatus:{1}\nResult:\n{2}\n", apiPath, "NoUri", "");
                    apiPath.SetResultState("NoUri");
                }
                else
                {
                    try
                    {
                        var client = new HttpClient();
                        HttpResponseMessage resMsg = client.GetAsync(url).Result;
                        var result = resMsg.Content.ReadAsStringAsync().Result;
                        //string resMsg=WebApiHelper.GetString(url);
                        TbResult.Text = string.Format("url:\n{0}\npath:\n{1}\nStatus:{2}\nResult:\n{3}\n", url, apiPath, resMsg.StatusCode, result);
                        apiPath.SetResultState(resMsg.StatusCode.ToString());
                    }
                    catch (Exception ex)
                    {
                        TbResult.Text = string.Format("url:\n{0}\npath:\n{1}\nStatus:{2}\nResult:\n{3}\n", url, apiPath, "Error", ex);
                    }
                }
            }
            else
            {
                string url = DataGrid1.SelectedItem as string;
                TbResult.Text = url;
            }
        }