本文整理汇总了C#中System.Windows.Automation.CacheRequest.Activate方法的典型用法代码示例。如果您正苦于以下问题:C# CacheRequest.Activate方法的具体用法?C# CacheRequest.Activate怎么用?C# CacheRequest.Activate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Automation.CacheRequest
的用法示例。
在下文中一共展示了CacheRequest.Activate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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]);
}
}
示例3: 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);
}
}
示例4: 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);
}
}
}
示例5: 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);
}
}
}
示例6: GetUpdatedAEWhenStructureChanged
public AutomationElement GetUpdatedAEWhenStructureChanged(AutomationElement mainWidow, AutomationPattern patternToCache = null, AutomationProperty propertyToCache = null)
{
CacheRequest cacheRequest = new CacheRequest();
cacheRequest.TreeScope = TreeScope.Element | TreeScope.Descendants | TreeScope.Children;
cacheRequest.AutomationElementMode = AutomationElementMode.Full;
cacheRequest.TreeFilter = System.Windows.Automation.Automation.RawViewCondition;
if (patternToCache != null)
{
cacheRequest.Add(patternToCache);
}
else
{
cacheRequest.Add(SelectionPattern.Pattern);
cacheRequest.Add(WindowPattern.Pattern);
cacheRequest.Add(InvokePattern.Pattern);
cacheRequest.Add(TogglePattern.Pattern);
cacheRequest.Add(ExpandCollapsePattern.Pattern);
cacheRequest.Add(ValuePattern.Pattern);
cacheRequest.Add(SelectionItemPattern.Pattern);
}
if (propertyToCache != null)
{
cacheRequest.Add(propertyToCache);
}
else
{
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(AutomationElement.AutomationIdProperty);
cacheRequest.Add(AutomationElement.ClassNameProperty);
cacheRequest.Add(AutomationElement.ControlTypeProperty);
}
AutomationElement updatedElement;
using (cacheRequest.Activate())
{
updatedElement = mainWidow.GetUpdatedCache(cacheRequest);
}
return updatedElement;
}
示例7: 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);
//.........这里部分代码省略.........
示例8: 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);
}
}
示例9: 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);
}
}
}
示例10: 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);
}
}
}
示例11: 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);
}
}
}
示例12: 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);
}
}
}
示例13: 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);
}
}
示例14: LegacyIAccessiblePatternCachedTest
public void LegacyIAccessiblePatternCachedTest()
{
using (AppHost host = new AppHost("rundll32.exe", "shell32.dll,Control_RunDLL intl.cpl"))
{
CacheRequest req = new CacheRequest();
req.Add(LegacyIAccessiblePattern.Pattern);
req.Add(LegacyIAccessiblePattern.NameProperty);
req.Add(LegacyIAccessiblePattern.ChildIdProperty);
req.Add(LegacyIAccessiblePattern.KeyboardShortcutProperty);
req.Add(LegacyIAccessiblePattern.RoleProperty);
req.Add(LegacyIAccessiblePattern.ValueProperty);
req.Add(LegacyIAccessiblePattern.StateProperty);
req.Add(LegacyIAccessiblePattern.SelectionProperty);
using (req.Activate())
{
// Find a well-known combo box
AutomationElement combo = host.Element.FindFirst(TreeScope.Subtree,
new PropertyCondition(AutomationElement.AutomationIdProperty, "1021"));
Assert.IsNotNull(combo);
// BLOCK
{
LegacyIAccessiblePattern acc = (LegacyIAccessiblePattern)combo.GetCachedPattern(LegacyIAccessiblePattern.Pattern);
Assert.AreEqual(0, acc.Cached.ChildId);
Assert.IsTrue(acc.Cached.Name.Length > 0);
Assert.IsTrue(acc.Cached.Value.Length > 0);
Assert.AreEqual("Alt+f", acc.Cached.KeyboardShortcut);
Assert.AreEqual((uint)0x2E /* combo box */, acc.Cached.Role);
Assert.AreEqual((uint)0x100400 /* collapsed|focusable */, acc.Cached.State & 0x100400);
}
// Get the tab controls
AutomationElement tabCtrl = host.Element.FindFirst(TreeScope.Subtree,
new PropertyCondition(AutomationElement.AutomationIdProperty, "12320"));
Assert.IsNotNull(tabCtrl);
// BLOCK
{
LegacyIAccessiblePattern acc = (LegacyIAccessiblePattern)tabCtrl.GetCachedPattern(LegacyIAccessiblePattern.Pattern);
AutomationElement[] selection = acc.Cached.GetSelection();
Assert.IsTrue(selection.Length > 0);
Assert.IsInstanceOf<AutomationElement>(selection[0]);
Assert.AreEqual(ControlType.TabItem, selection[0].Current.ControlType);
}
}
}
}
示例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);
}
}