public T GetNativePattern <T>(PatternId pattern)
        {
            if (Equals(pattern, PatternId.NotSupportedByFramework))
            {
                throw new NotSupportedByFrameworkException();
            }

            var isCacheActive = CacheRequest.IsCachingActive;

            try
            {
                var nativePattern = this.InternalGetPattern(pattern.Id, isCacheActive);
                if (nativePattern == null)
                {
                    throw new InvalidOperationException("Native pattern is null");
                }

                return((T)nativePattern);
            }
            catch (Exception ex)
            {
                if (isCacheActive)
                {
                    var cacheRequest = CacheRequest.Current;
                    if (!cacheRequest.Patterns.Contains(pattern))
                    {
                        throw new PatternNotCachedException(pattern, ex);
                    }
                }

                throw new PatternNotSupportedException(pattern, ex);
            }
        }
        public bool TryGetNativePattern <T>(PatternId pattern, out T nativePattern)
        {
            nativePattern = default(T);
            if (Equals(pattern, PatternId.NotSupportedByFramework))
            {
                return(false);
            }

            var isCacheActive = CacheRequest.IsCachingActive;

            nativePattern = (T)this.InternalGetPattern(pattern.Id, isCacheActive);
            return(nativePattern != null);
        }
        /// <summary>
        /// Checks if the given pattern is available for the element via properties
        /// </summary>
        public bool IsPatternSupported(PatternId pattern)
        {
            if (Equals(pattern, PatternId.NotSupportedByFramework))
            {
                return(false);
            }

            if (pattern.AvailabilityProperty == null)
            {
                throw new ArgumentException("Pattern doesn't have an AvailabilityProperty");
            }

            var success = this.BasicAutomationElement.TryGetPropertyValue(pattern.AvailabilityProperty, out bool isPatternAvailable);

            return(success && isPatternAvailable);
        }
 public void Add(PatternId pattern)
 {
     this.Patterns.Add(pattern);
 }
Example #5
0
 public AutomationPattern(PatternId patternId, BasicAutomationElementBase basicAutomationElement, Func <BasicAutomationElementBase, TNative, T> patternCreateFunc)
 {
     this.patternId = patternId;
     this.BasicAutomationElement = basicAutomationElement;
     this.patternCreateFunc      = patternCreateFunc;
 }
Example #6
0
 public PatternNotCachedException(string message, PatternId pattern, Exception innerException)
     : base(message, innerException)
 {
     this.Pattern = pattern;
 }
Example #7
0
 public PatternNotCachedException(PatternId pattern, Exception innerException)
     : base(string.Format(DefaultMessageWithData, pattern.Name), innerException)
 {
     this.Pattern = pattern;
 }
 public static bool TryGet(int id, out PatternId patternId)
 {
     return(Cache.TryGetValue(id, out patternId));
 }
 public PatternNotSupportedException(string message, PatternId pattern)
     : base(message)
 {
     this.Pattern = pattern;
 }
 public PatternNotSupportedException(PatternId pattern)
     : base(string.Format(DefaultMessageWithData, pattern.Name))
 {
     this.Pattern = pattern;
 }
 public abstract IAutomationPattern <T> GetCustomPattern <T, TNative>(PatternId pattern, Func <BasicAutomationElementBase, TNative, T> patternCreateFunc)
     where T : IPattern;
 /// <summary>
 /// Checks if the given pattern is available for the element via UIA method.
 /// Does not work with cached elements and might be unreliable.
 /// </summary>
 public bool IsPatternSupportedDirect(PatternId pattern)
 {
     return(this.GetSupportedPatternsDirect().Contains(pattern));
 }