/// <summary>
        /// Populate Hierarchy tree in live mode
        /// </summary>
        /// <param name="ec"></param>
        /// <param name="expandall"></param>
        private void PopulateHierarchyTree(ElementContext ec, bool expandall)
        {
            var begin = DateTime.Now;
            HierarchyNodeViewModel rnvm = null;

            var tm    = Configuration.TreeViewMode;
            var showa = Configuration.ShowAncestry;

            /// in the case that UIElement is not alive any more, it will fail.
            /// we need to handle it properly
            rnvm = ec.DataContext.GetRootNodeHierarchyViewModel(Configuration.ShowAncestry, Configuration.ShowUncertain, this.IsLiveMode);

            // send exception to mode control.
            if (rnvm == null)
            {
                throw new ApplicationException(Properties.Resources.HierarchyControl_PopulateHierarchyTree_No_data_to_populate_hierarchy);
            }

            UpdateTreeView(rnvm, expandall);

            this.SelectedElement = ec.Element;
            var span = DateTime.Now - begin;

            this.tbTimeSpan.Visibility = Visibility.Collapsed;
        }
        /// <summary>
        /// Find, select, and expand to element in tree
        /// </summary>
        /// <param name="node"></param>
        /// <param name="select"></param>
        /// <returns></returns>
        public bool Select(HierarchyNodeViewModel node, int uniqueId)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            foreach (var child in node.Children)
            {
                if (child.Element.UniqueId == uniqueId)
                {
                    if (child.IsSelected)
                    {
                        this.HierarchyActions.SelectedElementChanged();
                    }
                    else
                    {
                        child.IsSelected = true;
                    }
                    return(true);
                }
                else
                {
                    if (Select(child, uniqueId))
                    {
                        child.IsExpanded = true;
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#3
0
        public void GetDescendentStatusCounts()
        {
            A11yElement e = LoadA11yElementsFromJSON("Snapshots/Taskbar.snapshot");

            PopulateChildrenTests(e);
            HierarchyNodeViewModel model = new HierarchyNodeViewModel(e, true, false);

            Assert.AreEqual(23, model.AggregateStatusCounts[(int)ScanStatus.Pass]);
        }
        public 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.IssueLink != null)
            {
                // Bug already filed, open it in a new window
                try
                {
                    System.Diagnostics.Process.Start(vm.IssueLink.OriginalString);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex)
                {
                    ex.ReportException();
                    // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue
                    MessageDialog.Show(ex.InnerException?.Message);
                    vm.IssueDisplayText = null;
                }
#pragma warning restore CA1031 // Do not catch general exception types
            }
            else
            {
                // File a new bug
                var telemetryEvent = TelemetryEventFactory.ForIssueFilingRequest(FileBugRequestSource.Hierarchy);
                Logger.PublishTelemetryEvent(telemetryEvent);

                if (IssueReporter.IsConnected)
                {
                    IssueInformation issueInformation = this.SelectedElement.GetIssueInformation(IssueType.NoFailure);
                    FileIssueAction.AttachIssueData(issueInformation, this.ElementContext.Id, this.SelectedElement.BoundingRectangle,
                                                    this.SelectedElement.UniqueId);
                    IIssueResult issueResult = FileIssueAction.FileIssueAsync(issueInformation);
                    if (issueResult != null)
                    {
                        vm.IssueDisplayText = issueResult.DisplayText;
                        vm.IssueLink        = issueResult.IssueLink;
                    }
                    File.Delete(issueInformation.TestFileName);
                }
                else
                {
                    bool?accepted = MessageDialog.Show(Properties.Resources.HierarchyControl_FileIssue_Configure);
                    if (accepted.HasValue && accepted.Value)
                    {
                        this.HierarchyActions.SwitchToServerLogin();
                    }
                }
            }
        }
        public 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.IssueLink != null)
            {
                // Bug already filed, open it in a new window
                try
                {
                    System.Diagnostics.Process.Start(vm.IssueLink.OriginalString);
                }
                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.IssueDisplayText = null;
                }
            }
            else
            {
                // File a new bug
                Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.By, FileBugRequestSource.Hierarchy.ToString() },
                    { TelemetryProperty.IsAlreadyLoggedIn, IssueReporter.IsConnected.ToString(CultureInfo.InvariantCulture) },
                });

                if (IssueReporter.IsConnected)
                {
                    IssueInformation issueInformation = this.SelectedElement.GetIssueInformation(IssueType.NoFailure);
                    FileIssueAction.AttachIssueData(issueInformation, this.ElementContext.Id, this.SelectedElement.BoundingRectangle,
                                                    this.SelectedElement.UniqueId);
                    IIssueResult issueResult = FileIssueAction.FileIssueAsync(issueInformation);
                    if (issueResult != null)
                    {
                        vm.IssueDisplayText = issueResult.DisplayText;
                        vm.IssueLink        = issueResult.IssueLink;
                    }
                    File.Delete(issueInformation.TestFileName);
                }
                else
                {
                    bool?accepted = MessageDialog.Show(Properties.Resources.HierarchyControl_FileIssue_Configure);
                    if (accepted.HasValue && accepted.Value)
                    {
                        this.HierarchyActions.SwitchToServerLogin();
                    }
                }
            }
        }
 /// <summary>
 /// Clear Tree
 /// </summary>
 public void Clear()
 {
     if (!SelectAction.GetDefaultInstance().IsPaused)
     {
         CleanUpTreeView();
         this.SelectedInHierarchyElement = null;
         this.ElementContext             = null;
         // clean up all data.
         this.SelectedElement           = null;
         this.RootNode                  = null;
         this.btnTestElement.Visibility = Visibility.Collapsed;
         this.btnMenu.Visibility        = Visibility.Collapsed;
     }
 }
        public 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;
            }

            var input = new FileIssueWrapperInput(
                vm,
                this.ElementContext.Id,
                this.HierarchyActions.SwitchToServerLogin,
                () => this._selectedElement.GetIssueInformation(IssueType.NoFailure),
                FileBugRequestSource.Hierarchy);

            FileIssueWrapper.FileIssueFromControl(input);
        }
        /// <summary>
        /// Update Tree View
        /// </summary>
        /// <param name="rnvm">RootNode View Model</param>
        /// <param name="se">Selected element in hierarchy</param>
        private void UpdateTreeView(HierarchyNodeViewModel rnvm, bool expandall)
        {
            if (!SelectAction.GetDefaultInstance().IsPaused)
            {
                CleanUpTreeView();
            }
            this.RootNode = rnvm;
            this.treeviewHierarchy.ItemsSource = new List <HierarchyNodeViewModel>()
            {
                rnvm
            };
            this.treeviewHierarchy.IsEnabled = true;
            this.HierarchyActions.SelectedElementChanged();

            // expand all if it is required.
            if (expandall)
            {
                rnvm.Expand(true);
            }

            textboxSearch.Text = "";
        }
        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();
                    }
                }
            }
        }