本文整理汇总了C#中System.Windows.Automation.CacheRequest.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CacheRequest.Add方法的具体用法?C# CacheRequest.Add怎么用?C# CacheRequest.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Automation.CacheRequest
的用法示例。
在下文中一共展示了CacheRequest.Add方法的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]);
}
}
示例2: 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);
}
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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);
}
}
}
示例6: 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);
}
}
示例7: 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),
//.........这里部分代码省略.........
示例8: GetCachedPatternTest
public void GetCachedPatternTest()
{
CacheRequest req = new CacheRequest();
req.Add(InvokePatternIdentifiers.Pattern);
using (req.Activate())
{
InvokePattern pattern = (InvokePattern)GetStartButton().GetCachedPattern(InvokePatternIdentifiers.Pattern);
Assert.IsNotNull(pattern);
}
}
示例9: DoWork
public void DoWork()
{
long timeToGetUncached = 0;
long timeToGetCached = 0;
// Create a System.Diagnostics.Stopwatch.
var stopWatchTimer = new Stopwatch();
// TEST 1: Get the target element without caching, and retrieve
// current properties.
stopWatchTimer.Start();
AutomationElement targetNoCache = null;
try
{
targetNoCache = AutomationElement.FromPoint(_targetPoint);
}
catch (ElementNotAvailableException)
{
OutputLine("Could not retrieve element.");
return;
}
// Get current properties.
_currentPropCount = 0;
GetCurrentProperties(targetNoCache, 0);
stopWatchTimer.Stop();
timeToGetUncached = stopWatchTimer.Elapsed.Ticks;
// TEST 2: Get the target element with caching, and retrieve
// cached properties.
// Create CacheRequest.
var fetchRequest = new CacheRequest();
// Add properties to fetch.
fetchRequest.Add(AutomationElement.NameProperty);
fetchRequest.Add(AutomationElement.AutomationIdProperty);
fetchRequest.Add(AutomationElement.ControlTypeProperty);
fetchRequest.Add(AutomationElement.FrameworkIdProperty);
fetchRequest.Add(AutomationElement.IsContentElementProperty);
// Set options.
fetchRequest.AutomationElementMode = _mode;
fetchRequest.TreeScope = _treeScope;
fetchRequest.TreeFilter = Automation.RawViewCondition;
// Activate the CacheRequest and fetch the target.
AutomationElement targetCached = null;
using (fetchRequest.Activate())
{
stopWatchTimer.Reset();
stopWatchTimer.Start();
try
{
targetCached = AutomationElement.FromPoint(_targetPoint);
}
catch (InvalidOperationException)
{
OutputLine("InvalidOperationException. Could not retrieve element.");
return;
}
catch (ElementNotAvailableException)
{
OutputLine("ElementNotAvailableException. Could not retrieve element.");
return;
}
} // CacheRequest is now inactive.
// Get cached properties.
GetCachedProperties(targetCached, true);
stopWatchTimer.Stop();
timeToGetCached = stopWatchTimer.Elapsed.Ticks;
// TEST 3: Get updated cache.
stopWatchTimer.Reset();
stopWatchTimer.Start();
var cacheUpdated = false;
if (_mode == AutomationElementMode.Full)
{
var updatedTargetCached = targetCached.GetUpdatedCache(fetchRequest);
GetCachedProperties(updatedTargetCached, false);
// Fetches were counted again, so divide count by 2.
_cachedPropCount /= 2;
cacheUpdated = true;
stopWatchTimer.Stop();
}
var updateTicks = stopWatchTimer.Elapsed.Ticks;
// END OF TESTS.
// Display results
var nameProperty = targetNoCache.Current.Name;
var framework = targetNoCache.Current.FrameworkId;
OutputLine("Name: " + nameProperty);
OutputLine("Framework: " + framework);
//.........这里部分代码省略.........
示例10: RangeValuePatternCachedTest
public void RangeValuePatternCachedTest()
{
using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL main.cpl ,2"))
{
CacheRequest req = new CacheRequest();
req.Add(RangeValuePattern.Pattern);
req.Add(RangeValuePattern.IsReadOnlyProperty);
req.Add(RangeValuePattern.MaximumProperty);
req.Add(RangeValuePattern.MinimumProperty);
req.Add(RangeValuePattern.SmallChangeProperty);
req.Add(RangeValuePattern.LargeChangeProperty);
using (req.Activate())
{
// Find a well-known slider
AutomationElement slider = host.Element.FindFirst(TreeScope.Subtree,
new PropertyCondition(AutomationElement.AutomationIdProperty, "101"));
Assert.IsNotNull(slider);
RangeValuePattern range = (RangeValuePattern)slider.GetCachedPattern(RangeValuePattern.Pattern);
double originalValue = range.Cached.Value;
Assert.IsTrue(range.Cached.SmallChange >= 0);
Assert.IsTrue(range.Cached.LargeChange >= 0);
Assert.IsTrue(originalValue >= range.Cached.Minimum);
Assert.IsTrue(originalValue <= range.Cached.Maximum);
Assert.IsFalse(range.Cached.IsReadOnly);
}
}
}
示例11: WindowPatternCachedTest
public void WindowPatternCachedTest()
{
using (AppHost host = new AppHost("notepad.exe", ""))
{
CacheRequest req = new CacheRequest();
req.Add(WindowPattern.Pattern);
req.Add(WindowPattern.CanMaximizeProperty);
req.Add(WindowPattern.CanMinimizeProperty);
req.Add(WindowPattern.IsTopmostProperty);
req.Add(WindowPattern.WindowInteractionStateProperty);
req.Add(WindowPattern.WindowVisualStateProperty);
using (req.Activate())
{
AutomationElement cachedEl = host.Element.GetUpdatedCache(req);
// Window Pattern
WindowPattern windowPattern = (WindowPattern)cachedEl.GetCachedPattern(WindowPattern.Pattern);
Assert.IsTrue(windowPattern.Cached.CanMaximize);
Assert.IsTrue(windowPattern.Cached.CanMinimize);
Assert.IsFalse(windowPattern.Cached.IsTopmost);
Assert.AreNotEqual(windowPattern.Cached.WindowVisualState, WindowVisualState.Minimized);
Assert.AreNotEqual(windowPattern.Cached.WindowInteractionState, WindowInteractionState.Closing);
}
}
}
示例12: ValuePatternCachedTest
public void ValuePatternCachedTest()
{
using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL intl.cpl"))
{
CacheRequest req = new CacheRequest();
req.Add(WindowPattern.Pattern);
req.Add(WindowPattern.CanMaximizeProperty);
req.Add(WindowPattern.CanMinimizeProperty);
req.Add(WindowPattern.IsTopmostProperty);
req.Add(WindowPattern.WindowInteractionStateProperty);
req.Add(WindowPattern.WindowVisualStateProperty);
using (req.Activate())
{
// Find a well-known combo box
AutomationElement combo = host.Element.FindFirst(TreeScope.Subtree,
new PropertyCondition(AutomationElement.AutomationIdProperty, "1021"));
Assert.IsNotNull(combo);
ValuePattern value = (ValuePattern)combo.GetCurrentPattern(ValuePattern.Pattern);
Assert.IsFalse(value.Current.IsReadOnly);
Assert.IsTrue(value.Current.Value.Length > 0);
}
}
}
示例13: TransformPatternCachedTest
public void TransformPatternCachedTest()
{
using (AppHost host = new AppHost("notepad.exe", ""))
{
CacheRequest req = new CacheRequest();
req.Add(TransformPattern.Pattern);
req.Add(TransformPattern.CanMoveProperty);
req.Add(TransformPattern.CanResizeProperty);
req.Add(TransformPattern.CanRotateProperty);
using (req.Activate())
{
AutomationElement cachedEl = host.Element.GetUpdatedCache(req);
TransformPattern transformPattern = (TransformPattern)cachedEl.GetCachedPattern(TransformPattern.Pattern);
// Coded to expectations for an explorer window
Assert.IsTrue(transformPattern.Cached.CanMove);
Assert.IsTrue(transformPattern.Cached.CanResize);
Assert.IsFalse(transformPattern.Cached.CanRotate);
// Little move
transformPattern.Move(10, 10);
// Little resize
transformPattern.Resize(200, 200);
}
}
}
示例14: TogglePatternCachedTest
public void TogglePatternCachedTest()
{
using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL main.cpl"))
{
CacheRequest req = new CacheRequest();
req.Add(TogglePattern.Pattern);
req.Add(TogglePattern.ToggleStateProperty);
using (req.Activate())
{
// Find a well-known checkbox
AutomationElement checkbox = host.Element.FindFirst(TreeScope.Subtree,
new PropertyCondition(AutomationElement.AutomationIdProperty, "114"));
Assert.IsNotNull(checkbox);
TogglePattern toggle = (TogglePattern)checkbox.GetCachedPattern(TogglePattern.Pattern);
ToggleState originalState = toggle.Cached.ToggleState;
Assert.IsTrue(originalState == ToggleState.On || originalState == ToggleState.Off);
}
}
}
示例15: MultipleViewPatternTest
public void MultipleViewPatternTest()
{
CacheRequest req = new CacheRequest();
req.Add(MultipleViewPattern.Pattern);
req.Add(MultipleViewPattern.CurrentViewProperty);
req.Add(MultipleViewPattern.SupportedViewsProperty);
using (req.Activate())
{
AutomationElement itemsView = ExplorerTargetTests.explorerHost.Element.FindFirst(TreeScope.Subtree,
new PropertyCondition(AutomationElement.ClassNameProperty, "UIItemsView"));
Assert.IsNotNull(itemsView);
MultipleViewPattern multiView = (MultipleViewPattern)itemsView.GetCachedPattern(MultipleViewPattern.Pattern);
int[] supportedViews = multiView.Cached.GetSupportedViews();
Assert.IsNotNull(supportedViews.Length > 0);
bool inSupportedViews = false;
foreach (int view in supportedViews)
{
if (view == multiView.Cached.CurrentView)
{
inSupportedViews = true;
break;
}
string viewName = multiView.GetViewName(view);
Assert.IsTrue(viewName.Length > 0);
}
Assert.IsTrue(inSupportedViews);
}
}