CacheRequest CacheRequest CacheRequest CacheRequest Class

정의

AutomationElement를 가져올 때 UI Automation 프레임워크에서 캐시하는 속성 및 패턴을 지정합니다.Specifies properties and patterns that the UI Automation framework caches when an AutomationElement is obtained.

public ref class CacheRequest sealed
public sealed class CacheRequest
type CacheRequest = class
Public NotInheritable Class CacheRequest
상속
CacheRequestCacheRequestCacheRequestCacheRequest

예제

다음 예제에서는 사용 하는 방법을 보여 줍니다 Activate 캐시 패턴 및 속성입니다.The following example shows how to use Activate to cache patterns and properties.

/// <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

다음 예제에서는 사용 하는 방법을 보여 줍니다 PushPop 캐시 패턴 및 속성입니다.The following example shows how to use Push and Pop to cache patterns and properties.

/// <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 자동화UI Automation 성능이 느려질 수는 크로스 프로세스 호출 해야 합니다.Retrieving properties and patterns through UI 자동화UI Automation requires cross-process calls that can slow down performance. 속성 값 및 일괄 처리 작업의 패턴을 캐시 하 여 애플리케이션의 성능을 향상 시킬 수 있습니다.By caching values of proprieties and patterns in a batch operation, you can enhance the performance of your application.

클래스 생성자를 호출 하 여 새 캐시 요청을 만듭니다.Create a new cache request by calling the class constructor. 요청에 대 한 반복된 호출 하 여 채워집니다는 Add 메서드.The request is populated by repeated calls to the Add method.

단일 CacheRequest 활성화 될 수 있습니다.Only a single CacheRequest can be active. 두 가지 방법으로 요청을 활성화 하려면:There are two ways to activate a request:

  • 호출 Activate 를 요청 합니다.Call Activate on the request. 스택에 요청 푸시하고 개체가 삭제 되 면 요청이 팝 됩니다.This pushes the request onto the stack, and the request is popped when the object is disposed. 예외가 발생 하는 경우에 삭제 되도록의 반환 값을 사용 하 여 Activate 내에서 using 블록 (Using Visual Basic에서).To ensure disposal even if an exception is raised, use the return value from Activate within a using block (Using in Visual Basic).

  • 호출 하 여 내부 스택에 요청이 배치 Push합니다.Put the request onto the internal stack by calling Push. 스택의 맨 위에 있는 요청 활성화 되며, 그 다음 누적 기준에서 제거 해야만 Pop합니다.Only the topmost request on the stack is active, and it must be the next one removed from the stack by Pop. 비활성화 요청 팝 됩니다.Popping the request deactivates it.

UI 자동화UI Automation 요청이 활성 상태인 동안 가져온 요소 속성 및 지정 된 패턴에 대 한 값은 캐싱되어 있습니다.elements obtained while the request is active will have cached values for the properties and patterns specified.

생성자

CacheRequest() CacheRequest() CacheRequest() CacheRequest()

CacheRequest 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the CacheRequest class.

속성

AutomationElementMode AutomationElementMode AutomationElementMode AutomationElementMode

반환된 요소에 내부 UI(사용자 인터페이스)user interface (UI)에 대한 전체 참조가 포함될지 아니면 캐시된 정보만 포함될지를 지정하는 값을 가져오거나 설정합니다.Gets or sets a value that specifies whether returned elements should contain full references to the underlying UI(사용자 인터페이스)user interface (UI), or only cached information.

Current Current Current Current

현재 스레드에서 활성화된 CacheRequest입니다.Gets the CacheRequest that is active on the current thread.

TreeFilter TreeFilter TreeFilter TreeFilter

캐싱 시 사용할 UI 자동화UI Automation 요소 트리의 뷰를 지정하는 값을 가져오거나 설정합니다.Gets or sets a value specifying the view of the UI 자동화UI Automation element tree to use when caching.

TreeScope TreeScope TreeScope TreeScope

하위 트리의 루트만 캐시할지 아니면 해당 자식이나 하위 항목도 캐시할지를 지정하는 값을 가져오거나 설정합니다.Gets or sets a value that specifies whether caching is done only for the root of the subtree, or also for its children or descendants.

메서드

Activate() Activate() Activate() Activate()

같은 스레드에서 CacheRequest를 요청할 때 이 AutomationElement를 반환되는 항목에 대한 활성 사양으로 설정합니다.Sets this CacheRequest as the active specification for the items that are returned when an AutomationElement is requested on the same thread.

Add(AutomationPattern) Add(AutomationPattern) Add(AutomationPattern) Add(AutomationPattern)

지정된 AutomationPattern 식별자를 이 CacheRequest에 추가합니다.Adds the specified AutomationPattern identifier to this CacheRequest.

Add(AutomationProperty) Add(AutomationProperty) Add(AutomationProperty) Add(AutomationProperty)

지정된 AutomationProperty 식별자를 이 CacheRequest에 추가합니다.Adds the specified AutomationProperty identifier to this CacheRequest.

Clone() Clone() Clone() Clone()

CacheRequest의 복사본을 만듭니다.Creates a copy of this CacheRequest.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
Pop() Pop() Pop() Pop()

현재 스레드의 내부 스택에서 활성 CacheRequest를 제거합니다.Removes the active CacheRequest from the internal stack for the current thread.

Push() Push() Push() Push()

CacheRequest를 내부 상태 스택에 놓아 현재 스레드의 활성 요청으로 만듭니다.Places the CacheRequest on the internal state stack, making it the active request on the current thread.

ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보