Example #1
0
 /// <summary>
 /// Make sure that statemachine and UI are updated for Live mode.
 /// </summary>
 private static void UpdateStateMachineForCCAAutomaticMode()
 {
     // enable selector once UI update is finished.
     MainWin?.SetCurrentViewAndUpdateUI(CCAView.Automatic);
     MainWin?.EnableElementSelector();
 }
Example #2
0
 /// <summary>
 /// Make sure that statemachine and UI are updated for Live mode.
 /// </summary>
 private static void UpdateStateMachineForLiveMode()
 {
     // enable selector once UI update is finished.
     MainWin?.SetCurrentViewAndUpdateUI(InspectView.Live);
     MainWin?.EnableElementSelector();
 }
Example #3
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>
        /// 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
            }
        }