当前位置: 首页>>代码示例>>C#>>正文


C# Automation.CacheRequest类代码示例

本文整理汇总了C#中System.Windows.Automation.CacheRequest的典型用法代码示例。如果您正苦于以下问题:C# CacheRequest类的具体用法?C# CacheRequest怎么用?C# CacheRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CacheRequest类属于System.Windows.Automation命名空间,在下文中一共展示了CacheRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTabsOfWindow

		public IEnumerable<ITab> GetTabsOfWindow(IntPtr hWnd)
		{
			var notepadPlusPlusWindow = AutomationElement.FromHandle(hWnd);

			var cacheRequest = new CacheRequest();
			cacheRequest.Add(AutomationElement.NameProperty);
			cacheRequest.Add(AutomationElement.LocalizedControlTypeProperty);
			cacheRequest.Add(SelectionItemPattern.Pattern);
			cacheRequest.Add(SelectionItemPattern.SelectionContainerProperty);
			cacheRequest.TreeScope = TreeScope.Element;

			AutomationElement tabBarElement;

			using (cacheRequest.Activate())
			{
				tabBarElement = notepadPlusPlusWindow.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "tab"));
			}

			if(tabBarElement == null)
				yield break;

			var tabElements = tabBarElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "tab item"));

			for (var tabIndex = 0; tabIndex < tabElements.Count; tabIndex++)
			{
				yield return new NotepadPlusPlusTab(tabElements[tabIndex]);
			}
		}
开发者ID:olivierdagenais,项目名称:GoToWindow,代码行数:28,代码来源:NotepadPlusPlusTabsFinder.cs

示例2: PushPopTest

        public void PushPopTest()
        {
            CacheRequest defaultCR = CacheRequest.Current;
            CacheRequest target = new CacheRequest();
            target.TreeScope = TreeScope.Children;
            target.Push();
            CacheRequest target2 = new CacheRequest();
            target2.TreeScope = TreeScope.Subtree;
            target2.Push();

            // Try to change target2 - this should fail
            try
            {
                target2.TreeScope = TreeScope.Descendants;

                Assert.Fail("exception expected");
            }
            catch (System.InvalidOperationException)
            {
            }

            target2.Pop();
            target.Pop();
            Assert.AreEqual(CacheRequest.Current, defaultCR);
        }
开发者ID:RyuaNerin,项目名称:UIAComWrapper,代码行数:25,代码来源:CacheRequestTest.cs

示例3: GridPatternCachedTest

        public void GridPatternCachedTest()
        {
            CacheRequest req = new CacheRequest();
            req.Add(GridItemPattern.Pattern);
            req.Add(GridPattern.Pattern);
            req.Add(GridPattern.RowCountProperty);
            req.Add(GridPattern.ColumnCountProperty);
            req.Add(GridItemPattern.RowProperty);
            req.Add(GridItemPattern.ColumnProperty);
            req.Add(GridItemPattern.ContainingGridProperty);

            using (req.Activate())
            {
                AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree,
                    new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView"));
                Assert.IsNotNull(itemsView);

                // Try out the Grid Pattern
                GridPattern grid = (GridPattern)itemsView.GetCachedPattern(GridPattern.Pattern);
                Assert.IsTrue(grid.Cached.ColumnCount > 0);
                Assert.IsTrue(grid.Cached.RowCount > 0);

                // GridItem
                AutomationElement gridItemElement = grid.GetItem(0, 0);
                Assert.IsNotNull(gridItemElement);
                GridItemPattern gridItem = (GridItemPattern)gridItemElement.GetCachedPattern(GridItemPattern.Pattern);
                Assert.AreEqual(gridItem.Cached.Row, 0);
                Assert.AreEqual(gridItem.Cached.Column, 0);
                Assert.AreEqual(gridItem.Cached.ContainingGrid, itemsView);
            }
        }
开发者ID:RyuaNerin,项目名称:UIAComWrapper,代码行数:31,代码来源:ExplorerTargetTests.cs

示例4: AutomationElementModeTest

 public void AutomationElementModeTest()
 {
     CacheRequest target = new CacheRequest(); 
     target.AutomationElementMode = AutomationElementMode.Full;
     AutomationElementMode actual = target.AutomationElementMode;
     Assert.AreEqual(AutomationElementMode.Full, actual);
 }
开发者ID:RyuaNerin,项目名称:UIAComWrapper,代码行数:7,代码来源:CacheRequestTest.cs

示例5: BuildCacheRequest

 public static CacheRequest BuildCacheRequest(TreeScope treeScope, params AutomationProperty[] properties)
 {
     var cr = new CacheRequest { TreeScope = treeScope };
      foreach (var property in properties)
     cr.Add(property);
      return cr;
 }
开发者ID:softek,项目名称:WinUIScraper,代码行数:7,代码来源:AutomationExtensions.cs

示例6: TreeScopeTest

 public void TreeScopeTest()
 {
     CacheRequest target = new CacheRequest();
     TreeScope expected = TreeScope.Subtree;
     TreeScope actual;
     target.TreeScope = expected;
     actual = target.TreeScope;
     Assert.AreEqual(expected, actual);
 }
开发者ID:jeffras,项目名称:uiverify,代码行数:9,代码来源:CacheRequestTest.cs

示例7: TreeFilterTest

 public void TreeFilterTest()
 {
     CacheRequest target = new CacheRequest();
     PropertyCondition expected = new PropertyCondition(AutomationElement.NameProperty, "foo");
     PropertyCondition actual;
     target.TreeFilter = expected;
     actual = (PropertyCondition)target.TreeFilter;
     Assert.AreEqual(expected.Flags, actual.Flags);
     Assert.AreEqual(expected.Property, actual.Property);
     Assert.AreEqual(expected.Value, actual.Value);
 }
开发者ID:RyuaNerin,项目名称:UIAComWrapper,代码行数:11,代码来源:CacheRequestTest.cs

示例8: GetLastChild

 public AutomationElement GetLastChild(AutomationElement element, CacheRequest request)
 {
     Utility.ValidateArgumentNonNull(element, "element");
     Utility.ValidateArgumentNonNull(request, "request");
     try
     {
         return AutomationElement.Wrap(this._obj.GetLastChildElementBuildCache(
             element.NativeElement,
             request.NativeCacheRequest));
     }
     catch (System.Runtime.InteropServices.COMException e)
     {
         Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
     }
 }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:15,代码来源:TreeWalker.cs

示例9: MyTestInitialize

 public void MyTestInitialize()
 {
     // Get all children of the desktop for our target collection
     CacheRequest cacheReq = new CacheRequest();
     cacheReq.Add(AutomationElement.NameProperty);
     cacheReq.Add(AutomationElement.NativeWindowHandleProperty);
     using (cacheReq.Activate())
     {
         this.testColl = AutomationElement.RootElement.FindAll(
             TreeScope.Children,
             Condition.TrueCondition);
         Assert.IsNotNull(this.testColl);
         Assert.IsTrue(this.testColl.Count > 0);
     }
 }
开发者ID:jeffras,项目名称:uiverify,代码行数:15,代码来源:AutomationElementCollectionTest.cs

示例10: ExpandCollapsePatternCachedTest

        public void ExpandCollapsePatternCachedTest()
        {
            using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL intl.cpl"))
            {
                CacheRequest req = new CacheRequest();
                req.Add(ExpandCollapsePattern.Pattern);
                req.Add(ExpandCollapsePattern.ExpandCollapseStateProperty);
                using (req.Activate())
                {
                    // Find a well-known combo box
                    AutomationElement combo = host.Element.FindFirst(TreeScope.Subtree,
                        new PropertyCondition(AutomationElement.AutomationIdProperty, "1021"));
                    Assert.IsNotNull(combo);

                    ExpandCollapsePattern expando = (ExpandCollapsePattern)combo.GetCachedPattern(ExpandCollapsePattern.Pattern);
                    Assert.AreEqual(expando.Cached.ExpandCollapseState, ExpandCollapseState.Collapsed);
                }
            }
        }
开发者ID:RyuaNerin,项目名称:UIAComWrapper,代码行数:19,代码来源:ScenarioTests.cs

示例11: TablePatternCachedTest

        public void TablePatternCachedTest()
        {
            CacheRequest req = new CacheRequest();
            req.Add(TablePattern.Pattern);
            req.Add(TableItemPattern.Pattern);
            req.Add(GridPattern.Pattern);
            req.Add(GridItemPattern.Pattern);
            req.Add(GridPattern.RowCountProperty);
            req.Add(GridPattern.ColumnCountProperty);
            req.Add(GridItemPattern.RowProperty);
            req.Add(GridItemPattern.ColumnProperty);
            req.Add(GridItemPattern.ContainingGridProperty);
            req.Add(TablePattern.RowHeadersProperty);
            req.Add(TablePattern.ColumnHeadersProperty);
            req.Add(TableItemPattern.RowHeaderItemsProperty);
            req.Add(TableItemPattern.ColumnHeaderItemsProperty);
            using (req.Activate())
            {
                AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree,
                    new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView"));
                Assert.IsNotNull(itemsView);

                // TablePattern test
                TablePattern table = (TablePattern)itemsView.GetCachedPattern(TablePattern.Pattern);
                Assert.IsTrue(table.Cached.ColumnCount > 0);
                Assert.IsTrue(table.Cached.RowCount > 0);
                Assert.IsTrue(table.Cached.GetRowHeaders().Length == 0);
                Assert.IsTrue(table.Cached.GetColumnHeaders().Length > 0);

                AutomationElement tableItemElement = table.GetItem(0, 0);
                TableItemPattern tableItem = (TableItemPattern)tableItemElement.GetCachedPattern(TableItemPattern.Pattern);
                Assert.AreEqual(tableItem.Cached.Row, 0);
                Assert.AreEqual(tableItem.Cached.Column, 0);
                Assert.AreEqual(tableItem.Cached.ContainingGrid, itemsView);
                Assert.IsTrue(tableItem.Cached.GetColumnHeaderItems().Length == 1);
                Assert.IsTrue(tableItem.Cached.GetRowHeaderItems().Length == 0);
            }
        }
开发者ID:RyuaNerin,项目名称:UIAComWrapper,代码行数:38,代码来源:ExplorerTargetTests.cs

示例12: Navigate

        // Called by the treewalker classes to navigate - we call through to the
        // provider wrapper, which gets the navigator code to do its stuff
        internal AutomationElement Navigate(NavigateDirection direction, Condition condition, CacheRequest request)
        {
            CheckElement();

            UiaCoreApi.UiaCacheRequest cacheRequest;
            if (request == null)
                cacheRequest = CacheRequest.DefaultUiaCacheRequest;
            else
                cacheRequest = request.GetUiaCacheRequest();

            UiaCoreApi.UiaCacheResponse response = UiaCoreApi.UiaNavigate(_hnode, direction, condition, cacheRequest);
            return CacheHelper.BuildAutomationElementsFromResponse(cacheRequest, response);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:15,代码来源:AutomationElement.cs

示例13: Normalize

        internal AutomationElement Normalize(Condition condition, CacheRequest request )
        {
            CheckElement();

            UiaCoreApi.UiaCacheRequest cacheRequest;
            if (request == null)
                cacheRequest = CacheRequest.DefaultUiaCacheRequest;
            else
                cacheRequest = request.GetUiaCacheRequest();

            // Normalize against the treeview condition, not the one in the cache request...
            UiaCoreApi.UiaCacheResponse response = UiaCoreApi.UiaGetUpdatedCache(_hnode, cacheRequest, UiaCoreApi.NormalizeState.Custom, condition);
            return CacheHelper.BuildAutomationElementsFromResponse(cacheRequest, response);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:14,代码来源:AutomationElement.cs

示例14: SubscribeToEvents

        protected internal void SubscribeToEvents(HasControlInputCmdletBase cmdlet,
                                                  AutomationElement inputObject,
                                                  AutomationEvent eventType,
                                                  AutomationProperty prop)
        {
            AutomationEventHandler uiaEventHandler;
            AutomationPropertyChangedEventHandler uiaPropertyChangedEventHandler;
            StructureChangedEventHandler uiaStructureChangedEventHandler;
            AutomationFocusChangedEventHandler uiaFocusChangedEventHandler;

            // 20130109
            if (null == CurrentData.Events) {
                CurrentData.InitializeEventCollection();
            }

            try {

                CacheRequest cacheRequest = new CacheRequest();
                cacheRequest.AutomationElementMode = AutomationElementMode.Full; //.None;
                cacheRequest.TreeFilter = Automation.RawViewCondition;
                cacheRequest.Add(AutomationElement.NameProperty);
                cacheRequest.Add(AutomationElement.AutomationIdProperty);
                cacheRequest.Add(AutomationElement.ClassNameProperty);
                cacheRequest.Add(AutomationElement.ControlTypeProperty);
                //cacheRequest.Add(AutomationElement.ProcessIdProperty);
                // cache patterns?

                // cacheRequest.Activate();
                cacheRequest.Push();

                switch (eventType.ProgrammaticName) {
                    case "InvokePatternIdentifiers.InvokedEvent":
                        this.WriteVerbose(cmdlet, "subscribing to the InvokedEvent handler");
                        Automation.AddAutomationEventHandler(
                            InvokePattern.InvokedEvent,
                            inputObject,
                            TreeScope.Element, // TreeScope.Subtree, // TreeScope.Element,
                            // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent));
                            //uiaEventHandler = new AutomationEventHandler(handler));
                            //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler));
                            uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler));
                        UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler);
                        // 20130327
                        //this.WriteObject(cmdlet, uiaEventHandler);
                        if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); }
                        break;
                    case "TextPatternIdentifiers.TextChangedEvent":
                        this.WriteVerbose(cmdlet, "subscribing to the TextChangedEvent handler");
                        Automation.AddAutomationEventHandler(
                            TextPattern.TextChangedEvent,
                            inputObject,
                            TreeScope.Element,
                            // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent));
                            //uiaEventHandler = new AutomationEventHandler(handler));
                            //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler));
                            uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler));
                        UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler);
                        // 20130327
                        //this.WriteObject(cmdlet, uiaEventHandler);
                        if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); }
                        break;
                    case "TextPatternIdentifiers.TextSelectionChangedEvent":
                        this.WriteVerbose(cmdlet, "subscribing to the TextSelectionChangedEvent handler");
                        Automation.AddAutomationEventHandler(
                            TextPattern.TextSelectionChangedEvent,
                            inputObject,
                            TreeScope.Element,
                            // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent));
                            //uiaEventHandler = new AutomationEventHandler(handler));
                            //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler));
                            uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler));
                        UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler);
                        // 20130327
                        //this.WriteObject(cmdlet, uiaEventHandler);
                        if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); }
                        break;
                    case "WindowPatternIdentifiers.WindowOpenedProperty":
                        this.WriteVerbose(cmdlet, "subscribing to the WindowOpenedEvent handler");
                        Automation.AddAutomationEventHandler(
                            WindowPattern.WindowOpenedEvent,
                            inputObject,
                            TreeScope.Subtree,
                            // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent));
                            //uiaEventHandler = new AutomationEventHandler(handler));
                            //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler));
                            uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler));
                        UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler);
                        // 20130327
                        //this.WriteObject(cmdlet, uiaEventHandler);
                        if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); }
                        break;
                    case "AutomationElementIdentifiers.AutomationPropertyChangedEvent":
                        if (prop != null) {
                            this.WriteVerbose(cmdlet, "subscribing to the AutomationPropertyChangedEvent handler");
                            Automation.AddAutomationPropertyChangedEventHandler(
                                inputObject,
                                TreeScope.Subtree,
                                uiaPropertyChangedEventHandler =
                                    // new AutomationPropertyChangedEventHandler(OnUIAutomationPropertyChangedEvent),
                                    //new AutomationPropertyChangedEventHandler(handler),
//.........这里部分代码省略.........
开发者ID:JosefNemec,项目名称:STUPS,代码行数:101,代码来源:HasControlInputCmdletBase.cs

示例15: GetUpdatedCache

 public AutomationElement GetUpdatedCache(CacheRequest request)
 {
     try
     {
         return AutomationElement.Wrap(this._obj.BuildUpdatedCache(request.NativeCacheRequest));
     }
     catch (System.Runtime.InteropServices.COMException e)
     {
         Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
     }
 }
开发者ID:geeksree,项目名称:cSharpGeeks,代码行数:11,代码来源:AutomationElement.cs


注:本文中的System.Windows.Automation.CacheRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。