Esempio n. 1
0
        public static void AddToCache(AutomationElement root, int ident, string Conditions, AutomationElement[] Result)
        {
            if (!PluginConfig.enable_cache)
            {
                return;
            }
            MatchCacheItem result = null;

            try
            {
                lock (cache_lock) result = MatchCache.Where(x => x.Conditions == Conditions && x.Ident == ident && x.Root.Equals(root)).FirstOrDefault();
            }
            catch (Exception)
            {
            }
            if (result != null)
            {
                result.Result  = Result;
                result.Created = DateTime.Now;
                return;
            }
            result = new MatchCacheItem()
            {
                Conditions = Conditions, Created = DateTime.Now, Root = root, Ident = ident, Result = Result
            };
            lock (cache_lock) MatchCache.Add(result);
        }
Esempio n. 2
0
        public void RemoveFromCache(MatchCacheItem item)
        {
            var items = MatchCache.Where(x => x.Root.Equals(item.Root) && x.Ident >= item.Ident).ToList();

            foreach (var e in items)
            {
                MatchCache.Remove(e);
            }
            MatchCache.Remove(item);
        }
Esempio n. 3
0
        public static void AddToCache(AutomationElement root, int ident, string Conditions, AutomationElement[] Result)
        {
            if (!PluginConfig.enable_cache)
            {
                return;
            }
            MatchCacheItem result = null;

            try
            {
                if (System.Threading.Monitor.TryEnter(cache_lock, 1000))
                {
                    try
                    {
                        result = MatchCache.Where(x => x.Conditions == Conditions && x.Ident == ident && x.Root.Equals(root)).FirstOrDefault();
                    }
                    finally
                    {
                        System.Threading.Monitor.Exit(cache_lock);
                    }
                }
            }
            catch (Exception)
            {
            }
            if (result != null)
            {
                result.Result  = Result;
                result.Created = DateTime.Now;
                return;
            }
            result = new MatchCacheItem()
            {
                Conditions = Conditions, Created = DateTime.Now, Root = root, Ident = ident, Result = Result
            };
            if (System.Threading.Monitor.TryEnter(cache_lock, 1000))
            {
                try
                {
                    MatchCache.Add(result);
                }
                finally
                {
                    System.Threading.Monitor.Exit(cache_lock);
                }
            }
        }
Esempio n. 4
0
 public static void RemoveFromCache(MatchCacheItem item)
 {
     try
     {
         lock (cache_lock)
         {
             var items = MatchCache.Where(x => x.Root.Equals(item.Root) && x.Ident >= item.Ident).ToList();
             foreach (var e in items)
             {
                 MatchCache.Remove(e);
             }
         }
     }
     catch (Exception)
     {
     }
     lock (cache_lock) MatchCache.Remove(item);
 }
Esempio n. 5
0
 public static void RemoveFromCache(MatchCacheItem item, bool remove_related)
 {
     try
     {
         if (remove_related)
         {
             if (System.Threading.Monitor.TryEnter(cache_lock, 1000))
             {
                 try
                 {
                     var items = MatchCache.Where(x => x.Root.Equals(item.Root) && x.Ident >= item.Ident).ToList();
                     foreach (var e in items)
                     {
                         MatchCache.Remove(e);
                     }
                 }
                 finally
                 {
                     System.Threading.Monitor.Exit(cache_lock);
                 }
             }
         }
     }
     catch (Exception)
     {
     }
     if (System.Threading.Monitor.TryEnter(cache_lock, 1000))
     {
         try
         {
             MatchCache.Remove(item);
         }
         finally
         {
             System.Threading.Monitor.Exit(cache_lock);
         }
     }
 }
Esempio n. 6
0
        public static AutomationElement[] GetFromCache(AutomationElement root, int ident, string Conditions)
        {
            if (!PluginConfig.enable_cache)
            {
                return(null);
            }
            var            now     = DateTime.Now;
            var            timeout = PluginConfig.cache_timeout;
            MatchCacheItem result  = null;

            MatchCacheItem[] _list = null;
            lock (cache_lock) _list = MatchCache.ToArray();
            try
            {
                for (var i = _list.Length - 1; i >= 0; i--)
                {
                    try
                    {
                        if (now - _list[i].Created > timeout)
                        {
                            RemoveFromCache(_list[i]);
                        }
                        if (_list[i].Conditions == Conditions && _list[i].Root.Equals(root) && _list[i].Ident == ident)
                        {
                            result = _list[i];
                        }
                    }
                    catch (Exception)
                    {
                        RemoveFromCache(_list[i]);
                    }
                }
            }
            catch (Exception)
            {
            }
            if (result != null)
            {
                try
                {
                    foreach (var e in result.Result)
                    {
                        // _ = e.Parent;
                        if (!e.IsAvailable)
                        {
                            RemoveFromCache(result);
                            return(null);
                        }
                        else if (!e.Properties.BoundingRectangle.IsSupported || e.Properties.BoundingRectangle.Value == System.Drawing.Rectangle.Empty)
                        {
                            RemoveFromCache(result);
                            return(null);
                        }
                        //else if ((e.ControlType == FlaUI.Core.Definitions.ControlType.Button ||
                        //    e.ControlType == FlaUI.Core.Definitions.ControlType.CheckBox ||
                        //    e.ControlType == FlaUI.Core.Definitions.ControlType.ComboBox ||
                        //    e.ControlType == FlaUI.Core.Definitions.ControlType.Text ||
                        //    e.ControlType == FlaUI.Core.Definitions.ControlType.RadioButton
                        //    ) &&e.IsOffscreen)
                        //{
                        //    RemoveFromCache(result);
                        //    return null;
                        //}
                    }
                }
                catch (Exception)
                {
                    RemoveFromCache(result);
                }
                return(result.Result);
            }
            return(null);
        }