Пример #1
0
        /// <summary>
        /// Private helper function (formerly in SaveSnapshotZip) to make it easier to call with different inputs
        /// </summary>
        private static void SaveSnapshotFromElement(int?focusedElementId, A11yFileMode mode, Dictionary <SnapshotMetaPropertyName, object> otherProperties, Contexts.ElementContext ec, Package package, A11yElement root)
        {
            var json = JsonConvert.SerializeObject(root, Formatting.Indented);

            using (MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(json)))
            {
                AddStream(package, mStrm, elementFileName);
            }

            if (ec.DataContext.Screenshot != null)
            {
                using (MemoryStream mStrm = new MemoryStream())
                {
                    ec.DataContext.Screenshot.Save(mStrm, System.Drawing.Imaging.ImageFormat.Png);
                    mStrm.Seek(0, SeekOrigin.Begin);

                    AddStream(package, mStrm, screenshotFileName);
                }
            }

            var meta     = new SnapshotMetaInfo(mode, RuleRunner.GetRuleVersion(), focusedElementId, ec.DataContext.ScreenshotElementId, otherProperties);
            var jsonMeta = JsonConvert.SerializeObject(meta, Formatting.Indented);

            using (MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(jsonMeta)))
            {
                AddStream(package, mStrm, metatdataFileName);
            }
        }
Пример #2
0
 /// <summary>
 /// Notify Element selection to swith mode to snapshot
 /// </summary>
 /// <param name="e"></param>
 private void NotifySelected(A11yElement e)
 {
     this.DataContext.FocusedElementUniqueId = e.UniqueId;
     NotifyElementSelected();
 }
 /// <summary>
 /// Add Element in highlighter
 /// Overlay highlighter needs element than Id. please see comment above at class definition.
 /// </summary>
 /// <param name="e">element</param>
 /// <param name="num">Id Number of highlighter</param>
 public void AddElement(A11yElement e, string num)
 {
     Highlighter.AddElementRoundBorder(e, num);
 }
Пример #4
0
 /// <summary>
 /// SetElement with A11yElement
 /// this one should be used only for Event handling case
 /// </summary>
 /// <param name="el"></param>
 public void SetElement(A11yElement el)
 {
     SetElementInternal(el);
 }
Пример #5
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="file">The file that contains the element</param>
 /// <param name="element">The element in question</param>
 public OutputFileLocation(string file, A11yElement element)
     : this(file, element, (startInfo) => Process.Start(startInfo))
 {
 }
 /// <summary>
 /// Remove Element
 /// Overlay highlighter needs element than Id. please see comment above at class definition.
 /// </summary>
 /// <param name="e"></param>
 public void RemoveElement(A11yElement e)
 {
     Highlighter.RemoveElement(e);
 }
        /// <summary>
        /// Draw rectangle around the selected element in the application
        /// </summary>
        public void MarkSelectedElement()
        {
            A11yElement ele = SelectAction.GetDefaultInstance().POIElementContext.Element;

            this.Highlighter.MarkSelectedElement(ele);
        }
        /// <summary>
        /// SetElement with A11yElement
        /// this one should be used only for Event handling case
        /// </summary>
        /// <param name="el"></param>
        public void SetElement(A11yElement el)
        {
#pragma warning disable CA1062 // Validate arguments of public methods
            SetElementInternal(el);
#pragma warning restore CA1062 // Validate arguments of public methods
        }
Пример #9
0
        public DropTargetPattern(A11yElement e, IUIAutomationDropTargetPattern p) : base(e, PatternType.UIA_DropTargetPatternId)
        {
            Pattern = p;

            PopulateProperties();
        }
Пример #10
0
        private static OutputFile WriteOutputFiles(OutputFileFormat outputFileFormat, IScanTools scanTools, A11yElement element, Guid elementId)
        {
            if (scanTools == null)
            {
                throw new ArgumentNullException(nameof(scanTools));
            }
            if (scanTools.OutputFileHelper == null)
            {
                throw new ArgumentException(ErrorMessages.ScanToolsOutputFileHelperNull, nameof(scanTools));
            }

            string a11yTestOutputFile = null;

            if (outputFileFormat.HasFlag(OutputFileFormat.A11yTest))
            {
                scanTools.Actions.CaptureScreenshot(elementId);

                a11yTestOutputFile = scanTools.OutputFileHelper.GetNewA11yTestFilePath();
                if (a11yTestOutputFile == null)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ErrorMessages.VariableNull, nameof(a11yTestOutputFile)));
                }

                scanTools.Actions.SaveA11yTestFile(a11yTestOutputFile, element, elementId);
            }

            return(OutputFile.BuildFromA11yTestFile(a11yTestOutputFile));
        }
Пример #11
0
 public ScrollItemPattern(A11yElement e, IUIAutomationScrollItemPattern p) : base(e, PatternType.UIA_ScrollItemPatternId)
 {
     Pattern = p;
 }
Пример #12
0
 /// <summary>
 /// Wrapper to switch to events mode for IHierarchyAction
 /// </summary>
 public void HandleLiveToEvents(A11yElement el)
 {
     MainWin.HandleLiveToEvents(el);
 }
Пример #13
0
 /// <summary>
 /// Update Element Info UI(Properties/Patterns/Tests)
 /// </summary>
 /// <param name="e"></param>
 private void UpdateElementInfoUI(A11yElement e)
 {
     this.ctrlTabs.SetElement(e, e != null && e.PlatformObject != null);
 }
 /// <summary>
 /// Draw rectangle around the selected element in the pattern window in the application
 /// </summary>
 public void MarkElement(A11yElement ele)
 {
     RemoveBorder(PatternSelectedElementRect);
     PatternSelectedElementRect = AddElement(ele, Brush);
 }
Пример #15
0
        /// <summary>
        /// Get the Instance of specific pattern.
        /// if there is no matching pattern, it is wrapped up as Unknown.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static A11yPattern GetPatternInstance(A11yElement e, IUIAutomationElement uia, int id, string name)
        {
            try
            {
                dynamic pt = null;

                if (PatternType.GetInstance().Exists(id))
                {
                    pt = uia.GetCachedPattern(id);
                }

                if (pt != null)
                {
                    switch (id)
                    {
                    case PatternType.UIA_AnnotationPatternId:
                        return(new AnnotationPattern(e, pt));

                    case PatternType.UIA_CustomNavigationPatternId:
                        return(new CustomNavigationPattern(e, pt));

                    case PatternType.UIA_DockPatternId:
                        return(new DockPattern(e, pt));

                    case PatternType.UIA_DragPatternId:
                        return(new DragPattern(e, pt));

                    case PatternType.UIA_DropTargetPatternId:
                        return(new DropTargetPattern(e, pt));

                    case PatternType.UIA_ExpandCollapsePatternId:
                        return(new ExpandCollapsePattern(e, pt));

                    case PatternType.UIA_GridItemPatternId:
                        return(new GridItemPattern(e, pt));

                    case PatternType.UIA_GridPatternId:
                        return(new GridPattern(e, pt));

                    case PatternType.UIA_InvokePatternId:
                        return(new InvokePattern(e, pt));

                    case PatternType.UIA_ItemContainerPatternId:
                        return(new ItemContainerPattern(e, pt));

                    case PatternType.UIA_LegacyIAccessiblePatternId:
                        return(new LegacyIAccessiblePattern(e, pt));

                    case PatternType.UIA_MultipleViewPatternId:
                        return(new MultipleViewPattern(e, pt));

                    case PatternType.UIA_ObjectModelPatternId:
                        return(new ObjectModelPattern(e, pt));

                    case PatternType.UIA_RangeValuePatternId:
                        return(new RangeValuePattern(e, pt));

                    case PatternType.UIA_ScrollItemPatternId:
                        return(new ScrollItemPattern(e, pt));

                    case PatternType.UIA_ScrollPatternId:
                        return(new ScrollPattern(e, pt));

                    case PatternType.UIA_SelectionItemPatternId:
                        return(new SelectionItemPattern(e, pt));

                    case PatternType.UIA_SelectionPatternId:
                        return(new SelectionPattern(e, pt));

                    case PatternType.UIA_SelectionPattern2Id:
                        return(new SelectionPattern2(e, pt));

                    case PatternType.UIA_SpreadsheetPatternId:
                        return(new SpreadsheetPattern(e, pt));

                    case PatternType.UIA_SpreadsheetItemPatternId:
                        return(new SpreadsheetItemPattern(e, pt));

                    case PatternType.UIA_StylesPatternId:
                        return(new StylesPattern(e, pt));

                    case PatternType.UIA_SynchronizedInputPatternId:
                        return(new SynchronizedInputPattern(e, pt));

                    case PatternType.UIA_TableItemPatternId:
                        return(new TableItemPattern(e, pt));

                    case PatternType.UIA_TablePatternId:
                        return(new TablePattern(e, pt));

                    case PatternType.UIA_TextChildPatternId:
                        return(new TextChildPattern(e, pt));

                    case PatternType.UIA_TextEditPatternId:
                        return(new TextEditPattern(e, pt));

                    case PatternType.UIA_TextPatternId:
                        return(new TextPattern(e, pt));

                    case PatternType.UIA_TextPattern2Id:
                        return(new TextPattern2(e, pt));

                    case PatternType.UIA_TogglePatternId:
                        return(new TogglePattern(e, pt));

                    case PatternType.UIA_TransformPatternId:
                        return(new TransformPattern(e, pt));

                    case PatternType.UIA_TransformPattern2Id:
                        return(new TransformPattern2(e, pt));

                    case PatternType.UIA_ValuePatternId:
                        return(new ValuePattern(e, pt));

                    case PatternType.UIA_VirtualizedItemPatternId:
                        return(new VirtualizedItemPattern(e, pt));

                    case PatternType.UIA_WindowPatternId:
                        return(new WindowPattern(e, pt));
                    }
                }
                return(new UnKnownPattern(e, id, name));
            }
            catch (Exception ex)
            {
                ex.ReportException();

                return(null);
            }
        }
Пример #16
0
        public SelectionItemPattern(A11yElement e, IUIAutomationSelectionItemPattern p) : base(e, PatternType.UIA_SelectionItemPatternId)
        {
            Pattern = p;

            PopulateProperties();
        }
 public static IFingerprint GetFingerPrint(A11yElement element, RuleId ruleId, ScanStatus status)
 {
     // Very simplistic implementation of the factory. If we decide to add a few more generators will need a switch case and type enum.
     return(new ScanResultFingerprint(element, ruleId, status));
 }
        public WindowPattern(A11yElement e, IUIAutomationWindowPattern p) : base(e, PatternType.UIA_WindowPatternId)
        {
            Pattern = p;

            PopulateProperties();
        }
 /// <summary>
 /// Update Element
 /// Overlay highlighter needs element than Id. please see comment above at class definition.
 /// </summary>
 /// <param name="el"></param>
 public void UpdateElement(A11yElement el)
 {
     Highlighter.UpdateElement(el);
 }
Пример #20
0
        /// <summary>
        /// Refresh the property and patterns with Live data.
        /// it also set the Glimpse
        /// the update is done via caching to improve performance.
        /// </summary>
        /// <param name="useProperties">default is false to refresh it from UIElement directly</param>
        private static void PopulatePropertiesAndPatternsFromCache(this A11yElement element)
        {
            try
            {
                // Get the list of properties to retrieve
                A11yAutomation.GetUIAutomationObject().PollForPotentialSupportedProperties((IUIAutomationElement)element.PlatformObject, out int[] ppids, out string[] ppns);

                var ppl = new List <Tuple <int, string> >();

                for (int i = 0; i < ppids.Length; i++)
                {
                    var id   = (int)ppids.GetValue(i);
                    var name = (string)ppns.GetValue(i);

                    if (DesktopElement.IsExcludedProperty(id, name) == false)
                    {
                        ppl.Add(new Tuple <int, string>(id, name));
                    }
                }

                A11yAutomation.GetUIAutomationObject().PollForPotentialSupportedPatterns((IUIAutomationElement)element.PlatformObject, out int[] ptids, out string[] ptns);
                var ptl = new List <Tuple <int, string> >();

                for (int i = 0; i < ptids.Length; i++)
                {
                    ptl.Add(new Tuple <int, string>((int)ptids.GetValue(i), (string)ptns.GetValue(i)));
                }

                var pplist = (from pp in ppl
                              select pp.Item1).ToList();
                var ptlist = (from pt in ptl
                              select pt.Item1).ToList();

                // build a cache based on the lists
                var cache = DesktopElementHelper.BuildCacheRequest(pplist, ptlist);

                // buildupdate cached element
                var uia = ((IUIAutomationElement)element.PlatformObject).BuildUpdatedCache(cache);

                // retrieve properties from cache
                var ps = (from pp in ppl//.AsParallel()
                          let val = GetPropertyValueFromCache(uia, pp.Item1)
                                    where val != null
                                    select new A11yProperty(pp.Item1, val, pp.Item2));

                element.Properties = ps.Where(p => !string.IsNullOrEmpty(p.TextValue)).ToDictionary(d => d.Id);

                element.UpdateGlimpse();

                // retrieve patterns from cache
                var ptlst = from pt in ptl
                            let pi = A11yPatternFactory.GetPatternInstance(element, uia, pt.Item1, pt.Item2)
                                     where pi != null
                                     select pi;

                element.Patterns = ptlst.ToList();

                // release previous UIAElement
                Marshal.ReleaseComObject(uia);
                // release cache interface.
                Marshal.ReleaseComObject(cache);

                ppl?.Clear();
                ptl?.Clear();
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
 /// <summary>
 /// Draw rectangle around the selected element in the pattern window in the application
 /// </summary>
 public void MarkElement(A11yElement ele)
 {
     this.Highlighter.MarkElement(ele);
 }
Пример #22
0
 public TextEditPattern(A11yElement e, IUIAutomationTextEditPattern p) : base(e, PatternType.UIA_TextEditPatternId)
 {
     Pattern = p;
 }
        public ScrollPattern(A11yElement e, IUIAutomationScrollPattern p) : base(e, PatternType.UIA_ScrollPatternId)
        {
            Pattern = p;

            PopulateProperties();
        }
 public SpreadsheetPattern(A11yElement e, IUIAutomationSpreadsheetPattern p) : base(e, PatternType.UIA_SpreadsheetPatternId)
 {
     Pattern = p;
 }
Пример #25
0
        public GridItemPattern(A11yElement e, IUIAutomationGridItemPattern p) : base(e, PatternType.UIA_GridItemPatternId)
        {
            Pattern = p;

            PopulateProperties();
        }
Пример #26
0
 public EventListenerFactory(A11yElement rootElement) : this(rootElement, ListenScope.Subtree)
 {
 }
Пример #27
0
 public TogglePattern(A11yElement e, IUIAutomationTogglePattern p) : base(e, PatternType.UIA_TogglePatternId)
 {
     Pattern = p;
     PopulateProperties();
 }
Пример #28
0
        public MultipleViewPattern(A11yElement e, IUIAutomationMultipleViewPattern p) : base(e, PatternType.UIA_MultipleViewPatternId)
        {
            Pattern = p;

            PopulateProperties();
        }
 /// <summary>
 /// Set Element
 /// Overlay highlighter needs element than Id. please see comment above at class definition.
 /// </summary>
 /// <param name="e"></param>
 /// <param name="brush"></param>
 /// <param name="onMouseDown"></param>
 /// <param name="gap"></param>
 public void SetElement(A11yElement e, SolidColorBrush brush, MouseButtonEventHandler onMouseDown = null, int gap = 2)
 {
     Highlighter.SetElement(e, brush, onMouseDown, gap);
 }
Пример #30
0
 /// <summary>
 /// Constructor
 /// </summary>
 internal ElementDataContext(A11yElement e, int maxElements)
 {
     this.Element   = e;
     ElementCounter = new BoundedCounter(maxElements);
 }