/// <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); HollowHighlightDriver.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; } }
/// <summary> /// Displays loading indicator and updates UI /// </summary> public void UpdateUI() { this.lblCongrats.Visibility = Visibility.Collapsed; this.lblNoFail.Visibility = Visibility.Collapsed; this.gdFailures.Visibility = Visibility.Collapsed; this.nonFrameworkListControl.Reset(); this.frameworkListControl.Reset(); HollowHighlightDriver.GetDefaultInstance().Clear(); if (this.DataContext != null) { var list = this.DataContext.GetRuleResultsViewModelList(); SetRuleResults(list); if (list != null) { var ha = ImageOverlayDriver.GetDefaultInstance(); ha.SetImageElement(ElementContext.Id); if (HighlightVisibility) { ha.Show(); } } Dispatcher.Invoke(() => { nonFrameworkListControl.CheckAllBoxes(); frameworkListControl.CheckAllBoxes(); }, DispatcherPriority.Input); } }
/// <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. HollowHighlightDriver.GetDefaultInstance().Clear(); SetWindowForLiveMode(); } // set the state to Capturing view. it will prevent testing for safety. this.CurrentView = InspectView.CapturingData; var ecId = SelectAction.GetDefaultInstance().SelectedElementContextId; 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(); } }
/// <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 = CommonUxComponents.Controls.FabricIcon.CaretSolidRight; this.SelectedItems.Clear(); this.chbxSelectAll.IsChecked = false; HollowHighlightDriver.GetDefaultInstance().Clear(); if (this.DataContext != null) { var list = this.DataContext.GetRuleResultsViewModelList(); SetRuleResults(list); if (list != null) { var ha = ImageOverlayDriver.GetDefaultInstance(); ha.SetImageElement(ElementContext.Id); if (HighlightVisibility) { ha.Show(); } } Dispatcher.Invoke(() => { CheckAllBoxes(lvResults, true); }, DispatcherPriority.Input); } }
/// <summary> /// Handle toggle highlighter request /// </summary> /// <returns></returns> public bool ToggleHighlighter() { var enabled = !HollowHighlightDriver.GetDefaultInstance().IsEnabled; HollowHighlightDriver.GetDefaultInstance().IsEnabled = enabled; return(enabled); }
/// <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(TelemetryEventFactory.ForTestRequested( method.ToString(), SelectAction.GetDefaultInstance().Scope.ToString())); } HollowHighlightDriver.GetDefaultInstance().Clear(); UpdateMainWindowUI(); }
/// <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 HollowHighlightDriver.GetInstance(HighlighterType.Selected).Clear(); ImageOverlayDriver.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 highlightDriver = HollowHighlightDriver.GetDefaultInstance(); highlightDriver.HighlighterMode = ConfigurationManager.GetDefaultInstance().AppConfig.HighlighterMode; highlightDriver.IsEnabled = true; highlightDriver.SetElement(null); /// make sure that all Mode UIs are clean since new selection will be done. CleanUpAllModeUIs(); #pragma warning disable CA1508 // Dead code warning doesn't apply here 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 ? Axe.Windows.Actions.Enums.SelectionScope.Element : Axe.Windows.Actions.Enums.SelectionScope.App; cbSelectionScope.SelectedIndex = (SelectAction.GetDefaultInstance().Scope == Axe.Windows.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; } #pragma warning restore CA1508 // Dead code warning doesn't apply here // 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(); }
/// <summary> /// Bring back to Inspect StartUp /// </summary> internal void HandleBackToLiveFromEventPage() { StartInspectMode(InspectView.Live); HollowHighlightDriver.GetInstance(HighlighterType.Selected).Clear(); HollowHighlightDriver.GetDefaultInstance().IsEnabled = ConfigurationManager.GetDefaultInstance().AppConfig.IsHighlighterOn; UpdateMainWindowUI(); }
/// <summary> /// Initialize the highlighter /// </summary> private void InitHighlighter() { // set the beaker callback. HollowHighlightDriver.GetDefaultInstance().SetCallBackForSnapshot(new Action(() => { HandleSnapshotRequest(TestRequestSources.Beaker); })); }
/// <summary> /// Hide control and hilighter /// </summary> public void HideControl() { HollowHighlightDriver.GetDefaultInstance().HighlighterMode = prevMode; MainWin.SetHighlightBtnState(prevHighlighterState); HollowHighlightDriver.GetDefaultInstance().IsEnabled = prevHighlighterState; UpdateConfigWithSize(); this.Visibility = Visibility.Collapsed; }
/// <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; HollowHighlightDriver.GetDefaultInstance().Clear(); }
/// <summary> /// Mark selected element /// </summary> public void MarkElement(A11yElement ele) { lock (_lockObject) { if (HollowHighlightDriver.GetDefaultInstance().IsEnabled) { var overlayDriver = ClearOverlayDriver.GetDefaultInstance(); ClearOverlayDriver.BringMainWindowOfPOIElementToFront(); overlayDriver.MarkElement(ele); } } }
/// <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; ImageOverlayDriver.SetHighlightBtnState = SetHighlightBtnState; HollowHighlightDriver.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(); }
/// <summary> /// Load event records /// </summary> /// <param name="el"></param> internal void LoadEventRecords(List <EventMessage> el) { this.ctrlTabs.CurrentMode = InspectTabMode.LoadedEvents; this.ctrlEvents.LoadEventRecords(el); HollowHighlightDriver highlightDriver = HollowHighlightDriver.GetDefaultInstance(); if (highlightDriver.IsEnabled) { highlightDriver.IsEnabled = false; highlightDriver.HighlighterMode = HighlighterMode.Highlighter; MainWin.SetHighlightBtnState(false); } }
public void HandleToggleStatusChanged(bool isEnabled) { if (isEnabled) { this.CurrentView = CCAView.Automatic; EnableElementSelector(); } else { this.CurrentView = CCAView.Manual; DisableElementSelector(); HollowHighlightDriver.GetDefaultInstance().Clear(); SelectAction.GetDefaultInstance().ClearSelectedContext(); } }
/// <summary> /// Handle configuration changed /// - apply changes as needed /// - Send telemetry /// </summary> /// <param name="testconfig"></param> internal void HandleConfigurationChanged(IReadOnlyDictionary <string, object> changes) { HotkeyHandler?.ClearHotkeys(); InitHotKeys(); var configManager = ConfigurationManager.GetDefaultInstance(); SelectAction.GetDefaultInstance().IntervalMouseSelector = configManager.AppConfig.MouseSelectionDelayMilliSeconds; this.Topmost = configManager.AppConfig.AlwaysOnTop; this.ctrlTestMode.ctrlTabStop.SetHotkeyText(configManager.AppConfig.HotKeyForRecord); HollowHighlightDriver.GetDefaultInstance().HighlighterMode = configManager.AppConfig.HighlighterMode; if (changes != null && changes.ContainsKey(ConfigurationModel.keyFontSize)) { SetFontSize(); } }
private void Initialize() { this.ctrlCurMode = ctrlLiveMode; this.ctrlCurMode.ShowControl(); UpdateTitleString(); this.hWnd = new WindowInteropHelper(this).Handle; ImageOverlayDriver.SetHighlightBtnState = SetHighlightBtnState; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = ConfigurationManager.GetDefaultInstance().AppConfig.HighlighterMode; InitHotKeys(); InitSelectActionMode(); InitTimerSelector(); InitTimerAutoSnap(); InitAccessKeyRule(); InitHighlighter(); if (ConfigurationManager.GetDefaultInstance().AppConfig.NeedToShowWelcomeScreen() && CommandLineSettings.FileToOpen == null) { InitStartMode(); } 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(); 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(); }
/// <summary> /// Show control and hilighter /// </summary> public void ShowControl() { this.Visibility = Visibility.Visible; this.prevHighlighterState = HollowHighlightDriver.GetDefaultInstance().IsEnabled; this.prevMode = HollowHighlightDriver.GetDefaultInstance().HighlighterMode; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.Highlighter; MainWin.SetHighlightBtnState(true); HollowHighlightDriver.GetDefaultInstance().IsEnabled = true; HollowHighlightDriver.GetDefaultInstance().Clear(); SelectAction.GetDefaultInstance().ClearSelectedContext(); Dispatcher.InvokeAsync(() => { this.SetFocusOnDefaultControl(); } , System.Windows.Threading.DispatcherPriority.Input); ctrlContrast.SetAutoCCAState(true); }
/// <summary> /// Set color theme /// </summary> public void SetColorTheme(Theme theme) { Resources.MergedDictionaries.Remove(this.themeResourceDictionaty); this.themeResourceDictionaty = new ResourceDictionary() { Source = Brushes[theme] }; Resources.MergedDictionaries.Add(this.themeResourceDictionaty); HollowHighlightDriver.ClearAllHighlighters(); // give the window a border if in high contrast mode if (theme == Theme.HighContrast) { App.Current.MainWindow.BorderThickness = new Thickness(4); } else { App.Current.MainWindow.BorderThickness = new Thickness(0); } }
/// <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 HollowHighlightDriver.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.SelectedElementContextId.Value); #pragma warning restore CS4014 this.CurrentPage = AppPage.Events; this.CurrentView = EventsView.Config; PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString()); } }
/// <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) { HollowHighlightDriver.GetDefaultInstance().SetElement(message.Element); } FireAsyncContentLoadedEventAtNewRecordAdded(); } }); } }
/// <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. HollowHighlightDriver.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(); }
/// <summary> /// set element /// </summary> /// <param name="ecId"></param> public async Task SetElement(Guid ecId) { if (GetDataAction.ExistElementContext(ecId)) { try { HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.Highlighter; HollowHighlightDriver.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; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip; HollowHighlightDriver.GetDefaultInstance().SetText(toolTipText); // enable element selector MainWin.EnableElementSelector(); }); this.ctrlContrast.DeactivateProgressRing(); } catch (Exception ex) { ex.ReportException(); Application.Current.Dispatcher.Invoke(() => { MainWin.CurrentView = CCAView.Automatic; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip; HollowHighlightDriver.GetDefaultInstance().SetText("Unable to detect colors!"); // enable element selector MainWin.EnableElementSelector(); this.ctrlContrast.DeactivateProgressRing(); }); } } }
#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); HollowHighlightDriver.GetDefaultInstance().SetElement(element); }
/// <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; HollowHighlightDriver.GetDefaultInstance().IsEnabled = false; this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { ScreenShotAction.CaptureScreenShot(ecId); Application.Current.MainWindow.WindowStyle = WindowStyle.SingleBorderWindow; // This needs to happen before the call to ctrlAutomatedChecks.SetElement. Otherwise, // ctrlAutomatedChecks's checkboxes become out of sync with the highlighter Application.Current.MainWindow.Visibility = Visibility.Visible; })).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(); }); }
/// <summary> /// Handle start/stop recording button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void onbuttonEventRecorderClicked(object sender, RoutedEventArgs e) { ToggleRecording(); HollowHighlightDriver.GetDefaultInstance().Clear(); }
/// <summary> /// set element /// </summary> /// <param name="ecId"></param> public async Task SetElement(Guid ecId) { if (GetDataAction.ExistElementContext(ecId)) { try { HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.Highlighter; HollowHighlightDriver.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 = Properties.Resources.ColorContrast_NoElementSelected; } else { if (ControlType.GetInstance().Values.Contains(ec.Element.ControlTypeId)) { Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { this.ctrlContrast.SetElement(ec); })).Wait(); toolTipText = string.Format(CultureInfo.InvariantCulture, Properties.Resources.ColorContrast_RatioAndConfidenceFormat, this.ctrlContrast.Ratio, this.ctrlContrast.Confidence); } else { toolTipText = Properties.Resources.ColorContrast_UnknownElementType; } } MainWin.CurrentView = CCAView.Automatic; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip; HollowHighlightDriver.GetDefaultInstance().SetText(toolTipText); // enable element selector MainWin.EnableElementSelector(); }); this.ctrlContrast.DeactivateProgressRing(); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); Application.Current.Dispatcher.Invoke(() => { MainWin.CurrentView = CCAView.Automatic; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip; HollowHighlightDriver.GetDefaultInstance().SetText(Properties.Resources.ColorContrast_UnableToDetectColors); // enable element selector MainWin.EnableElementSelector(); this.ctrlContrast.ClearUI(); this.ctrlContrast.DeactivateProgressRing(); }); } #pragma warning restore CA1031 // Do not catch general exception types } }
/// <summary> /// Clear the selected item, without showing any warning /// </summary> private void ClearSelectedItem() { Clear(); SelectAction.GetDefaultInstance().ClearSelectedContext(); HollowHighlightDriver.GetDefaultInstance().Clear(); }
/// <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; HollowHighlightDriver.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 imageOverlay = ImageOverlayDriver.GetDefaultInstance(); imageOverlay.SetImageElement(ecId); //disable button on highlighter. imageOverlay.SetHighlighterButtonClickHandler(null); if (Configuration.IsHighlighterOn) { imageOverlay.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; }); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); Application.Current.Dispatcher.Invoke(() => { Application.Current.MainWindow.Visibility = Visibility.Visible; EnableMenuButtons(false); this.ElementContext = null; selectionFailure = true; }); } #pragma warning restore CA1031 // Do not catch general exception types 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); }