public async Task SetElement()

in src/AccessibilityInsights/Modes/CCAModeControl.xaml.cs [156:241]


        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
            }
        }