Exemple #1
0
        /// <summary>
        /// Handles click on file bug button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFileBug_Click(object sender, RoutedEventArgs e)
        {
            var vm = ((Button)sender).Tag as RuleResultViewModel;

            if (vm.BugId.HasValue)
            {
                // Bug already filed, open it in a new window
                try
                {
                    var bugUrl = BugReporter.GetExistingBugUriAsync(vm.BugId.Value).Result.ToString();
                    Process.Start(bugUrl);
                }
                catch (Exception ex)
                {
                    // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue
                    MessageDialog.Show(ex.InnerException?.Message);
                    vm.BugId = null;
                }
            }
            else
            {
                // File a new bug
                Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string>()
                {
                    { TelemetryProperty.By, FileBugRequestSource.AutomatedChecks.ToString() },
                    { TelemetryProperty.IsAlreadyLoggedIn, BugReporter.IsConnected.ToString(CultureInfo.InvariantCulture) }
                });

                // TODO: figuring out whether a team project has been chosen should not require
                //  looking at the most recent connection, this should be broken out
                if (BugReporter.IsConnected && Configuration.SavedConnection?.IsPopulated == true)
                {
                    Action <int> updateZoom = (int x) => Configuration.ZoomLevel = x;

                    (int?bugId, string newBugId) = FileBugAction.FileNewBug(vm.GetBugInformation(), Configuration.SavedConnection,
                                                                            Configuration.AlwaysOnTop, Configuration.ZoomLevel, updateZoom);

                    vm.BugId = bugId;

                    // Check whether bug was filed once dialog closed & process accordingly
                    if (vm.BugId.HasValue)
                    {
                        try
                        {
                            var sc = DispatcherSynchronizationContext.Current;
                            vm.LoadingVisibility = Visibility.Visible;
                            var task = FileBugAction.AttachBugData(this.ElementContext.Id, vm.Element.BoundingRectangle, vm.Element.UniqueId, newBugId, vm.BugId.Value);

#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler
                            task.ContinueWith(delegate
                            {
                                sc.Post(delegate {
                                    vm.LoadingVisibility = Visibility.Collapsed;

                                    if (!task.Result)
                                    {
                                        MessageDialog.Show(Properties.Resources.AutomatedChecksControl_btnFileBug_Click_There_was_an_error_identifying_the_created_bug__This_may_occur_if_the_ID_used_to_create_the_bug_is_removed_from_its_AzureDevOps_description__Attachments_have_not_been_uploaded);
                                        vm.BugId = null;
                                    }
                                }, null);
                            });
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler
                        }
                        catch (Exception)
                        {
                            vm.LoadingVisibility = Visibility.Collapsed;
                        }
                    }
                }
                else
                {
                    bool?accepted = MessageDialog.Show(Properties.Resources.AutomatedChecksControl_btnFileBug_Click_Please_sign_into_Azure_DevOps_ensure_both_AzureDevOps_account_name_and_team_project_are_selected);
                    if (accepted.HasValue && accepted.Value)
                    {
                        SwitchToServerLogin();
                    }
                }
            }
        }
        /// <summary>
        /// Handles click on file bug button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnFileBug_Click(object sender, RoutedEventArgs e)
        {
            var vm = ((Button)sender).Tag as ScanListViewItemViewModel;

            if (vm.BugId.HasValue)
            {
                // Bug already filed, open it in a new window
                try
                {
                    var bugUri = await BugReporter.GetExistingBugUriAsync(vm.BugId.Value).ConfigureAwait(true);

                    System.Diagnostics.Process.Start(bugUri.ToString());
                }
                catch (Exception ex)
                {
                    // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue
                    MessageDialog.Show(ex.InnerException?.Message);
                    vm.BugId = null;
                }
            }
            else
            {
                // File a new bug
                Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string>()
                {
                    { TelemetryProperty.By, FileBugRequestSource.HowtoFix.ToString() },
                    { TelemetryProperty.IsAlreadyLoggedIn, BugReporter.IsConnected.ToString(CultureInfo.InvariantCulture) }
                });

                // TODO: figuring out whether a team project has been chosen should not require
                //  looking at the most recent connection, this should be broken out
                if (BugReporter.IsConnected && Configuration.SavedConnection?.IsPopulated == true)
                {
                    Action <int> updateZoom = (int x) => Configuration.ZoomLevel = x;
                    (int?bugId, string newBugId) = FileBugAction.FileNewBug(vm.GetBugInformation(), Configuration.SavedConnection, Configuration.AlwaysOnTop, Configuration.ZoomLevel, updateZoom);

                    vm.BugId = bugId;

                    // Check whether bug was filed once dialog closed & process accordingly
                    if (vm.BugId.HasValue)
                    {
                        vm.LoadingVisibility = Visibility.Visible;
                        try
                        {
                            var success = await FileBugAction.AttachBugData(this.EcId, vm.Element.BoundingRectangle,
                                                                            vm.Element.UniqueId, newBugId, vm.BugId.Value).ConfigureAwait(false);

                            if (!success)
                            {
                                MessageDialog.Show(Properties.Resources.ScannerResultControl_btnFileBug_Click_There_was_an_error_identifying_the_created_bug_This_may_occur_if_the_ID_used_to_create_the_bug_is_removed_from_its_AzureDevOps_description_Attachments_have_not_been_uploaded);
                                vm.BugId = null;
                            }
                            vm.LoadingVisibility = Visibility.Collapsed;
                        }
                        catch (Exception)
                        {
                            vm.LoadingVisibility = Visibility.Collapsed;
                        }
                    }
                }
                else
                {
                    bool?accepted = MessageDialog.Show(Properties.Resources.ScannerResultControl_btnFileBug_Click_Please_log_in_to_AzureDevOps_ensure_both_AzureDevOps_account_name_and_team_project_are_selected);
                    if (accepted.HasValue && accepted.Value)
                    {
                        SwitchToServerLogin();
                    }
                }
            }
        }
        public async void FileBug(HierarchyNodeViewModel vm = null)
        {
            vm = vm ?? this.treeviewHierarchy.SelectedItem as HierarchyNodeViewModel;

            if (vm == null)
            {
                MessageDialog.Show(Properties.Resources.HierarchyControl_FileBug_Could_not_find_the_selected_item__the_bug_filing_is_canceled);
                return;
            }

            if (vm.BugId.HasValue)
            {
                // Bug already filed, open it in a new window
                try
                {
                    Uri uri = await BugReporter.GetExistingBugUriAsync(vm.BugId.Value).ConfigureAwait(true);

                    var bugUrl = uri.ToString();
                    System.Diagnostics.Process.Start(bugUrl);
                }
                catch (Exception ex)
                {
                    // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue
                    MessageDialog.Show(ex.InnerException?.Message);
                    vm.BugId = null;
                }
            }
            else
            {
                // File a new bug
                Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.By, FileBugRequestSource.Hierarchy.ToString() },
                    { TelemetryProperty.IsAlreadyLoggedIn, BugReporter.IsConnected.ToString(CultureInfo.InvariantCulture) },
                });

                if (BugReporter.IsConnected && Configuration.SavedConnection?.IsPopulated == true)
                {
                    Action <int> updateZoom = (int x) => Configuration.ZoomLevel = x;
                    (int?bugId, string newBugId) = FileBugAction.FileNewBug(this.SelectedElement.GetBugInformation(BugType.NoFailure), Configuration.SavedConnection, Configuration.AlwaysOnTop, Configuration.ZoomLevel, updateZoom);

                    vm.BugId = bugId;

                    // Check whether bug was filed once dialog closed & process accordingly
                    if (vm.BugId.HasValue)
                    {
                        try
                        {
                            var success = await FileBugAction.AttachBugData(this.ElementContext.Id, this.SelectedElement.BoundingRectangle,
                                                                            this.SelectedElement.UniqueId, newBugId, vm.BugId.Value).ConfigureAwait(false);

                            if (!success)
                            {
                                MessageDialog.Show(Properties.Resources.HierarchyControl_FileBug_There_was_an_error_identifying_the_created_bug_This_may_occur_if_the_ID_used_to_create_the_bug_is_removed_from_its_Azure_DevOps_description_Attachments_have_not_been_uploaded);
                                vm.BugId = null;
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else
                {
                    bool?accepted = MessageDialog.Show(Properties.Resources.HierarchyControl_FileBug_Please_sign_in_to_Azure_DevOps_specify_both_Azure_DevOps_organization_name_and_project);
                    if (accepted.HasValue && accepted.Value)
                    {
                        this.HierarchyActions.SwitchToServerLogin();
                    }
                }
            }
        }