/// <summary> /// Handle Recording Request by Hotkey (Shift + F7) /// </summary> void HandleRequestRecordingByHotkey() { if (this.CurrentPage == AppPage.Test && (TestView)this.CurrentView == TestView.TabStop) { ctrlTestMode.ctrlTabStop.ToggleRecording(); } else if (this.CurrentPage == AppPage.Events) { ctrlEventMode.ctrlEvents.ToggleRecording(); } else if (this.IsInSelectingState()) { var sa = SelectAction.GetDefaultInstance(); if (sa.HasPOIElement()) { var poi = GetDataAction.GetElementContext(sa.GetSelectedElementContextId().Value); this.StartEventsMode(poi.Element); UpdateMainWindowUI(); } else { MessageDialog.Show(Properties.Resources.HandleRequestRecordingByHotkeySelectElementMessage); } } }
/// <summary> /// Update Element Info UI(Properties/Patterns/Tests) /// </summary> /// <param name="ec"></param> #pragma warning disable CS1998 public async Task SetElement(Guid ecId) { var ec = GetDataAction.GetElementContext(ecId); if (ec != null) { this.ctrlTabs.CurrentMode = InspectTabMode.Events; try { // the element context is special one for Event. so it doen't have any data yet. // need to populate data with selected element. var e = GetDataAction.GetA11yElementWithLiveData(ecId, 0); this.ElementContext = ec; this.ctrlEvents.SetElement(ec); UpdateUI(e); this.ctrlTabs.CtrlEventConfig.SetElement(e); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); MessageDialog.Show(Properties.Resources.SetElementException); this.Clear(); } #pragma warning restore CA1031 // Do not catch general exception types } }
/// <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 IHttpActionResult ElementContext(Guid id) { try { // check whether Id exists first. if (GetDataAction.ExistElementContext(id)) { return(Ok(GetDataAction.GetElementContext(id))); } else { return(NotFound()); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
/// <summary> /// Update Element Info UI(Properties/Patterns/Tests) /// </summary> /// <param name="ec"></param> #pragma warning disable CS1998 public async Task SetElement(Guid ecId) { var ec = GetDataAction.GetElementContext(ecId); if (ec != null) { this.ctrlTabs.CurrentMode = InspectTabMode.Events; try { // the element context is special one for Event. so it doen't have any data yet. // need to populate data with selected element. var e = GetDataAction.GetA11yElementWithLiveData(ecId, 0); this.ElementContext = ec; this.ctrlEvents.SetElement(ec); UpdateUI(e); this.ctrlTabs.CtrlEventConfig.SetElement(e); } catch { MessageDialog.Show(Properties.Resources.SetElementException); this.Clear(); } } }
/// <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> /// 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(); }); } } }
/// <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); }
/// <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> /// Update selected element /// </summary> /// <param name="ecId">Element Context Id</param> public async Task SetElement(Guid ecId) { this.ElementContext = null; this.SelectedInHierarchyElement = null; EnableSelectorWhenPOISelectedInHierarchy = false; var ec = GetDataAction.GetElementContext(ecId); if (ec != null) { var prevFocus = Keyboard.FocusedElement; try { this.ctrlProgressRing.Activate(); this.ctrlHierarchy.IsEnabled = false; ctrlHierarchy.Visibility = Visibility.Visible; svInstructions.Visibility = Visibility.Collapsed; await Task.Run(() => { CaptureAction.SetLiveModeDataContext(ecId, Configuration.TreeViewMode); }).ConfigureAwait(false); Application.Current.Dispatcher.Invoke(() => { this.ctrlHierarchy.DataContext = ec.DataContext; this.ElementContext = ec; // make sure that when selected node is changed in hiearchy tree, enable selector. EnableSelectorWhenPOISelectedInHierarchy = true; this.ctrlHierarchy.SetElement(ec); AutomationProperties.SetName(this, string.Format(CultureInfo.InvariantCulture, "Live inspect with {0}", ec.Element.Glimpse)); }); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); // if there was any exception, make sure that we enable selector later. EnableSelectorWhenPOISelectedInHierarchy = false; } #pragma warning restore CA1031 // Do not catch general exception types finally { this.ctrlProgressRing.Deactivate(); Application.Current.Dispatcher.Invoke(() => { this.ctrlHierarchy.IsEnabled = true; // if the previously focused element is no longer visible and focus has gone to the window, // we will set focus back 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 (prevFocus is FrameworkElement fe && !fe.IsVisible && Keyboard.FocusedElement is Window) { this.ctrlHierarchy.Focus(); } }); } } else { Clear(); } if (EnableSelectorWhenPOISelectedInHierarchy == false) { Application.Current.Dispatcher.Invoke(() => UpdateStateMachineForLiveMode()); } }
/// <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 } }