CacheRequest 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
AutomationElement 가져올 때 UI 자동화 프레임워크에서 캐시하는 속성과 패턴을 지정합니다.
public ref class CacheRequest sealed
public sealed class CacheRequest
type CacheRequest = class
Public NotInheritable Class CacheRequest
- 상속
-
CacheRequest
예제
다음 예제에서는 패턴 및 속성을 캐시하는 데 사용하는 Activate 방법을 보여 줍니다.
/// <summary>
/// Caches and retrieves properties for a list item by using CacheRequest.Activate.
/// </summary>
/// <param name="elementList">Element from which to retrieve a child element.</param>
/// <remarks>
/// This code demonstrates various aspects of caching. It is not intended to be
/// an example of a useful method.
/// </remarks>
private void CachePropertiesByActivate(AutomationElement elementList)
{
AutomationElement elementListItem;
// Set up the request.
CacheRequest cacheRequest = new CacheRequest();
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(AutomationElement.IsEnabledProperty);
cacheRequest.Add(SelectionItemPattern.Pattern);
cacheRequest.Add(SelectionItemPattern.SelectionContainerProperty);
// Obtain an element and cache the requested items.
using (cacheRequest.Activate())
{
Condition cond = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true);
elementListItem = elementList.FindFirst(TreeScope.Children, cond);
}
// The CacheRequest is now inactive.
// Retrieve the cached property and pattern.
SelectionItemPattern pattern;
String itemName;
try
{
itemName = elementListItem.Cached.Name;
pattern = elementListItem.GetCachedPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
}
catch (InvalidOperationException)
{
Console.WriteLine("Object was not in cache.");
return;
}
// Alternatively, you can use TryGetCachedPattern to retrieve the cached pattern.
object cachedPattern;
if (true == elementListItem.TryGetCachedPattern(SelectionItemPattern.Pattern, out cachedPattern))
{
pattern = cachedPattern as SelectionItemPattern;
}
// Specified pattern properties are also in the cache.
AutomationElement parentList = pattern.Cached.SelectionContainer;
// The following line will raise an exception, because the HelpText property was not cached.
/*** String itemHelp = elementListItem.Cached.HelpText; ***/
// Similarly, pattern properties that were not specified in the CacheRequest cannot be
// retrieved from the cache. This would raise an exception.
/*** bool selected = pattern.Cached.IsSelected; ***/
// This is still a valid call, even though the property is in the cache.
// Of course, the cached value and the current value are not guaranteed to be the same.
itemName = elementListItem.Current.Name;
}
''' <summary>
''' Caches and retrieves properties for a list item by using CacheRequest.Activate.
''' </summary>
''' <param name="elementList">Element from which to retrieve a child element.</param>
''' <remarks>
''' This code demonstrates various aspects of caching. It is not intended to be
''' an example of a useful method.
''' </remarks>
Private Sub CachePropertiesByActivate(ByVal elementList As AutomationElement)
' Set up the request.
Dim myCacheRequest As New CacheRequest()
myCacheRequest.Add(AutomationElement.NameProperty)
myCacheRequest.Add(AutomationElement.IsEnabledProperty)
myCacheRequest.Add(SelectionItemPattern.Pattern)
myCacheRequest.Add(SelectionItemPattern.SelectionContainerProperty)
Dim elementListItem As AutomationElement
' Obtain an element and cache the requested items.
Using myCacheRequest.Activate()
Dim myCondition As New PropertyCondition( _
AutomationElement.IsSelectionItemPatternAvailableProperty, True)
elementListItem = elementList.FindFirst(TreeScope.Children, myCondition)
End Using
' The CacheRequest is now inactive.
' Retrieve the cached property and pattern.
Dim pattern As SelectionItemPattern
Dim itemName As String
Try
itemName = elementListItem.Cached.Name
pattern = DirectCast(elementListItem.GetCachedPattern(SelectionItemPattern.Pattern), _
SelectionItemPattern)
Catch ex As InvalidOperationException
Console.WriteLine("Object was not in cache.")
Return
End Try
' Alternatively, you can use TryGetCachedPattern to retrieve the cached pattern.
Dim cachedPattern As Object = Nothing
If True = elementListItem.TryGetCachedPattern(SelectionItemPattern.Pattern, cachedPattern) Then
pattern = DirectCast(cachedPattern, SelectionItemPattern)
End If
' Specified pattern properties are also in the cache.
Dim parentList As AutomationElement = pattern.Cached.SelectionContainer
' The following line will raise an exception, because the HelpText property was not cached.
'** String itemHelp = elementListItem.Cached.HelpText; **
' Similarly, pattern properties that were not specified in the CacheRequest cannot be
' retrieved from the cache. This would raise an exception.
'** bool selected = pattern.Cached.IsSelected; **
' This is still a valid call, even though the property is in the cache.
' Of course, the cached value and the current value are not guaranteed to be the same.
itemName = elementListItem.Current.Name
End Sub
다음 예제에서는 패턴 및 Pop 속성을 사용하고 Push 캐시하는 방법을 보여 줍니다.
/// <summary>
/// Caches and retrieves properties for a list item by using CacheRequest.Push.
/// </summary>
/// <param name="autoElement">Element from which to retrieve a child element.</param>
/// <remarks>
/// This code demonstrates various aspects of caching. It is not intended to be
/// an example of a useful method.
/// </remarks>
private void CachePropertiesByPush(AutomationElement elementList)
{
// Set up the request.
CacheRequest cacheRequest = new CacheRequest();
// Do not get a full reference to the cached objects, only to their cached properties and patterns.
cacheRequest.AutomationElementMode = AutomationElementMode.None;
// Cache all elements, regardless of whether they are control or content elements.
cacheRequest.TreeFilter = Automation.RawViewCondition;
// Property and pattern to cache.
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(SelectionItemPattern.Pattern);
// Activate the request.
cacheRequest.Push();
// Obtain an element and cache the requested items.
Condition cond = new PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, true);
AutomationElement elementListItem = elementList.FindFirst(TreeScope.Children, cond);
// At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
// While that method was retrieving automation elements, the CacheRequest set in this method
// would not be active.
// Deactivate the request.
cacheRequest.Pop();
// Retrieve the cached property and pattern.
String itemName = elementListItem.Cached.Name;
SelectionItemPattern pattern = elementListItem.GetCachedPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
// The following is an alternative way of retrieving the Name property.
itemName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty) as String;
// This is yet another way, which returns AutomationElement.NotSupported if the element does
// not supply a value. If the second parameter is false, a default name is returned.
object objName = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, true);
if (objName == AutomationElement.NotSupported)
{
itemName = "Unknown";
}
else
{
itemName = objName as String;
}
// The following call raises an exception, because only the cached properties are available,
// as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
// default value (Full), this call would be valid.
/*** bool enabled = elementListItem.Current.IsEnabled; ***/
}
''' <summary>
''' Caches and retrieves properties for a list item by using CacheRequest.Push.
''' </summary>
''' <param name="elementList">Element from which to retrieve a child element.</param>
''' <remarks>
''' This code demonstrates various aspects of caching. It is not intended to be
''' an example of a useful method.
''' </remarks>
Private Sub CachePropertiesByPush(ByVal elementList As AutomationElement)
' Set up the request.
Dim cacheRequest As New CacheRequest()
' Do not get a full reference to the cached objects, only to their cached properties and patterns.
cacheRequest.AutomationElementMode = AutomationElementMode.None
' Cache all elements, regardless of whether they are control or content elements.
cacheRequest.TreeFilter = Automation.RawViewCondition
' Property and pattern to cache.
cacheRequest.Add(AutomationElement.NameProperty)
cacheRequest.Add(SelectionItemPattern.Pattern)
' Activate the request.
cacheRequest.Push()
' Obtain an element and cache the requested items.
Dim myCondition As New PropertyCondition(AutomationElement.IsSelectionItemPatternAvailableProperty, _
True)
Dim elementListItem As AutomationElement = elementList.FindFirst(TreeScope.Children, myCondition)
' At this point, you could call another method that creates a CacheRequest and calls Push/Pop.
' While that method was retrieving automation elements, the CacheRequest set in this method
' would not be active.
' Deactivate the request.
cacheRequest.Pop()
' Retrieve the cached property and pattern.
Dim itemName As String = elementListItem.Cached.Name
Dim pattern As SelectionItemPattern = _
DirectCast(elementListItem.GetCachedPattern(SelectionItemPattern.Pattern), SelectionItemPattern)
' The following is an alternative way of retrieving the Name property.
itemName = CStr(elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty))
' This is yet another way, which returns AutomationElement.NotSupported if the element does
' not supply a value. If the second parameter is false, a default name is returned.
Dim objName As Object = elementListItem.GetCachedPropertyValue(AutomationElement.NameProperty, True)
If objName Is AutomationElement.NotSupported Then
itemName = "Unknown"
Else
itemName = CStr(objName)
End If
' The following call raises an exception, because only the cached properties are available,
' as specified by cacheRequest.AutomationElementMode. If AutomationElementMode had its
' default value (Full), this call would be valid.
'** bool enabled = elementListItem.Current.IsEnabled; **
End Sub
설명
UI 자동화 통해 속성 및 패턴을 검색하려면 성능 저하를 줄 수 있는 프로세스 간 호출이 필요합니다. 일괄 처리 작업에서 속성 및 패턴 값을 캐싱하면 애플리케이션의 성능을 향상시킬 수 있습니다.
클래스 생성자를 호출하여 새 캐시 요청을 만듭니다. 요청은 메서드에 대한 반복 호출로 Add 채워집니다.
한 CacheRequest 개만 활성화할 수 있습니다. 요청을 활성화하는 방법에는 두 가지가 있습니다.
요청을 호출 Activate 합니다. 이렇게 하면 요청이 스택으로 푸시되고 개체가 삭제될 때 요청이 표시됩니다. 예외가 발생하더라도 삭제하려면
using블록 내의 Activate 반환 값(Visual BasicUsing)을 사용합니다.를 호출 Push하여 내부 스택에 요청을 배치합니다. 스택의 맨 위 요청만 활성 상태이며 다음 요청은 다음 요청이 스택 Pop에서 제거되어야 합니다. 요청을 표시하면 비활성화됩니다.
요청이 활성화된 동안 가져온 UI 자동화 요소에는 지정된 속성 및 패턴에 대한 캐시된 값이 있습니다.
생성자
| Name | Description |
|---|---|
| CacheRequest() |
CacheRequest 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| AutomationElementMode |
반환된 요소에 기본 UI(사용자 인터페이스)에 대한 전체 참조를 포함할지 캐시된 정보만 포함할지 여부를 지정하는 값을 가져오거나 설정합니다. |
| Current |
현재 스레드에서 CacheRequest 활성 상태인 해당 스레드를 가져옵니다. |
| TreeFilter |
캐싱할 때 사용할 UI 자동화 요소 트리의 뷰를 지정하는 값을 가져오거나 설정합니다. |
| TreeScope |
하위 트리의 루트 또는 자식 또는 하위 항목에 대해서만 캐싱이 수행되는지 여부를 지정하는 값을 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| Activate() |
동일한 CacheRequest 스레드에서 요청된 경우 AutomationElement 반환되는 항목에 대한 활성 사양으로 설정합니다. |
| Add(AutomationPattern) |
지정된 AutomationPattern 식별자를 이 CacheRequest식별자에 추가합니다. |
| Add(AutomationProperty) |
지정된 AutomationProperty 식별자를 이 CacheRequest식별자에 추가합니다. |
| Clone() |
이 CacheRequest복사본을 만듭니다. |
| Equals(Object) |
지정한 개체와 현재 개체가 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetHashCode() |
기본 해시 함수로 작동합니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| Pop() |
현재 스레드의 내부 스택에서 활성 CacheRequest 을 제거합니다. |
| Push() |
CacheRequest 내부 상태 스택을 배치하여 현재 스레드에서 활성 요청으로 만듭니다. |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
적용 대상
추가 정보
- UI 자동화 클라이언트에서 캐싱
UI 자동화