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

                // selection only when UI snapshot is done.
                if (this.SelectedInHierarchyElement != null && MainWin.CurrentPage == AppPage.Inspect && (InspectView)MainWin.CurrentView == InspectView.Live)
                {
                    var e = GetDataAction.GetA11yElementWithLiveData(this.SelectedInHierarchyElement.Item1, this.SelectedInHierarchyElement.Item2);
                    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;
            }
        }
 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()));
     }
 }
 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()));
     }
 }
Beispiel #4
0
        /// <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>
        /// 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 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
            }
        }