/// <summary>
        /// When snapshot is invoked, Request appropriate mode change.
        /// </summary>
        /// <param name="method">by which way : Beaker or Hotkey</param>
        internal void HandleSnapshotRequest(TestRequestSources method)
        {
            if (this.CurrentPage == AppPage.Inspect && this.CurrentView == InspectView.Live)
            {
                if (ctrlLiveMode.SelectedInHierarchyElement != null)
                {
                    if (ctrlLiveMode.SelectedInHierarchyElement.Item2 == 0)
                    {
                        SetDataAction.ReleaseDataContext(SelectAction.GetDefaultInstance().GetSelectedElementContextId().Value);
                    }
                    else
                    {
                        var sa = SelectAction.GetDefaultInstance();
                        sa.SetCandidateElement(ctrlLiveMode.SelectedInHierarchyElement.Item1, ctrlLiveMode.SelectedInHierarchyElement.Item2);
                        sa.Select();
                    }
                }

                // Based on Ux model feedback from PM team, we decided to go to AutomatedTestResults as default page view for snapshot.
                StartTestMode(TestView.AutomatedTestResults);

                Logger.PublishTelemetryEvent(TelemetryAction.Test_Requested, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.By, method.ToString() },
                    { TelemetryProperty.Scope, SelectAction.GetDefaultInstance().Scope.ToString() }
                });
            }
            HighlightAction.GetDefaultInstance().Clear();
            UpdateMainWindowUI();
        }
        /// <summary>
        /// Handle toggle highlighter request
        /// </summary>
        /// <returns></returns>
        public bool ToggleHighlighter()
        {
            var enabled = !HighlightAction.GetDefaultInstance().IsEnabled;

            HighlightAction.GetDefaultInstance().IsEnabled = enabled;
            return(enabled);
        }
        /// <summary>
        /// Handle configuration changed
        /// - apply changes as needed
        /// - Send telemetry
        /// </summary>
        /// <param name="testconfig"></param>
        internal void HandleConfigurationChanged(IReadOnlyDictionary <string, object> changes)
        {
            HotkeyHandler?.Dispose();
            InitHotKeys();

            var configManager = ConfigurationManager.GetDefaultInstance();

            SelectAction.GetDefaultInstance().IntervalMouseSelector = configManager.AppConfig.MouseSelectionDelayMilliSeconds;
            this.Topmost = configManager.AppConfig.AlwaysOnTop;
            this.ctrlTestMode.ctrlTabStop.SetHotkeyText(configManager.AppConfig.HotKeyForRecord);

            HighlightAction.GetDefaultInstance().HighlighterMode = configManager.AppConfig.HighlighterMode;

            configManager.TestConfig = TestSetting.GenerateSuiteConfiguration(RuleSelection.SuiteConfigurationType.Default);

            InitSelectActionMode();

            HideConfigurationMode();

            if (changes != null && changes.ContainsKey(ConfigurationModel.keyFontSize))
            {
                SetFontSize();
            }

            UpdateMainWindowUI();
            this.btnConfig.Focus();
        }
        /// <summary>
        /// Start Live Monitor mode
        /// show only single selected item information
        /// </summary>
        private void StartLiveMode()
        {
            if (!(this.CurrentPage == AppPage.Inspect && (InspectView)this.CurrentView == InspectView.Live))
            {
                this.CurrentPage = AppPage.Inspect;
                this.CurrentView = InspectView.Live;
                PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString());

                // make sure that highlighter is cleared for new selection.
                HighlightAction.GetDefaultInstance().Clear();

                SetWindowForLiveMode();
            }

            // set the state to Capturing view. it will prevent testing for safety.
            this.CurrentView = InspectView.CapturingData;

            var ecId = SelectAction.GetDefaultInstance().GetSelectedElementContextId();

            if (ecId != null)
            {
                // make sure that no more selection is requested.
                DisableElementSelector();

                // Pass the currently selected Element Context
                this.ctrlCurMode.SetElement(ecId.Value);
            }
            else
            {
                // make sure that state is set to Live since View is not changed via SetElement.
                SetCurrentViewAndUpdateUI(InspectView.Live);
                EnableElementSelector();
            }
        }
Example #5
0
        public void ShouldCallSetBackgroundColorOnlyOnceWithNestedCallsToOnAndOff()
        {
            // GIVEN
            var domContainer      = new Mock <DomContainer>().Object;
            var nativeElementMock = new Mock <INativeElement>();
            var element           = new Element(domContainer, nativeElementMock.Object);

            Settings.HighLightColor = "myTestColor";
            var highLight = new HighlightAction(element);

            nativeElementMock.Expect(nativeElement => nativeElement.GetStyleAttributeValue("backgroundColor")).Returns("initialColor").AtMostOnce();
            nativeElementMock.Expect(nativeElement => nativeElement.SetStyleAttributeValue("backgroundColor", "myTestColor")).AtMostOnce();
            nativeElementMock.Expect(nativeElement => nativeElement.SetStyleAttributeValue("backgroundColor", "initialColor")).AtMostOnce();

            // WHEN
            highLight.On();
            highLight.On();
            highLight.On();
            highLight.Off();
            highLight.Off();
            highLight.Off();

            // THEN
            nativeElementMock.VerifyAll();
        }
Example #6
0
        /// <summary>
        /// Event handler when node selection is changed in treeview.
        /// </summary>
        public void SelectedElementChanged()
        {
            if (this.ElementContext != null && GetDataAction.ExistElementContext(this.ElementContext.Id))
            {
                this.SelectedInHierarchyElement = this.ctrlHierarchy.SelectedInHierarchyElement != null ? new Tuple <Guid, int>(this.ElementContext.Id, this.ctrlHierarchy.SelectedInHierarchyElement.UniqueId) : null;

                // selection only when UI snapshot is done.
                if (this.SelectedInHierarchyElement != null && MainWin.CurrentPage == AppPage.Inspect && (InspectView)MainWin.CurrentView == InspectView.Live)
                {
                    var e = GetDataAction.GetA11yElementWithLiveData(this.SelectedInHierarchyElement.Item1, this.SelectedInHierarchyElement.Item2);
                    HighlightAction.GetDefaultInstance().SetElement(this.SelectedInHierarchyElement.Item1, this.SelectedInHierarchyElement.Item2);
                    UpdateElementInfoUI(e);
                }
            }
            else
            {
                ClearSelectedItem();
            }

            // NeedToEnableSelector is set True in SetElement
            // it is to make sure that ElementSelector is continued after populating UI
            if (EnableSelectorWhenPOISelectedInHierarchy)
            {
                // enable selector once UI update is finished.
                UpdateStateMachineForLiveMode();
                EnableSelectorWhenPOISelectedInHierarchy = false;
            }
        }
Example #7
0
        /// <summary>
        /// Displays loading indicator and updates UI
        /// </summary>
        /// <param name="forceRefresh"></param>
        public void UpdateUI()
        {
            this.lblCongrats.Visibility = Visibility.Collapsed;
            this.lblNoFail.Visibility   = Visibility.Collapsed;
            this.gdFailures.Visibility  = Visibility.Collapsed;
            this.AllExpanded            = false;
            fabicnExpandAll.GlyphName   = DesktopUI.Controls.FabricIcon.CaretSolidRight;
            this.SelectedItems.Clear();
            this.chbxSelectAll.IsChecked = false;
            HighlightAction.GetDefaultInstance().Clear();

            if (this.DataContext != null)
            {
                var list = this.DataContext.GetRuleResultsViewModelList();

                SetRuleResults(list);

                if (list != null)
                {
                    var ha = HighlightImageAction.GetDefaultInstance();
                    ha.SetImageElement(ElementContext.Id);
                    if (HighlightVisibility)
                    {
                        ha.Show();
                    }
                }

                Dispatcher.Invoke(() =>
                {
                    CheckAllBoxes(lvResults, true);
                }, DispatcherPriority.Input);
            }
        }
        /// <summary>
        /// Bring back to Inspect StartUp
        /// </summary>
        internal void HandleBackToLiveFromEventPage()
        {
            StartInspectMode(InspectView.Live);
            HighlightAction.GetInstance(AccessibilityInsights.Actions.Enums.HighlighterType.Selected).Clear();
            HighlightAction.GetDefaultInstance().IsEnabled = ConfigurationManager.GetDefaultInstance().AppConfig.IsHighlighterOn;

            UpdateMainWindowUI();
        }
Example #9
0
 /// <summary>
 /// Initialize the highlighter
 /// </summary>
 private void InitHighlighter()
 {
     // set the beaker callback.
     HighlightAction.GetDefaultInstance().SetCallBackForSnapshot(new Action(() =>
     {
         HandleSnapshotRequest(TestRequestSources.Beaker);
     }));
 }
Example #10
0
 /// <summary>
 /// Hide control and hilighter
 /// </summary>
 public void HideControl()
 {
     HighlightAction.GetDefaultInstance().HighlighterMode = prevMode;
     MainWin.SetHighlightBtnState(prevHighlighterState);
     HighlightAction.GetDefaultInstance().IsEnabled = prevHighlighterState;
     UpdateConfigWithSize();
     this.Visibility = Visibility.Collapsed;
 }
        /// <summary>
        /// Bring app back to selecting State
        /// </summary>
        public void HandleBackToSelectingState()
        {
            // if coming from startup, restore left nav bar
            if (this.CurrentPage == AppPage.Start)
            {
                this.bdLeftNav.IsEnabled = true;
                this.gdModes.Visibility  = Visibility.Visible;
                this.btnPause.Visibility = Visibility.Visible;
            }

            // clear selected element highliter
            HighlightAction.GetInstance(AccessibilityInsights.Actions.Enums.HighlighterType.Selected).Clear();
            HighlightImageAction.ClearDefaultInstance();

            // this can be disabled if previous action was loading old data format.
            // bring it back to enabled state.
            this.btnHilighter.IsEnabled = true;

            // since we comes back to live mode, enable highlighter by default.
            SelectAction.GetDefaultInstance().ClearSelectedContext();

            // turn highlighter on once you get back to selection mode.
            SetHighlightBtnState(true);
            var ha = HighlightAction.GetDefaultInstance();

            ha.HighlighterMode = ConfigurationManager.GetDefaultInstance().AppConfig.HighlighterMode;
            ha.IsEnabled       = true;
            ha.SetElement(null);

            /// make sure that all Mode UIs are clean since new selection will be done.
            CleanUpAllModeUIs();

            if (this.CurrentPage == AppPage.Start ||
                (this.CurrentPage == AppPage.CCA) ||
                (this.CurrentPage == AppPage.Test) ||
                (this.CurrentPage == AppPage.Inspect && this.CurrentView != InspectView.Live) ||
                (this.CurrentPage == AppPage.Events) ||
                (this.CurrentPage == AppPage.Inspect && SelectAction.GetDefaultInstance().IsPaused))
            {
                SelectAction.GetDefaultInstance().Scope = ConfigurationManager.GetDefaultInstance().AppConfig.IsUnderElementScope ? AccessibilityInsights.Actions.Enums.SelectionScope.Element : AccessibilityInsights.Actions.Enums.SelectionScope.App;
                cbSelectionScope.SelectedIndex = (SelectAction.GetDefaultInstance().Scope == AccessibilityInsights.Actions.Enums.SelectionScope.Element) ? 0 : 1;
                StartInspectMode(InspectView.Live); // clean up data when we get back to selection mode.
                this.CurrentPage = AppPage.Inspect;
                this.CurrentView = InspectView.Live;
            }

            // garbage collection for any UI elements
            GC.Collect();

            // enable element selector
            EnableElementSelector();

            // if it was open when the switch back button is clicked.
            HideConfigurationMode();

            UpdateMainWindowUI();
        }
Example #12
0
 /// <summary>
 /// Set test view with instructions to select an element first
 /// </summary>
 public void SetForNoSelection()
 {
     this.ctrlAutomatedChecks.ClearUI();
     this.EnableMenuButtons(false);
     this.tabControl.SelectedIndex       = 1;
     this.tbiTabStop.Visibility          = Visibility.Visible;
     this.tabControl.IsEnabled           = false;
     this.ctrlAutomatedChecks.Visibility = Visibility.Collapsed;
     this.tbSelectElement.Visibility     = Visibility.Visible;
     HighlightAction.GetDefaultInstance().Clear();
 }
 /// <summary>
 /// Mark selected element
 /// </summary>
 public void MarkElement(A11yElement ele)
 {
     lock (this)
     {
         if (HighlightAction.GetDefaultInstance().IsEnabled)
         {
             var ha = HighlightOverlayAction.GetDefaultInstance();
             HighlightOverlayAction.BringMainWindowOfPOIElementToFront();
             ha.MarkElement(ele);
         }
     }
 }
Example #14
0
        /// <summary>
        /// Start Start Mode
        /// </summary>
        /// <returns></returns>
        void StartStartMode()
        {
            this.CurrentPage = AppPage.Start;
            this.ctrlCurMode = ctrlStartUpMode;
            PageTracker.TrackPage(this.CurrentPage, null);

            /// Make sure that title and Name property are set with same value.
            UpdateTitleString();

            this.hWnd = new WindowInteropHelper(this).Handle;

            HighlightImageAction.SetHighlightBtnState = SetHighlightBtnState;
            HighlightAction.GetDefaultInstance().HighlighterMode = ConfigurationManager.GetDefaultInstance().AppConfig.HighlighterMode;

            InitHotKeys();
            InitSelectActionMode();
            InitTimerSelector();
            InitTimerAutoSnap();
            InitAccessKeyRule();
            InitHighlighter();

            /// Set UI appropriately if showing startup screen
            if (ConfigurationManager.GetDefaultInstance().AppConfig.NeedToShowWelcomeScreen())
            {
                this.bdLeftNav.IsEnabled = false;
                this.gdModes.Visibility  = Visibility.Collapsed;
                this.ctrlStartUpMode.ShowControl();
                //show telemetry dialog
                ShowTelemetryDialog();
                // make sure that we show update.
                CheckForUpdates();
            }
            else
            {
                HandleBackToSelectingState();
                // make sure that we disable selector before showing update
                // otherwise, UI could be in weird state (Main window is gray out but still show selection and update dialog is disappearing)
                DisableElementSelector();
                //show telemetry dialog
                ShowTelemetryDialog();
                CheckForUpdates();
                EnableElementSelector();
            }

            // chrome height is set to make sure system menu is shown over title bar area.
            var chrome = new WindowChrome();

            chrome.CaptionHeight = 35;
            WindowChrome.SetWindowChrome(this, chrome);

            UpdateTabSelection();
        }
 public void HandleToggleStatusChanged(bool isEnabled)
 {
     if (isEnabled)
     {
         this.CurrentView = CCAView.Automatic;
         EnableElementSelector();
     }
     else
     {
         this.CurrentView = CCAView.Manual;
         DisableElementSelector();
         HighlightAction.GetDefaultInstance().Clear();
         SelectAction.GetDefaultInstance().ClearSelectedContext();
     }
 }
Example #16
0
        public void ShouldSetBackgroundColor()
        {
            // GIVEN
            var domContainer      = new Mock <DomContainer>().Object;
            var nativeElementMock = new Mock <INativeElement>();
            var element           = new Element(domContainer, nativeElementMock.Object);

            Settings.HighLightColor = "myTestColor";
            var highLightAction = new HighlightAction(element);

            // WHEN
            highLightAction.On();

            // THEN
            nativeElementMock.Verify(nativeElement => nativeElement.SetStyleAttributeValue("backgroundColor", "myTestColor"));
        }
Example #17
0
        public void ShouldSetBackgroundColorToStringEmptyIfHighLightColorIsNull()
        {
            // GIVEN
            var domContainer      = new Mock <DomContainer>().Object;
            var nativeElementMock = new Mock <INativeElement>();

            nativeElementMock.Expect(x => x.IsElementReferenceStillValid()).Returns(true);
            var element         = new Element(domContainer, nativeElementMock.Object);
            var highLightAction = new HighlightAction(element);

            Settings.HighLightColor = null;

            // WHEN
            highLightAction.On();

            // THEN
            nativeElementMock.Verify(nativeElement => nativeElement.SetStyleAttributeValue("backgroundColor", ""));
        }
Example #18
0
        /// <summary>
        /// Show control and hilighter
        /// </summary>
        public void ShowControl()
        {
            this.Visibility           = Visibility.Visible;
            this.prevHighlighterState = HighlightAction.GetDefaultInstance().IsEnabled;
            this.prevMode             = HighlightAction.GetDefaultInstance().HighlighterMode;
            HighlightAction.GetDefaultInstance().HighlighterMode = HighlighterMode.Highlighter;
            MainWin.SetHighlightBtnState(true);
            HighlightAction.GetDefaultInstance().IsEnabled = true;
            HighlightAction.GetDefaultInstance().Clear();

            SelectAction.GetDefaultInstance().ClearSelectedContext();

            Dispatcher.InvokeAsync(() =>
            {
                this.SetFocusOnDefaultControl();
            }
                                   , System.Windows.Threading.DispatcherPriority.Input);

            ctrlContrast.SetAutoCCAState(true);
        }
Example #19
0
        public void ShouldIgnoreStackEmptyExceptionWhenColorStackIsEmpty()
        {
            // GIVEN
            var domContainer      = new Mock <DomContainer>().Object;
            var nativeElementMock = new Mock <INativeElement>();
            var element           = new Element(domContainer, nativeElementMock.Object);

            Settings.HighLightColor = "myTestColor";
            var highLight = new HighlightAction(element);

            nativeElementMock.Expect(nativeElement => nativeElement.GetStyleAttributeValue("backgroundColor")).Returns("initialColor");

            highLight.On();
            highLight.Off();

            // WHEN
            highLight.Off();

            // THEN no exception
        }
Example #20
0
        public void ShouldReturnToOriginalBackgroundColorWhenCallingHighLight()
        {
            // GIVEN
            var domContainer      = new Mock <DomContainer>().Object;
            var nativeElementMock = new Mock <INativeElement>();
            var element           = new Element(domContainer, nativeElementMock.Object);

            Settings.HighLightColor = "myTestColor";
            var highLight = new HighlightAction(element);

            nativeElementMock.Expect(nativeElement => nativeElement.GetStyleAttributeValue("backgroundColor")).Returns("initialColor");

            // WHEN
            highLight.Highlight(true);
            highLight.Highlight(false);

            // THEN
            nativeElementMock.Verify(nativeElement => nativeElement.SetStyleAttributeValue("backgroundColor", "myTestColor"));
            nativeElementMock.Verify(nativeElement => nativeElement.SetStyleAttributeValue("backgroundColor", "initialColor"));
        }
        /// <summary>
        /// Start snapshot mode.
        /// </summary>
        /// <param name="e">root element for listening events</param>
        private void StartEventsMode(A11yElement e)
        {
            if (e == null)
            {
                this.AllowFurtherAction = false;
                MessageDialog.Show(Properties.Resources.StartElementDetailViewNoElementIsSelectedMessage);
                this.AllowFurtherAction = true;
            }
            else if (e.IsSafeToRefresh() == false)
            {
                this.AllowFurtherAction = false;
                MessageDialog.Show(Properties.Resources.StartEventsModeElementNotAvailableMessage);
                this.AllowFurtherAction = true;
            }
            else
            {
                // we need to explicitly set the highlighter mode despite of the highlighter button status
                HighlightAction.GetDefaultInstance().HighlighterMode = HighlighterMode.Highlighter;

                this.ctrlEventMode.Clear();

                DisableElementSelector();

                this.ctrlCurMode.HideControl();
                this.ctrlCurMode = this.ctrlEventMode;
                this.ctrlEventMode.CurrentView = EventsView.Config;
                this.ctrlCurMode.ShowControl();

                var sa = SelectAction.GetDefaultInstance();

                // set the root element to listen to.
#pragma warning disable CS4014
                // NOTE: We aren't awaiting this async call, so if you
                // touch it, consider if you need to add the await
                this.ctrlEventMode.SetElement(sa.GetSelectedElementContextId().Value);
#pragma warning restore CS4014
                this.CurrentPage = AppPage.Events;
                this.CurrentView = EventsView.Config;
                PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString());
            }
        }
Example #22
0
        /// <summary>
        /// Event Handler to update event log list view
        /// </summary>
        /// <param name="message"></param>
        private void onRecordEvent(EventMessage message)
        {
            if (this.vmEventRecorder.State == ButtonState.On && this.isClosed == false)
            {
                Dispatcher.Invoke(delegate()
                {
                    lock (this.dgEvents)
                    {
                        this.dgEvents.Items.Add(message);
                        this.dgEvents.ScrollIntoView(message);
                        this.dgEvents.SelectedIndex = this.dgEvents.Items.Count - 1;

                        if (message.Element != null)
                        {
                            HighlightAction.GetDefaultInstance().SetElement(message.Element);
                        }

                        FireAsyncContentLoadedEventAtNewRecordAdded();
                    }
                });
            }
        }
Example #23
0
        /// <summary>
        /// Start CCA Automatic Monitor mode
        /// show only single selected item information
        /// </summary>
        private void StartCCAMode()
        {
            if (!(this.CurrentPage == AppPage.CCA && (CCAView)this.CurrentView == CCAView.Automatic))
            {
                this.CurrentPage = AppPage.CCA;
                this.CurrentView = CCAView.Automatic;
                PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString());

                // make sure that highlighter is cleared for new selection.
                HighlightAction.GetDefaultInstance().Clear();

                SetWindowForAutomaticMode();
            }

            SelectAction.GetDefaultInstance().Scope = SelectionScope.Element;

            // set the state to Capturing view. it will prevent testing for safety.
            this.CurrentView = CCAView.CapturingData;

            var ecId = SelectAction.GetDefaultInstance().GetSelectedElementContextId();

            if (ecId != null)
            {
                // make sure that no more selection is requested.
                DisableElementSelector();

                // Pass the currently selected Element Context
                this.ctrlCurMode.SetElement(ecId.Value);
            }
            else
            {
                this.CurrentView = CCAView.Automatic;
            }

            // enable element selector
            EnableElementSelector();
        }
Example #24
0
 /// <summary>
 /// Handle start/stop recording button click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void onbuttonEventRecorderClicked(object sender, RoutedEventArgs e)
 {
     ToggleRecording();
     HighlightAction.GetDefaultInstance().Clear();
 }
Example #25
0
        /// <summary>
        /// set element
        /// </summary>
        /// <param name="ecId"></param>
        public async Task SetElement(Guid ecId)
        {
            if (GetDataAction.ExistElementContext(ecId))
            {
                try
                {
                    HighlightAction.GetDefaultInstance().HighlighterMode = HighlighterMode.Highlighter;

                    HighlightAction.GetDefaultInstance().SetElement(ecId, 0);

                    this.ctrlContrast.ActivateProgressRing();

                    ElementContext ec          = null;
                    string         warning     = string.Empty;
                    string         toolTipText = string.Empty;

                    await Task.Run(() =>
                    {
                        var updated = CaptureAction.SetTestModeDataContext(ecId, this.DataContextMode, Configuration.TreeViewMode);
                        ec          = GetDataAction.GetElementContext(ecId);

                        // send telemetry of scan results.
                        var dc = GetDataAction.GetElementDataContext(ecId);
                        if (dc.ElementCounter.UpperBoundExceeded)
                        {
                            warning = string.Format(CultureInfo.InvariantCulture,
                                                    Properties.Resources.SetElementCultureInfoFormatMessage,
                                                    dc.ElementCounter.UpperBound);
                        }
                    }).ConfigureAwait(false);

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        if (ec == null || ec.Element == null)
                        {
                            toolTipText = "No Eelement Selected!";
                        }
                        else
                        {
                            if (CCAControlTypesFilter.GetDefaultInstance().Contains(ec.Element.ControlTypeId))
                            {
                                Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
                                {
                                    this.ctrlContrast.SetElement(ec);
                                })).Wait();
                                toolTipText = string.Format(CultureInfo.InvariantCulture, "Ratio: {0}\nConfidence: {1}",
                                                            this.ctrlContrast.getRatio(), this.ctrlContrast.getConfidence());
                            }
                            else
                            {
                                toolTipText = "Unknown Element Type!";
                            }
                        }

                        MainWin.CurrentView = CCAView.Automatic;

                        HighlightAction.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip;


                        HighlightAction.GetDefaultInstance().SetText(toolTipText);

                        // enable element selector
                        MainWin.EnableElementSelector();
                    });

                    this.ctrlContrast.DeactivateProgressRing();
                }
                catch (Exception ex)
                {
                    ex.ReportException();
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        MainWin.CurrentView = CCAView.Automatic;
                        HighlightAction.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip;


                        HighlightAction.GetDefaultInstance().SetText("Unable to detect colors!");
                        // enable element selector
                        MainWin.EnableElementSelector();

                        this.ctrlContrast.DeactivateProgressRing();
                    });
                }
            }
        }
Example #26
0
 /// <summary>
 /// Clear the selected item, without showing any warning
 /// </summary>
 private void ClearSelectedItem()
 {
     Clear();
     SelectAction.GetDefaultInstance().ClearSelectedContext();
     HighlightAction.GetDefaultInstance().Clear();
 }
#pragma warning restore CS1998

        /// <summary>
        /// Update UI with element data
        /// </summary>
        /// <param name="element"></param>
        private void UpdateUI(A11yElement element)
        {
            this.ctrlTabs.SetElement(element, false);
            HighlightAction.GetDefaultInstance().SetElement(element);
        }
        /// <summary>
        /// Update Element Info UI(Properties/Patterns/Tests)
        /// </summary>
        /// <param name="ecId"></param>
        public async Task SetElement(Guid ecId)
        {
            this.ctrlProgressRing.Activate();

            EnableMenuButtons(this.DataContextMode != DataContextMode.Load);

            bool selectionFailure = false;

            try
            {
                this.ctrlHierarchy.IsEnabled = false;
                ElementContext ec = null;
                await Task.Run(() =>
                {
                    CaptureAction.SetTestModeDataContext(ecId, this.DataContextMode, Configuration.TreeViewMode);
                    ec = GetDataAction.GetElementContext(ecId);

                    // send telemetry of scan results.
                    var dc = GetDataAction.GetElementDataContext(ecId);
                    dc.PublishScanResults();
                }).ConfigureAwait(false);

                Application.Current.Dispatcher.Invoke(() =>
                {
                    if (ec != null && ec.DataContext != null)
                    {
                        this.ElementContext = ec;
                        this.ctrlTabs.Clear();
                        if (!SelectAction.GetDefaultInstance().IsPaused)
                        {
                            this.ctrlHierarchy.CleanUpTreeView();
                        }
                        this.ctrlHierarchy.SetElement(ec);
                        this.ctrlTabs.SetElement(ec.Element, false, ec.Id);

                        if (ec.DataContext.Screenshot == null && ec.DataContext.Mode != DataContextMode.Load)
                        {
                            Application.Current.MainWindow.WindowStyle     = WindowStyle.ToolWindow;
                            Application.Current.MainWindow.Visibility      = Visibility.Hidden;
                            HighlightAction.GetDefaultInstance().IsEnabled = false;

                            this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
                            {
                                ScreenShotAction.CaptureScreenShot(ecId);
                                Application.Current.MainWindow.Visibility  = Visibility.Visible;
                                Application.Current.MainWindow.WindowStyle = WindowStyle.SingleBorderWindow;
                            })).Wait();
                        }
                        var ha = HighlightImageAction.GetDefaultInstance();

                        ha.SetImageElement(ecId);
                        //disable button on highlighter.
                        ha.SetHighlighterButtonClickHandler(null);

                        if (Configuration.IsHighlighterOn)
                        {
                            ha.Show();
                        }
                    }

                    // if it is enforced to select a specific element(like fastpass click case)
                    if (ec.DataContext.FocusedElementUniqueId.HasValue)
                    {
                        this.ctrlHierarchy.SelectElement(ec.DataContext.FocusedElementUniqueId.Value);
                    }

                    if (!ec.DataContext.Elements.TryGetValue(ec.DataContext.FocusedElementUniqueId ?? 0, out A11yElement selectedElement))
                    {
                        selectedElement = ec.DataContext.Elements[0];
                    }
                    AutomationProperties.SetName(this, string.Format(CultureInfo.InvariantCulture, Properties.Resources.SetElementInspectTestDetail, selectedElement.Glimpse));

                    FireAsyncContentLoadedEvent(AsyncContentLoadedState.Completed);

                    // Set focus on hierarchy tree
                    Dispatcher.InvokeAsync(() => this.ctrlHierarchy.SetFocusOnHierarchyTree(), DispatcherPriority.Input).Wait();

                    ec.DataContext.FocusedElementUniqueId = null;
                });
            }
            catch (Exception)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    Application.Current.MainWindow.Visibility = Visibility.Visible;
                    EnableMenuButtons(false);
                    this.ElementContext = null;
                    selectionFailure    = true;
                });
            }
            finally
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    this.ctrlProgressRing.Deactivate();
                    this.ctrlHierarchy.IsEnabled = true;

                    // if focus has gone to the window, we set focus to the hierarchy control. We do this because disabling the hierarchy control
                    // will throw keyboard focus to mainwindow, where it is not very useful.
                    if (Keyboard.FocusedElement is Window)
                    {
                        this.ctrlHierarchy.Focus();
                    }

                    if (selectionFailure)
                    {
                        MainWin.HandleFailedSelectionReset();
                    }
                    else
                    {
                        // Set the right view state :
                        if (MainWin.CurrentView is TestView iv && iv == TestView.ElementHowToFix)
                        {
                            MainWin.SetCurrentViewAndUpdateUI(TestView.ElementHowToFix);
                        }
Example #29
0
        /// <summary>
        /// Sets element context and updates UI
        /// </summary>
        /// <param name="ecId"></param>
        public async Task SetElement(Guid ecId)
        {
            EnableMenuButtons(false); // first disable them to avoid any conflict.

            bool selectionFailure = false;

            if (GetDataAction.ExistElementContext(ecId))
            {
                EnableMenuButtons(this.DataContextMode != DataContextMode.Load);
                this.ctrlAutomatedChecks.Visibility = Visibility.Visible;
                this.tbSelectElement.Visibility     = Visibility.Collapsed;
                this.tabControl.IsEnabled           = true;

                try
                {
                    AutomationProperties.SetName(this, "Test");

                    this.tabControl.IsEnabled = false;
                    this.ctrlProgressRing.Activate();

                    ElementContext ec      = null;
                    string         warning = string.Empty;

                    await Task.Run(() =>
                    {
                        var updated = CaptureAction.SetTestModeDataContext(ecId, this.DataContextMode, Configuration.TreeViewMode);
                        ec          = GetDataAction.GetElementContext(ecId);

                        // send telemetry of scan results.
                        var dc = GetDataAction.GetElementDataContext(ecId);
                        if (dc.ElementCounter.UpperBoundExceeded)
                        {
                            warning = string.Format(CultureInfo.InvariantCulture,
                                                    Properties.Resources.SetElementCultureInfoFormatMessage,
                                                    dc.ElementCounter.UpperBound);
                            IsSaveEnabled = false;
                        }
                        dc.PublishScanResults();
                    }).ConfigureAwait(false);

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        if (ec.Element == null || ec.Element.Properties == null || ec.Element.Properties.Count == 0)
                        {
                            this.ctrlAutomatedChecks.ClearUI();
                            selectionFailure = true;
                        }
                        else
                        {
                            if (ec.DataContext.Screenshot == null && ec.DataContext.Mode != DataContextMode.Load)
                            {
                                if (ec.Element.BoundingRectangle.IsEmpty == true)
                                {
                                    MessageDialog.Show(Properties.Resources.noScreenShotAvailableMessage);
                                }
                                else
                                {
                                    Application.Current.MainWindow.WindowStyle = WindowStyle.ToolWindow;
                                    Application.Current.MainWindow.Visibility  = Visibility.Hidden;

                                    HighlightAction.GetDefaultInstance().IsEnabled = false;

                                    this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
                                    {
                                        ScreenShotAction.CaptureScreenShot(ecId);
                                        Application.Current.MainWindow.WindowStyle = WindowStyle.SingleBorderWindow;
                                    })).Wait();
                                }
                            }
                            this.tabControl.IsEnabled = true;
                            this.ctrlAutomatedChecks.SetElement(ec);

                            this.ElementContext = ec;

                            if (ec.DataContext.Mode == DataContextMode.Test)
                            {
                                tbiTabStop.Visibility = Visibility.Visible;
                                this.ctrlTabStop.SetElement(ec);
                            }
                            else
                            {
                                tbiTabStop.Visibility = Visibility.Collapsed;
                            }

                            var count = ec.DataContext?.GetRuleResultsViewModelList()?.Count ?? 0;
                            AutomationProperties.SetName(this, Invariant($"{Properties.Resources.detectedFailuresMessagePart1} {this.ElementContext.Element.Glimpse}. {count} {Properties.Resources.detectedFailuresMessagePart2}"));

                            if (!string.IsNullOrEmpty(warning))
                            {
                                MessageDialog.Show(warning);
                            }
                            ///Set focus on automated checks tab.
                            FireAsyncContentLoadedEvent(AsyncContentLoadedState.Completed);
                        }
                    });
                }
                catch (Exception)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        Application.Current.MainWindow.Visibility = Visibility.Visible;
                        this.Clear();
                        selectionFailure = true;
                        EnableMenuButtons(false);
                        this.ElementContext = null;
                    });
                }
                finally
                {
                    Application.Current.Dispatcher.Invoke(() => {
                        this.ctrlProgressRing.Deactivate();
                    });
                }
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                // Set the right view state :
                if (selectionFailure)
                {
                    MainWin.HandleFailedSelectionReset();
                }
                else
                {
                    MainWin.SetCurrentViewAndUpdateUI(TestView.AutomatedTestResults);
                }

                // Improves the reliability of the rendering but does not solve across the board issues seen with all WPF apps.
                this.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
                {
                    Application.Current.MainWindow.InvalidateVisual();
                    Application.Current.MainWindow.Visibility = Visibility.Visible;
                    this.tbiAutomatedChecks.Focus();
                })).Wait();
            });
        }