/// <summary> /// Refresh /// </summary> public void Refresh() { // data will be asked to be captured again. so set the CurrentView right. MainWin.SetCurrentViewAndUpdateUI(TestView.CapturingData); ImageOverlayDriver.ClearDefaultInstance(); var ecId = SelectAction.GetDefaultInstance().SelectedElementContextId.Value; SetDataAction.ReleaseDataContext(ecId); #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.SetElement(ecId); #pragma warning restore CS4014 }
/// <summary> /// Shows a dialog with an error message and then goes back to selecting state /// </summary> internal void HandlePauseButtonToggle(bool enabled) { if (enabled) { this.vmLiveModePauseResume.State = ButtonState.On; SelectAction.GetDefaultInstance().ResumeUIATreeTracker(); AutomationProperties.SetName(btnPause, Properties.Resources.btnPauseAutomationPropertiesNameOn); } else { this.vmLiveModePauseResume.State = ButtonState.Off; SelectAction.GetDefaultInstance().PauseUIATreeTracker(); AutomationProperties.SetName(btnPause, Properties.Resources.btnPauseAutomationPropertiesNameOff); } UpdateMainWindowUI(); }
/// <summary> /// Selector timer event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OntimerSelectorElapsedEvent(object sender, ElapsedEventArgs e) { if (this.timerSelector != null) { if (AllowFurtherAction) { Dispatcher.Invoke(delegate() { lock (this) { if (this.CurrentPage != AppPage.Exit && AllowFurtherAction) { var sa = SelectAction.GetDefaultInstance(); var cecId = sa.GetSelectedElementContextId(); var cec = cecId.HasValue ? GetDataAction.GetElementContext(cecId.Value) : null; if (sa.Select()) { var ec = GetDataAction.GetElementContext(sa.GetSelectedElementContextId().Value); if ((cec == null || cec.Element.IsSameUIElement(ec.Element) == false) && ec.Element.IsRootElement() == false) { HandleTargetSelectionChanged(); } if (!sa.IsPaused) { cec?.Dispose(); cec = null; } } } } }); } lock (this) { EnableTimerSafely(timerSelector, true); // make sure that it is disabled. } } else { lock (this) { EnableTimerSafely(timerSelector, false); // make sure that it is disabled. } } }
/// <summary> /// Sets element context and updates UI /// </summary> /// <param name="ec"></param> public void SetElement() { var ecId = SelectAction.GetDefaultInstance().SelectedElementContextId; if (ecId.HasValue) { ElementContext ec = GetDataAction.GetElementContext(ecId.Value); this.ElementContext = ec; var brush = Application.Current.Resources["HLTextBrush"] as SolidColorBrush; var overlayDriver = ClearOverlayDriver.GetDefaultInstance(); overlayDriver.SetElement(ElementContext.Element, brush, null, 0); if (this.IsVisible && HighlightVisibility) { overlayDriver.Show(); } } }
public ResultsT Scan <ResultsT>(A11yElement element, ScanActionCallback <ResultsT> scanCallback) { if (element == null) { throw new ArgumentNullException(nameof(element)); } if (scanCallback == null) { throw new ArgumentNullException(nameof(scanCallback)); } using (var dataManager = DataManager.GetDefaultInstance()) using (var sa = SelectAction.GetDefaultInstance()) { sa.SetCandidateElement(element); if (!sa.Select()) { throw new AxeWindowsAutomationException(DisplayStrings.ErrorUnableToSetDataContext); } using (ElementContext ec2 = sa.POIElementContext) { Stopwatch stopwatch = Stopwatch.StartNew(); GetDataAction.GetProcessAndUIFrameworkOfElementContext(ec2.Id); if (!CaptureAction.SetTestModeDataContext(ec2.Id, DataContextMode.Test, TreeViewMode.Control)) { throw new AxeWindowsAutomationException(DisplayStrings.ErrorUnableToSetDataContext); } long scanDurationInMilliseconds = stopwatch.ElapsedMilliseconds; // send telemetry of scan results. var dc = GetDataAction.GetElementDataContext(ec2.Id); dc.PublishScanResults(scanDurationInMilliseconds); if (dc.ElementCounter.UpperBoundExceeded) { throw new AxeWindowsAutomationException(string.Format(CultureInfo.InvariantCulture, DisplayStrings.ErrorTooManyElementsToSetDataContext, dc.ElementCounter.UpperBound)); } return(scanCallback(ec2.Element, ec2.Id)); } // using }// using }
/// <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(); } }
/// <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> /// Handle Context Menu : Expand all /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuItem_Click(object sender, RoutedEventArgs e) { var node = (HierarchyNodeViewModel)((System.Windows.FrameworkElement)sender).DataContext; if (node.NeedSnapshot && node.Element is DesktopElement && node.Element.IsRootElement() == false) { Dispatcher.Invoke(() => { var sa = SelectAction.GetDefaultInstance(); sa.SetCandidateElement(this.ElementContext.Id, node.Element.UniqueId); sa.Select(); this.HierarchyActions.RefreshHierarchy(true); }); } else { Logger.PublishTelemetryEvent(TelemetryAction.Hilighter_Expand_AllDescendants); node.Expand(true); } }
/// <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()); } }
/// <summary> /// Event handler for Move to Parent button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMoveToParent_Click(object sender, RoutedEventArgs e) { if (this.SelectedElement.Parent != null) { if (this.SelectedElement.Parent.IsRootElement() == false) { var sa = SelectAction.GetDefaultInstance(); sa.SetCandidateElement(this.ElementContext.Id, this.SelectedElement.Parent.UniqueId); sa.Select(); this.HierarchyActions.RefreshHierarchy(true); } else { MessageDialog.Show(Properties.Resources.HierarchyControl_btnMoveToParent_Click_The_parent_is_Desktop_Element__Desktop_Element_can_t_be_snapshot); } } else { MessageDialog.Show(Properties.Resources.HierarchyControl_btnMoveToParent_Click_Parent_element_can_t_be_retrieved); } }
public IHttpActionResult Current() { try { var sa = SelectAction.GetDefaultInstance(); var gid = sa.GetSelectedElementContextId(); if (gid.HasValue) { return(Ok(gid)); } else { return(NotFound()); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
/// <summary> /// Merge a results file into the local issue store. This clears all internal data contexts /// </summary> /// <param name="path">Path to the file to merge</param> /// <returns>The number of changes (additions or merges) to the store</returns> public static int MergeOutputFileToIssueStore(string path) { int changeCount = 0; try { Tuple <Guid, SnapshotMetaInfo> loadInfo = SelectAction.GetDefaultInstance().SelectLoadedData(path); ElementContext elementContext = DataManager.GetDefaultInstance().GetElementContext(loadInfo.Item1); IIssueStore storeToMerge = new OutputFileIssueStore(path, elementContext.DataContext.Elements.Values); changeCount = SessionIssueStore.GetInstance().MergeIssuesFromStore(storeToMerge); } catch (Exception) { } finally { SelectAction.GetDefaultInstance().ClearSelectedContext(); } return(changeCount); }
/// <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 = ""; }
/// <summary> /// Start snapshot mode with loading data /// </summary> private void StartLoadingSnapshot(string path, int?selectedElementId = null) { DisableElementSelector(); var v = SelectAction.GetDefaultInstance().SelectLoadedData(path, selectedElementId); if (selectedElementId.HasValue) { Logger.PublishTelemetryEvent(TelemetryAction.Hierarchy_Load_Protocol, TelemetryProperty.ProtocolMode, v.Item2.Mode.ToString()); } Logger.PublishTelemetryEvent(TelemetryAction.Hierarchy_Load_NewFormat, TelemetryProperty.FileMode, v.Item2.Mode.ToString()); if (v.Item2.Mode == A11yFileMode.Test && !selectedElementId.HasValue) { StartTestAutomatedChecksView(); } else if (v.Item2.Mode == A11yFileMode.Contrast) { StartTestAutomatedChecksView(); // we got rid of the CC test tab. } else // A11yFileMode.Inspect { this.ctrlCurMode.HideControl(); this.ctrlCurMode = this.ctrlSnapMode; this.ctrlSnapMode.DataContextMode = GetDataContextModeForTest(); this.CurrentPage = AppPage.Test; this.CurrentView = TestView.ElementDetails; this.ctrlCurMode.ShowControl(); #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.ctrlSnapMode.SetElement(v.Item1); #pragma warning restore CS4014 } PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString()); }
/// <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 Hot Key for event recording /// honor the value from Configuration file. /// </summary> private void SetHotKeyForToggleRecord() { SetHotKey(ConfigurationManager.GetDefaultInstance().AppConfig.HotKeyForRecord, new Action(() => { lock (_lockObject) { Dispatcher.Invoke(() => { lock (_lockObject) { if (this.CurrentPage == AppPage.Test && (TestView)this.CurrentView == TestView.TabStop) { ctrlTestMode.ctrlTabStop.ToggleRecording(); } else if (this.CurrentPage == AppPage.Events && this.CurrentView != EventsView.Load) { ctrlEventMode.ctrlEvents.ToggleRecording(); } else { var sa = SelectAction.GetDefaultInstance(); // make sure that POI is set. if (this.IsInSelectingState() && sa.HasPOIElement()) { this.StartEventsMode(GetDataAction.GetElementContext(sa.GetSelectedElementContextId().Value).Element); UpdateMainWindowUI(); } } } }); } }), ErrorMessage(ConfigurationManager.GetDefaultInstance().AppConfig.HotKeyForSnap)); }
/// <summary> /// Bring the main window of POI element to front /// </summary> public static void BringMainWindowOfPOIElementToFront() { try { var procId = SelectAction.GetDefaultInstance().POIElementContext.Element.ProcessId; Process proc = Process.GetProcessById(procId); proc.Refresh(); IntPtr handle = proc.MainWindowHandle; NativeMethods.FocusWindow(handle); ((IUIAutomationElement)SelectAction.GetDefaultInstance().POIElementContext.Element.PlatformObject).SetFocus(); } catch (ArgumentException) { } catch (COMException) { } catch (NullReferenceException) { } catch (InvalidOperationException) { } }
/// <summary> /// Set the text and visibility of breadcrumb buttons based on current view /// </summary> private void UpdateBreadcrumbs() { var sa = SelectAction.GetDefaultInstance(); var rd = new ResourceDictionary(); rd.Source = new Uri(@"pack://application:,,,/AccessibilityInsights.SharedUx;component/Resources/Styles.xaml", UriKind.Absolute); CollapseAllCrumbs(); switch (this.CurrentPage) { case AppPage.Events: SetVisibleText(btnCrumbOne, Properties.Resources.liveInspect); SetVisibleText(ctrlFabCrumbOne); if (sa.IsPaused) { SetVisibleText(btnCrumbTwo, Properties.Resources.paused); SetVisibleText(ctrlFabCrumbTwo); SetVisibleText(tbCrumbThree, Properties.Resources.events); } else { SetVisibleText(tbCrumbTwo, Properties.Resources.events); } break; case AppPage.Inspect: if (sa.IsPaused) { SetVisibleText(btnCrumbOne, Properties.Resources.liveInspect); SetVisibleText(ctrlFabCrumbOne); SetVisibleText(tbCrumbTwo, Properties.Resources.paused); } else { SetVisibleText(tbCrumbOne, Properties.Resources.liveInspect); } break; case AppPage.Test: switch ((TestView)this.CurrentView) { case TestView.NoSelection: case TestView.CapturingData: case TestView.AutomatedTestResults: case TestView.TabStop: SetVisibleText(btnCrumbOne, Properties.Resources.liveInspect); SetVisibleText(ctrlFabCrumbOne); if (sa.IsPaused) { SetVisibleText(btnCrumbTwo, Properties.Resources.paused); SetVisibleText(ctrlFabCrumbTwo); SetVisibleText(tbCrumbThree, Properties.Resources.tests); } else { SetVisibleText(tbCrumbTwo, Properties.Resources.tests); } break; case TestView.ElementDetails: case TestView.ElementHowToFix: SetVisibleText(btnCrumbOne, Properties.Resources.liveInspect); SetVisibleText(ctrlFabCrumbOne); SetVisibleText(btnCrumbTwo, Properties.Resources.tests); SetVisibleText(ctrlFabCrumbTwo); SetVisibleText(tbCrumbThree, Properties.Resources.resultsInUIATree); break; default: break; } break; case AppPage.CCA: SetVisibleText(btnCrumbOne, Properties.Resources.liveInspect); SetVisibleText(ctrlFabCrumbOne); SetVisibleText(tbCrumbTwo, Properties.Resources.colorContrast); break; default: break; } }
/// <summary> /// Clear the selected item, without showing any warning /// </summary> private void ClearSelectedItem() { Clear(); SelectAction.GetDefaultInstance().ClearSelectedContext(); HollowHighlightDriver.GetDefaultInstance().Clear(); }
/// <summary> /// Draw rectangle around the selected element in the application /// </summary> public void MarkSelectedElement() { A11yElement ele = SelectAction.GetDefaultInstance().POIElementContext.Element; this.Highlighter.MarkSelectedElement(ele); }
/// <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); }