Exemplo n.º 1
0
        /// <summary>
        /// This method has a lot of logic that is specific to the sample. To process a request you can easily just call the Execute method on the request.
        /// </summary>
        /// <param name="request"></param>
        private async void ProcessRequest(BaseRestRequest request)
        {
            try
            {
                RequestProgressBar.Visibility = Visibility.Visible;
                RequestProgressBarText.Text   = string.Empty;

                ResultTreeView.ItemsSource = null;

                var start = DateTime.Now;

                //Execute the request.
                var response = await request.Execute((remainingTime) =>
                {
                    if (remainingTime > -1)
                    {
                        _time = TimeSpan.FromSeconds(remainingTime);

                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            RequestProgressBarText.Text = string.Format("Time remaining {0} ", _time);
                        });

                        _timer.Start();
                    }
                });

                RequestUrlTbx.Text = request.GetRequestUrl();

                var end = DateTime.Now;

                var processingTime = end - start;

                ProcessingTimeTbx.Text        = string.Format(CultureInfo.InvariantCulture, "{0:0} ms", processingTime.TotalMilliseconds);
                RequestProgressBar.Visibility = Visibility.Collapsed;

                var nodes = new List <ObjectNode>();
                var tree  = await ObjectNode.ParseAsync("result", response);

                nodes.Add(tree);
                ResultTreeView.ItemsSource = nodes;

                ResponseTab.IsSelected = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            _timer.Stop();
            RequestProgressBar.Visibility = Visibility.Collapsed;
        }
Exemplo n.º 2
0
        private static async Task <Resource[]> GetResoucesFromRequestAsync(BaseRestRequest request)
        {
            var response = await request.Execute();

            return(response.ResourceSets[0].Resources);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method triggers the request by calling the execute method of the BingMaps RESTToolKit.
        /// <param name="request"></param>
        private async void ProcessRequest(BaseRestRequest request)
        {
            try
            {
                RequestProgressBar.Visibility = Visibility.Visible;
                RequestProgressBarText.Text   = string.Empty;

                ResultTreeView.ItemsSource = null;

                var start = DateTime.Now;

                //Executes the request.
                var response = await request.Execute((remainingTime) =>
                {
                    if (remainingTime > -1)
                    {
                        _time = TimeSpan.FromSeconds(remainingTime);

                        RequestProgressBarText.Text = string.Format("Time remaining {0} ", _time);

                        _timer.Start();
                    }
                });

                RequestUrlTbx.Text = request.GetRequestUrl();

                var end            = DateTime.Now;
                var processingTime = end - start;
                var nodes_warnings = new List <ObjectNode>();
                var nodes_all      = new List <ObjectNode>();
                //Takes any Object and generates an Object Tree.
                var tree = await ObjectNode.ParseAsync("result", response);

                //List of warnings for trim function and visualisation in the view
                var    list_warnings   = new List <KeyValuePair <string, string> >();
                string filter_severity = "Severity";

                ProcessingTimeTbx.Text = string.Format(CultureInfo.InvariantCulture, "{0:0} ms",
                                                       processingTime.TotalMilliseconds);
                RequestProgressBar.Visibility = Visibility.Collapsed;

                nodes_all.Add(tree);

                SeverityRatings_panel.Children.Clear();

                nodes_warnings.Add(tree);
                ResultTreeViewFull.ItemsSource = nodes_all;

                TrimTree(nodes_warnings, filter_severity, list_warnings);

                ResultTreeView.ItemsSource = nodes_warnings;

                foreach (var element in list_warnings)
                {
                    switch (element.Value)
                    {
                    case "\"Minor\"":
                    case "\"LowImpact\"":
                        TextBlock Minor_Low_sev = new TextBlock
                        {
                            Text       = element.ToString(),
                            Background = Brushes.LightGreen,
                            FontSize   = 20
                        };
                        SeverityRatings_panel.Children.Add(Minor_Low_sev);
                        break;

                    case "\"Moderate\"":
                        TextBlock Moderate_sev = new TextBlock
                        {
                            Text       = element.ToString(),
                            Background = Brushes.Orange,
                            FontSize   = 20
                        };
                        SeverityRatings_panel.Children.Add(Moderate_sev);
                        break;

                    case "\"Serious\"":
                        TextBlock Serious_sev = new TextBlock
                        {
                            Text       = element.ToString(),
                            Background = Brushes.PaleVioletRed,
                            FontSize   = 20
                        };
                        SeverityRatings_panel.Children.Add(Serious_sev);
                        break;

                    default:
                        break;
                    }
                }

                ProcessWarnings(list_warnings);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            _timer.Stop();
            RequestProgressBar.Visibility = Visibility.Collapsed;
        }