예제 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            var selectorstring = Selector.Get(context);
            var selector       = new Interfaces.Selector.Selector(selectorstring);
            var pluginname     = selector.First().Selector;
            var Plugin         = Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
            var timeout        = Timeout.Get(context);

            Plugin.LaunchBySelector(selector, timeout);
        }
예제 #2
0
        protected override void Execute(CodeActivityContext context)
        {
            var selectorstring = Selector.Get(context);

            selectorstring = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selectorstring, context.DataContext);
            var selector   = new Interfaces.Selector.Selector(selectorstring);
            var pluginname = selector.First().Selector;
            var Plugin     = Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
            var timeout    = Timeout.Get(context);
            var force      = Force.Get(context);

            Plugin.CloseBySelector(selector, timeout, force);
        }
예제 #3
0
        private async void Highlight_Click(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresults     = 1;
            var    selector       = new Interfaces.Selector.Selector(SelectorString);

            var pluginname = selector.First().Selector;
            var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();

            var elements = Plugin.GetElementsWithSelector(selector, null, maxresults);

            foreach (var ele in elements)
            {
                await ele.Highlight(false, System.Drawing.Color.Red, TimeSpan.FromSeconds(1));
            }
        }
예제 #4
0
        protected override void StartLoop(NativeActivityContext context)
        {
            var selectorstring = Selector.Get(context);

            selectorstring = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selectorstring, context.DataContext);
            var selector     = new Interfaces.Selector.Selector(selectorstring);
            var checkrunning = CheckRunning.Get(context);

            checkrunning = true;
            var pluginname = selector.First().Selector;
            var Plugin     = Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
            var timeout    = Timeout.Get(context);
            var element    = Plugin.LaunchBySelector(selector, checkrunning, timeout);

            Result.Set(context, element);
            _element.Set(context, element);
            if (element != null && element is UIElement ui && Body == null)
            {
                //var window = ((UIElement)element).GetWindow();
                var x           = X.Get(context);
                var y           = Y.Get(context);
                var width       = Width.Get(context);
                var height      = Height.Get(context);
                var animatemove = AnimateMove.Get(context);
                if ((width == 0 && height == 0) || (x == 0 && y == 0))
                {
                }
                else
                {
                    if (animatemove)
                    {
                        ui.MoveWindowTo(x, y, width, height);
                    }
                    if (!animatemove)
                    {
                        ui.SetWindowSize(width, height);
                        ui.SetWindowPosition(x, y);
                    }
                }
            }
            if (element != null && Body != null)
            {
                IncIndex(context);
                SetTotal(context, 1);
                context.ScheduleAction(Body, element, OnBodyComplete);
            }
        }
        private void Open_Selector(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresult      = 1;

            if (string.IsNullOrEmpty(SelectorString))
            {
                SelectorString = "[{Selector: 'Windows'}]";
            }
            var selector   = new Interfaces.Selector.Selector(SelectorString);
            var pluginname = selector.First().Selector;
            var selectors  = new Interfaces.Selector.SelectorWindow(pluginname, selector, maxresult);

            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
            }
        }
        private async Task <Rectangle> GetBaseRectangle()
        {
            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            var pp = ModelItem.Properties["Element"];

            if (pp.IsSet)
            {
                while (loadFrom.Parent != null)
                {
                    var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                    if (p != null)
                    {
                        loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                        break;
                    }
                    if (loadFrom.ItemType == typeof(GetText))
                    {
                        gettext = loadFrom;
                    }
                    loadFrom = loadFrom.Parent;
                }
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
                match = element.Rectangle;
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    match = await getrectangle.GetitAsync();

                    tip.Close();
                    tip = null;
                }
            }
            else if (match.IsEmpty)
            {
                var image = loadFrom.GetValue <string>("Image");
                if (!string.IsNullOrEmpty(image))
                {
                    Bitmap b = Task.Run(() => {
                        return(Interfaces.Image.Util.LoadBitmap(image));
                    }).Result;
                    using (b)
                    {
                        var Threshold   = loadFrom.GetValue <double>("Threshold");
                        var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                        var Processname = loadFrom.GetValue <string>("Processname");
                        var limit       = loadFrom.GetValue <Rectangle>("Limit");
                        if (Threshold < 0.5)
                        {
                            Threshold = 0.8;
                        }

                        Interfaces.GenericTools.Minimize(Interfaces.GenericTools.MainWindow);
                        System.Threading.Thread.Sleep(100);
                        var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                        if (matches.Count() == 0)
                        {
                            Interfaces.GenericTools.Restore();
                            return(Rectangle.Empty);
                        }
                        match = matches[0];
                    }
                }
            }

            return(match);
        }
예제 #7
0
        private void Open_Selector(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresult      = 1;

            if (string.IsNullOrEmpty(SelectorString))
            {
                SelectorString = "[{Selector: 'Windows'}]";
            }
            var selector   = new Interfaces.Selector.Selector(SelectorString);
            var pluginname = selector.First().Selector;
            var selectors  = new Interfaces.Selector.SelectorWindow(pluginname, selector, maxresult);

            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
                var Plugin = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var _base  = Plugin.GetElementsWithSelector(selector, null, 10);
                if (_base == null || _base.Length == 0)
                {
                    return;
                }
                var ele = _base[0];
                if (ele != null && !(ele is UIElement))
                {
                    var automation = AutomationUtil.getAutomation();
                    var p          = new System.Drawing.Point(ele.Rectangle.X + 10, ele.Rectangle.Y + 10);
                    if (p.X > 0 && p.Y > 0)
                    {
                        var _temp = automation.FromPoint(p);
                        if (_temp != null)
                        {
                            ele = new UIElement(_temp);
                        }
                    }
                }
                if (ele is UIElement ui)
                {
                    var window = ui.GetWindow();
                    if (window == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(window.Name))
                    {
                        ModelItem.Properties["DisplayName"].SetValue(window.Name);
                    }
                    if (window.Properties.BoundingRectangle.IsSupported)
                    {
                        var bound = window.BoundingRectangle;
                        ModelItem.Properties["X"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.X)
                        });
                        ModelItem.Properties["Y"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Y)
                        });
                        ModelItem.Properties["Width"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Width)
                        });
                        ModelItem.Properties["Height"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Height)
                        });
                    }
                }
            }
        }
예제 #8
0
        private async void btn_Select(object sender, RoutedEventArgs e)
        {
            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    break;
                }
                if (loadFrom.ItemType == typeof(GetText))
                {
                    gettext = loadFrom;
                }
                loadFrom = loadFrom.Parent;
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    match = await getrectangle.GetitAsync();

                    tip.Close();
                    tip = null;
                }
            }
            else
            {
                var Image       = loadFrom.GetValue <string>("Image");
                var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
                var b           = new System.Drawing.Bitmap(stream);
                var Threshold   = loadFrom.GetValue <double>("Threshold");
                var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                var Processname = loadFrom.GetValue <string>("Processname");
                var limit       = loadFrom.GetValue <Rectangle>("Limit");
                if (Threshold < 0.5)
                {
                    Threshold = 0.8;
                }

                Interfaces.GenericTools.minimize(Interfaces.GenericTools.mainWindow);
                System.Threading.Thread.Sleep(100);
                var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                if (matches.Count() == 0)
                {
                    Interfaces.GenericTools.restore();
                    return;
                }
                match = matches[0];
            }

            Rectangle rect = Rectangle.Empty;

            using (Interfaces.Overlay.OverlayWindow _overlayWindow = new Interfaces.Overlay.OverlayWindow(true))
            {
                _overlayWindow.BackColor = System.Drawing.Color.Blue;
                _overlayWindow.Visible   = true;
                _overlayWindow.Bounds    = match;
                _overlayWindow.TopMost   = true;

                var tip = new Interfaces.Overlay.TooltipWindow("Select relative area to capture");
                rect = await getrectangle.GetitAsync();

                tip.Close();
                tip = null;
            }

            ModelItem.Properties["OffsetX"].SetValue(new System.Activities.InArgument <int>(rect.X - match.X));
            ModelItem.Properties["OffsetY"].SetValue(new System.Activities.InArgument <int>(rect.Y - match.Y));
            ModelItem.Properties["Width"].SetValue(new System.Activities.InArgument <int>(rect.Width));
            ModelItem.Properties["Height"].SetValue(new System.Activities.InArgument <int>(rect.Height));
            Interfaces.GenericTools.restore();
        }
예제 #9
0
        private void Highlight_Click(object sender, RoutedEventArgs e)
        {
            var OffsetX = ModelItem.GetValue <int>("OffsetX");
            var OffsetY = ModelItem.GetValue <int>("OffsetY");
            var Width   = ModelItem.GetValue <int>("Width");
            var Height  = ModelItem.GetValue <int>("Height");

            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    break;
                }
                if (loadFrom.ItemType == typeof(GetText))
                {
                    gettext = loadFrom;
                }
                loadFrom = loadFrom.Parent;
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    return;
                    //var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    //match = await getrectangle.GetitAsync();
                    //tip.Close();
                    //tip = null;
                }
            }
            else
            {
                var Image       = loadFrom.GetValue <string>("Image");
                var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
                var b           = new System.Drawing.Bitmap(stream);
                var Threshold   = loadFrom.GetValue <double>("Threshold");
                var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                var Processname = loadFrom.GetValue <string>("Processname");
                var limit       = loadFrom.GetValue <Rectangle>("Limit");
                if (Threshold < 0.5)
                {
                    Threshold = 0.8;
                }

                // Interfaces.GenericTools.minimize(Interfaces.GenericTools.mainWindow);
                System.Threading.Thread.Sleep(100);
                var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                if (matches.Count() == 0)
                {
                    Interfaces.GenericTools.restore();
                    return;
                }
                match = matches[0];
            }

            var _hi = new ImageElement(match);

            _hi.Highlight(false, System.Drawing.Color.Blue, TimeSpan.FromSeconds(1));

            var rect = new ImageElement(new Rectangle(_hi.X + OffsetX, _hi.Y + OffsetY, Width, Height));

            rect.Highlight(false, System.Drawing.Color.PaleGreen, TimeSpan.FromSeconds(1));
        }
예제 #10
0
        protected override void StartLoop(NativeActivityContext context)
        {
            var selectorstring = Selector.Get(context);

            selectorstring = OpenRPA.Interfaces.Selector.Selector.ReplaceVariables(selectorstring, context.DataContext);
            var selector     = new Interfaces.Selector.Selector(selectorstring);
            var checkrunning = CheckRunning.Get(context);

            checkrunning = true;
            var pluginname = selector.First().Selector;
            var Plugin     = Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
            var timeout    = Timeout.Get(context);

            if (Timeout == null || Timeout.Expression == null)
            {
                timeout = TimeSpan.FromSeconds(3);
            }
            var element = Plugin.LaunchBySelector(selector, checkrunning, timeout);

            Result.Set(context, element);
            _element.Set(context, element);
            if (element != null && element is UIElement ui && Body == null)
            {
                //var window = ((UIElement)element).GetWindow();
                var screen      = Screen.Get(context);
                var x           = X.Get(context);
                var y           = Y.Get(context);
                var width       = Width.Get(context);
                var height      = Height.Get(context);
                var animatemove = AnimateMove.Get(context);
                // if ((width == 0 && height == 0) || (x == 0 && y == 0))
                if (width <= 30 || height <= 10)
                {
                }
                else
                {
                    var allScreens = System.Windows.Forms.Screen.AllScreens.ToList();
                    if (screen < 0)
                    {
                        Log.Warning("screen cannot be below 0, using screen 0");
                        screen = 0;
                    }
                    if (screen >= allScreens.Count)
                    {
                        Log.Warning("screen " + screen + " does not exists, using " + (allScreens.Count - 1) + " instead");
                        screen = allScreens.Count - 1;
                    }
                    x += allScreens[screen].WorkingArea.X;
                    y += allScreens[screen].WorkingArea.Y;
                    if (animatemove)
                    {
                        ui.MoveWindowTo(x, y, width, height);
                    }
                    if (!animatemove)
                    {
                        ui.SetWindowSize(width, height);
                        ui.SetWindowPosition(x, y);
                    }
                }
            }
            if (element != null && Body != null)
            {
                IncIndex(context);
                SetTotal(context, 1);
                context.ScheduleAction(Body, element, OnBodyComplete);
            }
        }
예제 #11
0
        private void Open_Selector(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresult      = 1;

            if (string.IsNullOrEmpty(SelectorString))
            {
                SelectorString = "[{Selector: 'Windows'}]";
            }
            var selector   = new Interfaces.Selector.Selector(SelectorString);
            var pluginname = selector.First().Selector;
            var selectors  = new Interfaces.Selector.SelectorWindow(pluginname, selector, maxresult);

            // selectors.Owner = GenericTools.MainWindow;  -- Locks up and never returns ?
            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
                var Plugin = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var _base  = Plugin.GetElementsWithSelector(selector, null, 10);
                if (_base == null || _base.Length == 0)
                {
                    return;
                }
                var ele = _base[0];
                if (ele != null && !(ele is UIElement))
                {
                    var automation = AutomationUtil.getAutomation();
                    var p          = new System.Drawing.Point(ele.Rectangle.X + 10, ele.Rectangle.Y + 10);
                    if (p.X > 0 && p.Y > 0)
                    {
                        var _temp = automation.FromPoint(p);
                        if (_temp != null)
                        {
                            ele = new UIElement(_temp);
                        }
                    }
                }
                if (ele is UIElement ui)
                {
                    var window = ui.GetWindow();
                    if (window == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(window.Name))
                    {
                        ModelItem.Properties["DisplayName"].SetValue(window.Name);
                    }
                    if (window.Properties.BoundingRectangle.IsSupported)
                    {
                        var bound      = window.BoundingRectangle;
                        var newbound   = new System.Drawing.Rectangle(bound.X, bound.Y, bound.Width, bound.Height);
                        var p          = new System.Drawing.Point(bound.X, bound.Y);
                        var allScreens = System.Windows.Forms.Screen.AllScreens.ToList();
                        int screen     = 0;
                        for (var i = 0; i < allScreens.Count; i++)
                        {
                            var work = allScreens[i].WorkingArea;
                            if (work.Contains(bound) || allScreens[i].WorkingArea.Contains(p))
                            {
                                screen     = i;
                                newbound.X = newbound.X - work.X;
                                newbound.Y = newbound.Y - work.Y;
                                break;
                            }
                        }
                        ModelItem.Properties["Screen"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(screen)
                        });
                        ModelItem.Properties["X"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.X)
                        });
                        ModelItem.Properties["Y"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Y)
                        });
                        ModelItem.Properties["Width"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Width)
                        });
                        ModelItem.Properties["Height"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Height)
                        });
                    }
                }
            }
        }