/// <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> /// 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> /// 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> /// Start snapshot mode. /// </summary> private void StartElementDetailView() { var ecId = SelectAction.GetDefaultInstance().GetSelectedElementContextId(); if (ecId != null) { this.CurrentPage = AppPage.Test; this.CurrentView = TestView.CapturingData; DisableElementSelector(); var tp = GetDataAction.GetProcessAndUIFrameworkOfElementContext(ecId.Value); PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString(), tp.Item2); this.ctrlCurMode.HideControl(); this.ctrlCurMode = this.ctrlSnapMode; this.ctrlSnapMode.DataContextMode = GetDataContextModeForTest(); 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 ctrlSnapMode.SetElement(ecId.Value); #pragma warning restore CS4014 } else { this.AllowFurtherAction = false; MessageDialog.Show(Properties.Resources.StartElementDetailViewNoElementIsSelectedMessage); this.AllowFurtherAction = true; } }
/// <summary> /// Start fastpass mode. /// </summary> private void StartTestAutomatedChecksView() { var ec = SelectAction.GetDefaultInstance().GetSelectedElementContextId(); if (ec != null) { DisableElementSelector(); ctrlCurMode.HideControl(); // make sure that we honor loaded data. but in this case, some of manual test should be disabled. ctrlTestMode.DataContextMode = GetDataContextModeForTest(); ctrlCurMode = ctrlTestMode; ctrlCurMode.ShowControl(); // set mode to data capturing this.CurrentPage = AppPage.Test; this.CurrentView = TestView.CapturingData; #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.ctrlTestMode.SetElement(ec.Value); #pragma warning restore CS4014 var tp = GetDataAction.GetProcessAndUIFrameworkOfElementContext(ec.Value); PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString(), tp.Item2); } else { this.AllowFurtherAction = false; MessageDialog.Show(Properties.Resources.StartElementDetailViewNoElementIsSelectedMessage); this.AllowFurtherAction = true; } }
IHttpActionResult CaptureData(Guid id, DataContextMode dm, TreeViewMode tvm, bool force) { try { if (CaptureAction.SetTestModeDataContext(id, dm, tvm, force)) { if (dm == DataContextMode.Test) { var dc = GetDataAction.GetElementDataContext(id); dc.PublishScanResults(); } return(Ok()); } else { return(StatusCode(HttpStatusCode.NotModified)); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
/// <summary> /// Switches to snapshot mode and selects appropriate element /// </summary> /// <param name="followUp">An action to perform after tests have been run</param> private void StartElementHowToFixView(Action followUp = null) { var ecId = SelectAction.GetDefaultInstance().GetSelectedElementContextId(); this.CurrentPage = AppPage.Test; this.CurrentView = TestView.ElementHowToFix; var tp = GetDataAction.GetProcessAndUIFrameworkOfElementContext(ecId.Value); PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString(), tp.Item2); this.ctrlCurMode.HideControl(); this.ctrlCurMode = this.ctrlSnapMode; this.ctrlSnapMode.DataContextMode = GetDataContextModeForTest(); this.ctrlCurMode.ShowControl(); DisableElementSelector(); #pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler ctrlSnapMode.SetElement(ecId.Value).ContinueWith( t => { followUp?.Invoke(); }); #pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler }
/// <summary> /// Code to extract all A11yElement objects with failed results. Based on /// the code to display the failed results in Accessibility Insights for Windows. /// </summary> /// <param name="sa">The SelectAction that defines the context</param> private static List <(RuleResult, A11yElement)> ExtractFailedResults(SelectAction sa) { Guid ecId = sa.SelectedElementContextId.Value; ElementDataContext dataContext = GetDataAction.GetElementDataContext(ecId); List <(RuleResult, A11yElement)> list = new List <(RuleResult, A11yElement)>(); foreach (var element in dataContext.Elements.Values) { if (element.ScanResults?.Items == null || element.ScanResults.Items.Count == 0) { continue; } foreach (var item in element.ScanResults.Items) { var failures = from ruleResult in item.Items where ruleResult.Status == ScanStatus.Fail || ruleResult.Status == ScanStatus.ScanNotSupported select(ruleResult, element); list.AddRange(failures); } } return(list); }
/// <summary> /// Highlights the given rectangle on a clone of the given data context's /// inner bitmap and returns it /// /// If the given rectangle is null (might happen if bounding rectangle doesn't exist), /// then the original bitmap is returned /// </summary> /// <param name="ecId">Element context id</param> /// <param name="rect"></param> /// <returns></returns> private static Bitmap GetScreenShotForIssueDescription(Guid ecId, Rectangle?rect) { var dc = GetDataAction.GetElementDataContext(ecId); if (dc.Screenshot != null) { Bitmap newImg = new Bitmap(dc.Screenshot); if (rect.HasValue) { Rectangle valueRect = rect.Value; using (var graphics = Graphics.FromImage(newImg)) using (Pen pen = new Pen(Color.Red, 5)) { // Use element var el = GetDataAction.GetA11yElementInDataContext(ecId, dc.ScreenshotElementId); var outerRect = el.BoundingRectangle; valueRect.X -= outerRect.X; valueRect.Y -= outerRect.Y; graphics.DrawRectangle(pen, valueRect); } } return(newImg); } else { return(null); } }
/// <summary> /// Get appropriate DataContextMode based on datacontext of selected element context. /// </summary> /// <returns></returns> private static DataContextMode GetDataContextModeForCCA() { var mode = GetDataAction.GetDataContextMode(); switch (mode) { case DataContextMode.Live: return(DataContextMode.Test); } return(mode); }
private void GetFormAndData(DataBus dataBus, string formName) { //Get unload Form GetFormAction getFormAction = new GetFormAction(dataBus); HttpResponseMessage response = getFormAction.DoAction(); string responseData = response.GetContent(); GetDataAction getDataAction = new GetDataAction(dataBus); getDataAction.FormName = formName; response = getDataAction.DoAction(); responseData = response.GetContent(); }
/// <summary> /// Allow to change view value from mode control and update title. /// </summary> /// <param name="view"></param> internal void SetCurrentViewAndUpdateUI(dynamic view) { var ec = SelectAction.GetDefaultInstance().GetSelectedElementContextId(); this.CurrentView = view; if (ec != null) { var tp = GetDataAction.GetProcessAndUIFrameworkOfElementContext(ec.Value); PageTracker.TrackPage(this.CurrentPage, this.CurrentView.ToString(), tp.Item2); } UpdateTitleString(); UpdateMainCommandButtons(); }
/// <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. } } }
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 }
public static void GetFormAndData(DataBus dataBus, string formName) { GetFormAction getFormAction; HttpResponseMessage response; string responseData; //Get unload Form getFormAction = new GetFormAction(dataBus); response = getFormAction.DoAction(); responseData = response.GetContent(); GetDataAction getDataAction = new GetDataAction(dataBus); getDataAction.FormName = formName; response = getDataAction.DoAction(); responseData = response.GetContent(); }
/// <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 DataContext(Guid id) { try { // check whether Id exist first. if (GetDataAction.ExistElementContext(id)) { return(Ok(GetDataAction.GetElementDataContext(id))); } else { return(NotFound()); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IHttpActionResult LiveElement(Guid id, [FromUri(Name = "ElementId")] int elementId) { try { // check whether Id exist first. if (GetDataAction.ExistElementContext(id)) { return(Ok(GetDataAction.GetA11yElementWithLiveData(id, elementId))); } else { return(NotFound()); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
/// <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> /// 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> /// 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> /// Set single element /// </summary> /// <param name="ecId"></param> /// <param name="e"></param> /// <param name="txt">text to show in top right corner</param> public void SetSingleElement(Guid ecId, int eId, string txt = null) { var e = GetDataAction.GetA11yElementInDataContext(ecId, eId); Highlighter.SetSingleElement(e, txt); }
/// <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> /// 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(); }); } } }
public void Import(DataBus dataBus) { //1 Service ServiceAction serviceAction = new ServiceAction(dataBus); serviceAction.CommandLine = "db"; HttpResponseMessage response = serviceAction.DoAction(); Service serviceEntity = serviceAction.ResponseData as Service; if (serviceEntity.Threads.Count > 0) { dataBus.ThreadId = serviceEntity.Threads[0].ThreadId; } else { throw new Exception("Service action Error: no thread returned"); } string responseData = response.GetContent(); ////Get Form //GetFormAction getFormAction = new GetFormAction(dataBus); //response = getFormAction.DoAction(); //responseData = response.GetContent(); //Get Data GetDataAction getDataAction = new GetDataAction(dataBus); getDataAction.FormName = "format.prompt.db.g"; response = getDataAction.DoAction(); responseData = response.GetContent(); //Execute inport/load ExecuteAction executeAction = new ExecuteAction(dataBus); executeAction.FormName = "format.prompt.db.g"; executeAction.Type = "detail"; executeAction.EventId = 208; executeAction.ExecuteData.LoadXml("<modelChanges><focus cursorLine=\"7\" cursorLineAbs=\"10\">instance/file.name</focus></modelChanges>"); response = executeAction.DoAction(); responseData = response.GetContent(); //Get Form : import GetFormAction unloadGetFormAction = new GetFormAction(dataBus); response = unloadGetFormAction.DoAction(); responseData = response.GetContent(); //Execute import ExecuteAction importExecuteAction = new ExecuteAction(dataBus); importExecuteAction.FormName = "database.load.prompt.g"; importExecuteAction.Type = "detail"; importExecuteAction.EventId = 1; importExecuteAction.ExecuteData.LoadXml("<modelChanges></modelChanges>"); XmlElement importRootElement = importExecuteAction.ExecuteData.DocumentElement; XmlElement importVarElement = importExecuteAction.ExecuteData.CreateElement("var"); XmlElement importNameElement = importExecuteAction.ExecuteData.CreateElement("dbl.file.name"); importNameElement.AppendChild(importExecuteAction.ExecuteData.CreateTextNode(unloadLocation)); importVarElement.AppendChild(importNameElement); importRootElement.AppendChild(importVarElement); response = importExecuteAction.DoAction(); responseData = response.GetContent(); Execute executeEntity = null; do { ImportAction uploadAction = new ImportAction(dataBus); uploadAction.FileLocation = unloadLocation; response = uploadAction.DoAction(); responseData = response.GetContent(); executeEntity = uploadAction.ResponseData as Execute; ActionUtil.StoreMessages(executeEntity.ClientRequestEntity); }while (executeEntity.ClientRequestEntity.Name != "message"); while (executeEntity.ClientRequestEntity != null) { try { MessageResponseAction messageAction = new MessageResponseAction(dataBus); response = messageAction.DoAction(); // responseData = response.GetContent(); executeEntity = messageAction.ResponseData as Execute; ActionUtil.StoreMessages(executeEntity.ClientRequestEntity); } catch (Exception ex) { break; } } }
/// <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> /// Hilight an element with selected hilighter /// </summary> /// <param name="ecId">ElementContext Id</param> /// <param name="eId"></param> public void SetElement(Guid ecId, int eId) { SetElementInternal(GetDataAction.GetA11yElementInDataContext(ecId, eId)); }
public void GenerateUnload(DataBus dataBus) { //1 Service ServiceAction serviceAction = new ServiceAction(dataBus); serviceAction.CommandLine = "db"; HttpResponseMessage response = serviceAction.DoAction(); string responseData = response.GetContent(); //dataBus.ThreadId = 2; Service serviceEntity = serviceAction.ResponseData as Service; if (serviceEntity.Threads.Count > 0) { dataBus.ThreadId = serviceEntity.Threads[0].ThreadId; } else { throw new Exception("Service action Error: no thread returned"); } //Get Form GetFormAction getFormAction = new GetFormAction(dataBus); response = getFormAction.DoAction(); responseData = response.GetContent(); //Get Data GetDataAction getDataAction = new GetDataAction(dataBus); getDataAction.FormName = "format.prompt.db.g"; response = getDataAction.DoAction(); responseData = response.GetContent(); //Execute unload ExecuteAction executeAction = new ExecuteAction(dataBus); executeAction.FormName = "format.prompt.db.g"; executeAction.Type = "detail"; executeAction.EventId = 0; executeAction.ExecuteData.LoadXml("<modelChanges></modelChanges>"); XmlElement rootElement = executeAction.ExecuteData.DocumentElement; XmlElement instanceElement = executeAction.ExecuteData.CreateElement("instance"); XmlElement fileNameElement = executeAction.ExecuteData.CreateElement("file.name"); fileNameElement.AppendChild(executeAction.ExecuteData.CreateTextNode("unload")); instanceElement.AppendChild(fileNameElement); rootElement.AppendChild(instanceElement); response = executeAction.DoAction(); responseData = response.GetContent(); //Get Form : unload GetFormAction unloadGetFormAction = new GetFormAction(dataBus); response = unloadGetFormAction.DoAction(); responseData = response.GetContent(); //Execute unload ExecuteAction unloadExecuteAction = new ExecuteAction(dataBus); unloadExecuteAction.FormName = "unload.script.g"; unloadExecuteAction.Type = "detail"; unloadExecuteAction.EventId = 0; unloadExecuteAction.ExecuteData.LoadXml("<modelChanges></modelChanges>"); XmlElement unloadRootElement = unloadExecuteAction.ExecuteData.DocumentElement; XmlElement unloadInstanceElement = unloadExecuteAction.ExecuteData.CreateElement("instance"); XmlElement unloadNameElement = unloadExecuteAction.ExecuteData.CreateElement("name"); unloadNameElement.AppendChild(unloadExecuteAction.ExecuteData.CreateTextNode(unloadScriptName)); unloadInstanceElement.AppendChild(unloadNameElement); unloadRootElement.AppendChild(unloadInstanceElement); response = unloadExecuteAction.DoAction(); responseData = response.GetContent(); //Get unload Form unloadGetFormAction = new GetFormAction(dataBus); response = unloadGetFormAction.DoAction(); responseData = response.GetContent(); //GetFormAndData(dataBus, "unload.script.g"); //click unload ExecuteAction unloadButtonExecuteAction = new ExecuteAction(dataBus); unloadButtonExecuteAction.FormName = "unload.script.g"; unloadButtonExecuteAction.Type = "detail"; unloadButtonExecuteAction.EventId = 7; response = unloadButtonExecuteAction.DoAction(); responseData = response.GetContent(); //Get form and Data GetFormAndData(dataBus, "us.unload.get.name.g"); ////Get message //GetMessageAction getMessageAction = new GetMessageAction(dataBus); //response = getMessageAction.DoAction(); //responseData = response.GetContent(); //Get Unload file ExecuteAction unloadButtonOneExecuteAction = new ExecuteAction(dataBus); unloadButtonOneExecuteAction.FormName = "us.unload.get.name.g"; unloadButtonOneExecuteAction.Type = "detail"; unloadButtonOneExecuteAction.EventId = 5; unloadButtonOneExecuteAction.ExecuteData.LoadXml("<modelChanges> <focus cursorLine=\"5\" cursorLineAbs=\"5\">var/dbu.file.name</focus><focusContents>C:\\Project\\GateKeeper\\20110909\\123.unl</focusContents></modelChanges>"); XmlElement unloadButtonOneRootElement = unloadButtonOneExecuteAction.ExecuteData.DocumentElement; XmlElement unloadButtonOneVarElement = unloadButtonOneExecuteAction.ExecuteData.CreateElement("var"); XmlElement unloadButtonOneFileNameElement = unloadButtonOneExecuteAction.ExecuteData.CreateElement("L.unload.file"); unloadButtonOneFileNameElement.AppendChild(unloadButtonOneExecuteAction.ExecuteData.CreateTextNode(unloadLocation)); unloadButtonOneVarElement.AppendChild(unloadButtonOneFileNameElement); unloadButtonOneRootElement.AppendChild(unloadButtonOneVarElement); response = unloadButtonOneExecuteAction.DoAction(); responseData = response.GetContent(); Execute executeEntity = unloadButtonOneExecuteAction.ResponseData as Execute; int attachmentCount = 0; if (executeEntity.ClientRequestEntity.File != null) { try { attachmentCount = executeEntity.ClientRequestEntity.File.Attachments.Count; } catch (Exception ex) { throw new Exception("Error when get unload file"); } } ActionUtil.StoreMessages(executeEntity.ClientRequestEntity); //Message //FilePutResponseAction filePutResponseAction = new FilePutResponseAction(dataBus); //response = filePutResponseAction.DoAction(); //responseData = response.GetContent(); //MessageResponseAction messageResponseAction = new MessageResponseAction(dataBus); //response = messageResponseAction.DoAction(); //responseData = response.GetContent(); //Store Data to local FileStream fileStream = null; Collection <byte[]> attachments = response.GetAttachments(); if (attachments.Count > 0) { int lastSlashIndex = unloadLocation.LastIndexOf("\\"); string dirPath = unloadLocation.Substring(0, lastSlashIndex); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } fileStream = new FileStream(unloadLocation, FileMode.Create, FileAccess.Write); byte[] attachData = attachments[0].ToArray(); fileStream.Write(attachData, 0, attachData.Length); } //Get following parts of the attachments FilePutResponseAction filePutResponseAction = new FilePutResponseAction(dataBus); response = filePutResponseAction.DoAction(); responseData = response.GetContent(); while (response.GetAttachments().Count > 0) { byte[] attachData = response.GetAttachments()[0].ToArray(); fileStream.Write(attachData, 0, attachData.Length); response = filePutResponseAction.DoAction(); responseData = response.GetContent(); } if (fileStream != null) { fileStream.Flush(); fileStream.Close(); } ActionUtil.GetFormAndData(dataBus, "unload.script.g"); }
/// <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); }
public void GenerateUnloadScript(DataBus dataBus) { //1 Service ServiceAction serviceAction = new ServiceAction(dataBus); serviceAction.CommandLine = "db"; HttpResponseMessage response = serviceAction.DoAction(); string responseData = response.GetContent(); Service serviceEntity = serviceAction.ResponseData as Service; if (serviceEntity.Threads.Count > 0) { dataBus.ThreadId = serviceEntity.Threads[0].ThreadId; } else { throw new Exception("Service action Error: no thread returned"); } ////Get Form //GetFormAction getFormAction = new GetFormAction(dataBus); //response = getFormAction.DoAction(); //responseData = response.GetContent(); //Get Data GetDataAction getDataAction = new GetDataAction(dataBus); getDataAction.FormName = "format.prompt.db.g"; response = getDataAction.DoAction(); responseData = response.GetContent(); // ActionUtil.GetFormAndData(dataBus, "format.prompt.db.g"); //Execute in DB form to go to unload file ExecuteAction executeAction = new ExecuteAction(dataBus); executeAction.FormName = "format.prompt.db.g"; executeAction.Type = "detail"; executeAction.EventId = 0; executeAction.ExecuteData.LoadXml("<modelChanges></modelChanges>"); XmlElement rootElement = executeAction.ExecuteData.DocumentElement; XmlElement instanceElement = executeAction.ExecuteData.CreateElement("instance"); XmlElement fileNameElement = executeAction.ExecuteData.CreateElement("file.name"); fileNameElement.AppendChild(executeAction.ExecuteData.CreateTextNode("unload")); instanceElement.AppendChild(fileNameElement); rootElement.AppendChild(instanceElement); response = executeAction.DoAction(); responseData = response.GetContent(); //Get Form : unload GetFormAction unloadGetFormAction = new GetFormAction(dataBus); response = unloadGetFormAction.DoAction(); responseData = response.GetContent(); //Execute Search for specialized unload ticket ExecuteAction unloadExecuteAction = new ExecuteAction(dataBus); unloadExecuteAction.FormName = "unload.script.g"; unloadExecuteAction.Type = "detail"; unloadExecuteAction.EventId = 6; unloadExecuteAction.ExecuteData.LoadXml("<modelChanges></modelChanges>"); XmlElement unloadRootElement = unloadExecuteAction.ExecuteData.DocumentElement; XmlElement unloadInstanceElement = unloadExecuteAction.ExecuteData.CreateElement("instance"); XmlElement unloadNameElement = unloadExecuteAction.ExecuteData.CreateElement("name"); unloadNameElement.AppendChild(unloadExecuteAction.ExecuteData.CreateTextNode(unloadScriptName)); unloadInstanceElement.AppendChild(unloadNameElement); unloadRootElement.AppendChild(unloadInstanceElement); response = unloadExecuteAction.DoAction(); responseData = response.GetContent(); ////Get unload Form //GetFormAction unloadGetFormAction = new GetFormAction(dataBus); //response = unloadGetFormAction.DoAction(); //responseData = response.GetContent(); ActionUtil.GetFormAndData(dataBus, "unload.script.g"); //click unload ExecuteAction unloadButtonExecuteAction = new ExecuteAction(dataBus); unloadButtonExecuteAction.FormName = "unload.script.g"; unloadButtonExecuteAction.Type = "detail"; unloadButtonExecuteAction.EventId = 211; unloadButtonExecuteAction.ExecuteData.LoadXml("<modelChanges><focus cursorLine=\"2\" cursorLineAbs=\"2\">instance/name</focus></modelChanges>"); response = unloadButtonExecuteAction.DoAction(); responseData = response.GetContent(); ActionUtil.GetFormAndData(dataBus, "file.prompt.dbu.g"); //Get message GetMessageAction getMessageAction = new GetMessageAction(dataBus); response = getMessageAction.DoAction(); responseData = response.GetContent(); //Get Unload Script file ExecuteAction unloadButtonOneExecuteAction = new ExecuteAction(dataBus); unloadButtonOneExecuteAction.FormName = "file.prompt.dbu.g"; unloadButtonOneExecuteAction.Type = "detail"; unloadButtonOneExecuteAction.EventId = 1; unloadButtonOneExecuteAction.ExecuteData.LoadXml("<modelChanges> <focus cursorLine=\"5\" cursorLineAbs=\"5\">var/dbu.file.name</focus><focusContents>C:\\Users\\daizhen\\Research\\GK_Tool\\12d3.script.unl</focusContents></modelChanges>"); XmlElement unloadButtonOneRootElement = unloadButtonOneExecuteAction.ExecuteData.DocumentElement; XmlElement unloadButtonOneVarElement = unloadButtonOneExecuteAction.ExecuteData.CreateElement("var"); XmlElement unloadButtonOneFileNameElement = unloadButtonOneExecuteAction.ExecuteData.CreateElement("dbu.file.name"); unloadButtonOneFileNameElement.AppendChild(unloadButtonOneExecuteAction.ExecuteData.CreateTextNode(location)); unloadButtonOneVarElement.AppendChild(unloadButtonOneFileNameElement); unloadButtonOneRootElement.AppendChild(unloadButtonOneVarElement); response = unloadButtonOneExecuteAction.DoAction(); responseData = response.GetContent(); Execute executeEntity = unloadButtonOneExecuteAction.ResponseData as Execute; int attachmentCount = 0; try { attachmentCount = executeEntity.ClientRequestEntity.File.Attachments.Count; } catch (Exception ex) { throw new Exception("Error when get unload script"); } //Handle the messages ActionUtil.StoreMessages(executeEntity.ClientRequestEntity); //Store Data to local int lastSlashIndex = location.LastIndexOf("\\"); string dirPath = location.Substring(0, lastSlashIndex); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } FileStream fileStream = new FileStream(location, FileMode.Create, FileAccess.Write); byte[] attachData = response.GetAttachments()[0].ToArray(); fileStream.Write(attachData, 0, attachData.Length); //Get following parts of the attachments FilePutResponseAction filePutResponseAction = new FilePutResponseAction(dataBus); response = filePutResponseAction.DoAction(); responseData = response.GetContent(); executeEntity = filePutResponseAction.ResponseData as Execute; ActionUtil.StoreMessages(executeEntity.ClientRequestEntity); //while (response.GetAttachments().Count > 0) for (int i = 1; i < attachmentCount; i++) { attachData = response.GetAttachments()[0].ToArray(); fileStream.Write(attachData, 0, attachData.Length); response = filePutResponseAction.DoAction(); responseData = response.GetContent(); executeEntity = filePutResponseAction.ResponseData as Execute; ActionUtil.StoreMessages(executeEntity.ClientRequestEntity); } fileStream.Close(); ActionUtil.GetFormAndData(dataBus, "unload.script.g"); }