Esempio n. 1
0
        private async 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");
            Rectangle match   = await GetBaseRectangle();

            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));
            await rect.Highlight(false, System.Drawing.Color.PaleGreen, TimeSpan.FromSeconds(1));

            Interfaces.GenericTools.Restore();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string script = ModelItem.GetValue <string>("Script");
            var    f      = new Editor();

            f.highlightingComboBox.Visibility = Visibility.Hidden;
            f.textEditor.Text = script;
            f.textEditor.SyntaxHighlighting = null;
            f.ShowDialog();
            if (f.textEditor.Text != script)
            {
                ModelItem.Properties["Script"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(f.textEditor.Text)
                });
            }
        }
Esempio n. 3
0
        private async void ProcessLimit_Click(object sender, RoutedEventArgs e)
        {
            var Processname = ModelItem.GetValue <string>("Processname");
            var p           = System.Diagnostics.Process.GetProcessesByName(Processname).FirstOrDefault();

            if (p == null)
            {
                return;
            }

            var allChildWindows = new WindowHandleInfo(p.MainWindowHandle).GetAllChildHandles();

            allChildWindows.Add(p.MainWindowHandle);
            var       template   = new Rectangle(0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
            Rectangle windowrect = Rectangle.Empty;

            foreach (var window in allChildWindows)
            {
                WindowHandleInfo.RECT rct;
                if (!WindowHandleInfo.GetWindowRect(new HandleRef(this, window), out rct))
                {
                    continue;
                }
                var _rect = new Rectangle(rct.Left, rct.Top, rct.Right - rct.Left + 1, rct.Bottom - rct.Top + 1);
                if (_rect.Width < template.Width && _rect.Height < template.Height)
                {
                    continue;
                }
                if ((_rect.X > 0 || (_rect.X + _rect.Width) > 0) &&
                    (_rect.Y > 0 || (_rect.Y + _rect.Height) > 0))
                {
                    windowrect = _rect;
                    continue;
                }
            }

            Interfaces.GenericTools.minimize(Interfaces.GenericTools.mainWindow);
            var rect = await getrectangle.GetitAsync();

            var limit = new System.Drawing.Rectangle(rect.X - (int)windowrect.X, rect.Y - (int)windowrect.Y, rect.Width, rect.Height);

            ModelItem.Properties["Limit"].SetValue(new System.Activities.InArgument <System.Drawing.Rectangle>(limit));
            Interfaces.GenericTools.restore();
            NotifyPropertyChanged("Limit");
        }
Esempio n. 4
0
        private async void Highlight_Click(object sender, RoutedEventArgs e)
        {
            ModelItem  loadFrom = ModelItem.Parent;
            string     loadFromSelectorString = "";
            NMSelector anchor = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Selector").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    anchor = new NMSelector(loadFromSelectorString);
                    break;
                }
                loadFrom = loadFrom.Parent;
            }


            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresults     = ModelItem.GetValue <int>("MaxResults");
            var    selector       = new NMSelector(SelectorString);
            // var elements = NMSelector.GetElementsWithuiSelector(selector, anchor, maxresults);
            var elements = new List <NMElement>();

            if (anchor != null)
            {
                var _base = NMSelector.GetElementsWithuiSelector(anchor, null, 10);
                foreach (var _e in _base)
                {
                    var res = NMSelector.GetElementsWithuiSelector(selector, _e, maxresults);
                    elements.AddRange(res);
                }
            }
            else
            {
                var res = NMSelector.GetElementsWithuiSelector(selector, null, maxresults);
                elements.AddRange(res);
            }

            foreach (var ele in elements)
            {
                await ele.Highlight(false, System.Drawing.Color.Red, TimeSpan.FromSeconds(1));
            }
        }
Esempio n. 5
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var curAccount = ModelItem.GetValue <string>("Account");
         Accounts.Clear();
         var outlookApplication = CreateOutlookInstance();
         for (int i = 1; i <= outlookApplication.Session.Accounts.Count; i++)
         {
             Accounts.Add(outlookApplication.Session.Accounts[i]);
         }
         ModelItem.SetValueInArg("Account", curAccount);
     }
     catch (System.Exception ex)
     {
         Log.Error(ex.ToString());
     }
 }
        private async void ComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            try
            {
                string workflow = ModelItem.GetValue <string>("workflow");
                string target   = ModelItem.GetValue <string>("target");
                if (oldworkflow == workflow && oldtarget == target)
                {
                    return;
                }
                oldworkflow = workflow; oldtarget = target;
                if (string.IsNullOrEmpty(target))
                {
                    loadLocalWorkflows(); return;
                }
                if (target != originaltarget)
                {
                    workflows.Clear();
                    workflows.Add(new Workflow()
                    {
                        name = "Loading...", _id = "loading"
                    });
                    ModelItem.Properties["workflow"].SetValue("loading");
                }
                // var _workflows = await global.webSocketClient.Query<Workflow>("openrpa", "{_type: 'workflow'}", "{'name':1, 'projectandname': 1}", orderby: "{projectid:-1,name:-1}", queryas: target);
                var _workflows = await global.webSocketClient.Query <Workflow>("openrpa", "{_type: 'workflow'}", queryas : target, top : 5000);

                _workflows = _workflows.OrderBy(x => x.ProjectAndName).ToArray();
                workflows.Clear();
                foreach (var w in _workflows)
                {
                    workflows.Add(w);
                }
                var currentworkflow = ModelItem.GetValue <string>("workflow");
                if (workflow != currentworkflow && !string.IsNullOrEmpty(currentworkflow))
                {
                    ModelItem.Properties["workflow"].SetValue(workflow);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string Script = ModelItem.GetValue <string>("Script");

            if (Script == null)
            {
                Script = "";                 // so we don't overwrite if a variable has been used
            }
            var f = new Editor(Script);

            f.ShowDialog();
            if (f.textEditor.Text != Script)
            {
                ModelItem.Properties["Script"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(f.textEditor.Text)
                });
            }
        }
Esempio n. 8
0
        private void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
        {
            var ec           = ModelItemExtensions.GetEditingContext(ModelItem);
            var modelService = ec.Services.GetService <System.Activities.Presentation.Services.ModelService>();
            ModelItemCollection importsModelItem = modelService.Root.Properties["Imports"].Collection;
            var namespaces = new List <string>();

            foreach (ModelItem import in importsModelItem)
            {
                namespaces.Add(import.Properties["Namespace"].ComputedValue as string);
            }
            if (!namespaces.Contains("System.Collections"))
            {
                namespaces.Add("System.Collections");
            }
            if (!namespaces.Contains("System.Collections.Generic"))
            {
                namespaces.Add("System.Collections.Generic");
            }


            string[] current = ModelItem.GetValue <string[]>("namespaces");
            if (current == null || namespaces.Count() != current.Count())
            {
                ModelItem.Properties["namespaces"].SetValue(namespaces.ToArray());
            }
            else
            {
                bool changed = false;
                for (var i = 0; i < namespaces.Count(); i++)
                {
                    if (namespaces[i] != current[i])
                    {
                        changed = true;
                    }
                }
                if (changed)
                {
                    ModelItem.Properties["namespaces"].SetValue(namespaces.ToArray());
                }
            }
        }
Esempio n. 9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary;
            var options = new System.Activities.Presentation.DynamicArgumentDesignerOptions()
            {
                Title = ModelItem.GetValue <string>("DisplayName")
            };

            using (ModelEditingScope modelEditingScope = dictionary.BeginEdit())
            {
                if (System.Activities.Presentation.DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options))
                {
                    modelEditingScope.Complete();
                }
                else
                {
                    modelEditingScope.Revert();
                }
            }
        }
Esempio n. 10
0
 public void Reload()
 {
     try
     {
         var curfolder = ModelItem.GetValue <string>("Folder");
         folders.Clear();
         var        outlookApplication = CreateOutlookInstance();
         MAPIFolder inBox      = (MAPIFolder)outlookApplication.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
         MAPIFolder folderbase = inBox.Store.GetRootFolder();
         foreach (MAPIFolder folder in folderbase.Folders)
         {
             GetFolders(folder, 0);
         }
         ModelItem.SetValueInArg("Folder", curfolder);
     }
     catch (System.Exception ex)
     {
         Log.Error(ex.ToString());
     }
 }
        private async void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                originalworkflow = ModelItem.GetValue <string>("workflow");
                originaltarget   = ModelItem.GetValue <string>("target");
                //if (string.IsNullOrEmpty(originalworkflow)) throw new ArgumentException("ModelItem.workflow is null");
                //if (string.IsNullOrEmpty(originaltarget)) throw new ArgumentException("ModelItem.target is null");
                // loadLocalWorkflows();
                var _users = await global.webSocketClient.Query <apiuser>("users", "{\"$or\":[ {\"_type\": \"user\"}, {\"_type\": \"role\", \"rparole\": true} ]}", top : 5000);

                foreach (var u in _users)
                {
                    robots.Add(u);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
        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)
                });
            }
        }
Esempio n. 13
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var ec           = ModelItemExtensions.GetEditingContext(ModelItem);
            var modelService = ec.Services.GetService <System.Activities.Presentation.Services.ModelService>();
            ModelItemCollection importsModelItem = modelService.Root.Properties["Imports"].Collection;
            var namespaces = new List <string>();

            foreach (ModelItem import in importsModelItem)
            {
                namespaces.Add(import.Properties["Namespace"].ComputedValue as string);
            }

            var    vars     = FindVariablesInScope(ModelItem);
            string code     = ModelItem.GetValue <string>("Code");
            string language = ModelItem.GetValue <string>("Language");

            if (string.IsNullOrEmpty(language))
            {
                language = "VB";
            }
            var f = new Editor(code, language, vars, namespaces.ToArray());

            f.textEditor.SyntaxHighlighting = f.Languages.Where(x => x.Name == language).FirstOrDefault();
            f.ShowDialog();
            if (f.textEditor.Text != code)
            {
                ModelItem.Properties["Code"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(f.textEditor.Text)
                });
            }
            if (f.textEditor.SyntaxHighlighting.Name != language)
            {
                ModelItem.Properties["Language"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(f.textEditor.SyntaxHighlighting.Name)
                });
            }
        }
        private async void Highlight_Click(object sender, RoutedEventArgs e)
        {
            Rectangle match = await GetBaseRectangle();

            var X      = ModelItem.GetValue <int>("X");
            var Y      = ModelItem.GetValue <int>("Y");
            var Width  = ModelItem.GetValue <int>("Width");
            var Height = ModelItem.GetValue <int>("Height");

            if (match.IsEmpty)
            {
                match = new Rectangle(0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
            }
            var _hi = new ImageElement(match);

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

            var rect = new ImageElement(new Rectangle(_hi.X + X, _hi.Y + Y, Width, Height));
            await rect.Highlight(false, System.Drawing.Color.PaleGreen, TimeSpan.FromSeconds(1));

            Interfaces.GenericTools.Restore();
        }
Esempio n. 15
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string workflowid = ModelItem.GetValue <string>("workflow");
         if (string.IsNullOrEmpty(workflowid))
         {
             throw new ArgumentException("workflow property is null");
         }
         var workflow = RobotInstance.instance.GetWorkflowByIDOrRelativeFilename(workflowid);
         var designer = RobotInstance.instance.Window.Designer;
         if (string.IsNullOrEmpty(workflowid))
         {
             throw new ArgumentException("workflow is null, not found");
         }
         if (string.IsNullOrEmpty(workflowid))
         {
             throw new ArgumentException("designer is null, cannot find current designer");
         }
         foreach (var p in workflow.Parameters)
         {
             Type t = Type.GetType(p.type);
             if (p.type == "System.Data.DataTable")
             {
                 t = typeof(System.Data.DataTable);
             }
             if (t == null)
             {
                 throw new ArgumentException("Failed resolving type '" + p.type + "'");
             }
             Log.Information("Checking for variable " + p.name + " of type " + p.type);
             designer.GetVariable(p.name, t);
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
 }
Esempio n. 16
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string PropertyName = "Payload";
            DynamicArgumentDesignerOptions options1 = new DynamicArgumentDesignerOptions();

            options1.Title = ModelItem.GetValue <string>("DisplayName");
            DynamicArgumentDesignerOptions options = options1;

            if (!ModelItem.Properties[PropertyName].IsSet)
            {
                Log.Warning(PropertyName + " is not set");
                return;
            }
            ModelItem collection = ModelItem.Properties[PropertyName].Collection;

            if (collection == null)
            {
                collection = ModelItem.Properties[PropertyName].Dictionary;
            }
            if (collection == null)
            {
                Log.Warning(PropertyName + " is not a Collection or Dictionary");
                return;
            }
            using (ModelEditingScope scope = collection.BeginEdit(PropertyName + "Editing"))
            {
                if (DynamicArgumentDialog.ShowDialog(ModelItem, collection, ModelItem.GetEditingContext(), ModelItem.View, options))
                {
                    scope.Complete();
                }
                else
                {
                    scope.Revert();
                }
            }
        }
        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);
        }
Esempio n. 18
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Config = new termVB5250Config();

            bool as400 = false;

            if (as400)
            {
                Config.Hostname = "PUB400.COM";
                Config.Port     = 23;
                Config.TermType = "IBM-3278-2";
            }
            else
            {
                Config.Hostname = "localhost";
                Config.Port     = 3270;
                Config.TermType = "IBM-3179-2";
            }

            var body    = ModelItem.Properties["Body"].Value;
            var handler = body.Properties["Handler"].Value;

            global.OpenRPAClient.CurrentDesigner.SelectedActivity = handler;
            //body.Focus(20);
            //handler.Focus(20);

            string Hostname = ModelItem.GetValue <string>("Hostname");
            string TermType = ModelItem.GetValue <string>("TermType");
            int    Port     = ModelItem.GetValue <int>("Port");
            bool   UseSSL   = ModelItem.GetValue <bool>("UseSSL");

            if (!string.IsNullOrEmpty(Hostname))
            {
                Config.Hostname = Hostname;
            }
            if (!string.IsNullOrEmpty(TermType))
            {
                Config.TermType = TermType;
            }
            if (Port > 0)
            {
                Config.Port = Port;
            }
            Config.UseSSL = UseSSL;

            TerminalRecorder win = null;

            if (string.IsNullOrEmpty(Hostname) && string.IsNullOrEmpty(TermType))
            {
                win        = new TerminalRecorder();
                win.Config = Config;
                RunPlugin.Sessions.Add(win);
            }
            else
            {
                win = RunPlugin.GetRecorderWindow(Config);
            }
            sessionid = Guid.NewGuid().ToString();
            if (string.IsNullOrEmpty(win.WorkflowInstanceId))
            {
                win.WorkflowInstanceId = sessionid;
            }
            win.Show();
            //win.ShowDialog();
            win.Focus();
            win.Closed += Win_Closed;
        }
Esempio n. 19
0
        private void Open_Selector(object sender, RoutedEventArgs e)
        {
            ModelItem  loadFrom = ModelItem.Parent;
            string     loadFromSelectorString = "";
            NMSelector anchor = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Selector").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    anchor = new NMSelector(loadFromSelectorString);
                    break;
                }
                loadFrom = loadFrom.Parent;
            }
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresults     = ModelItem.GetValue <int>("MaxResults");

            Interfaces.Selector.SelectorWindow selectors;
            if (!string.IsNullOrEmpty(SelectorString))
            {
                var selector = new NMSelector(SelectorString);
                selectors = new Interfaces.Selector.SelectorWindow("NM", selector, anchor, maxresults);
            }
            else
            {
                var selector = new NMSelector("[{Selector: 'NM'}]");
                selectors = new Interfaces.Selector.SelectorWindow("NM", selector, anchor, maxresults);
            }
            selectors.Owner = GenericTools.MainWindow;
            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
                var l = selectors.vm.Selector.Last();
                if (l.Element != null)
                {
                    ModelItem.Properties["Image"].SetValue(l.Element.ImageString());
                    NotifyPropertyChanged("Image");
                }
                if (anchor != null)
                {
                    ModelItem.Properties["From"].SetValue(new InArgument <NMElement>()
                    {
                        Expression = new Microsoft.VisualBasic.Activities.VisualBasicValue <NMElement>("item")
                    });
                    ModelItem.Properties["MinResults"].SetValue(new InArgument <int>()
                    {
                        Expression = new Microsoft.VisualBasic.Activities.VisualBasicValue <int>("0")
                    });
                    ModelItem.Properties["Timeout"].SetValue(new InArgument <TimeSpan>()
                    {
                        Expression = new Microsoft.VisualBasic.Activities.VisualBasicValue <TimeSpan>("TimeSpan.FromSeconds(0)")
                    });
                }
            }
        }
Esempio n. 20
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)
                        });
                    }
                }
            }
        }
Esempio n. 21
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)
                        });
                    }
                }
            }
        }
Esempio n. 22
0
        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            string workflowid = ModelItem.GetValue <string>("workflow");
            ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary;

            if (!string.IsNullOrEmpty(workflowid))
            {
                var workflow = RobotInstance.instance.GetWorkflowByIDOrRelativeFilename(workflowid);
                var designer = RobotInstance.instance.Window.Designer;
                if (workflow != null)
                {
                    try
                    {
                        workflow.ParseParameters();
                    }
                    catch (Exception)
                    {
                        workflow = null;
                    }
                }
                if (workflow != null)
                {
                    foreach (var p in workflow.Parameters)
                    {
                        bool exists = false;
                        foreach (var key in dictionary.Keys)
                        {
                            if (key.ToString() == p.name)
                            {
                                exists = true;
                            }
                            if (key.GetValue <string>("AnnotationText") == p.name)
                            {
                                exists = true;
                            }
                            if (key.GetValue <string>("Name") == p.name)
                            {
                                exists = true;
                            }
                        }
                        if (!exists)
                        {
                            Type t = OpenRPA.Interfaces.Extensions.FindType(p.type);
                            if (p.type == "System.Data.DataTable")
                            {
                                t = typeof(System.Data.DataTable);
                            }
                            if (t == null)
                            {
                                throw new ArgumentException("Failed resolving type '" + p.type + "'");
                            }
                            Argument a = null;
                            if (p.direction == workflowparameterdirection.@in)
                            {
                                a = Argument.Create(t, ArgumentDirection.In);
                            }
                            if (p.direction == workflowparameterdirection.inout)
                            {
                                a = Argument.Create(t, ArgumentDirection.InOut);
                            }
                            if (p.direction == workflowparameterdirection.@out)
                            {
                                a = Argument.Create(t, ArgumentDirection.Out);
                            }
                            // a.GetType().GetProperties().Where(x => x.Name == "Expression").Last().SetValue(a, o);
                            //a.Expression = o as VisualBasicValue<>;
                            dictionary.Add(p.name, a);
                        }
                    }
                    foreach (var a in dictionary.ToList())
                    {
                        bool exists = workflow.Parameters.Where(x => x.name == a.Key.ToString()).Count() > 0;
                        if (!exists)
                        {
                            dictionary.Remove(a.Key);
                        }
                    }
                }
            }
            var options = new System.Activities.Presentation.DynamicArgumentDesignerOptions()
            {
                Title = ModelItem.GetValue <string>("DisplayName")
            };

            using (ModelEditingScope modelEditingScope = dictionary.BeginEdit())
            {
                if (System.Activities.Presentation.DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options))
                {
                    modelEditingScope.Complete();
                }
                else
                {
                    modelEditingScope.Revert();
                }
            }
        }
Esempio n. 23
0
        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            if (ModelItem.Properties["workflow"].Value == null)
            {
                return;
            }
            string workflowid = ModelItem.GetValue <string>("workflow");

            if (string.IsNullOrEmpty(workflowid))
            {
                throw new ArgumentException("workflow property is null");
            }
            var workflow = RobotInstance.instance.GetWorkflowByIDOrRelativeFilename(workflowid);
            var designer = RobotInstance.instance.Window.Designer;

            if (workflow == null)
            {
                throw new ArgumentException("workflow is null, not found");
            }
            if (designer == null)
            {
                throw new ArgumentException("designer is null, cannot find current designer");
            }
            ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary;

            try
            {
                workflow.ParseParameters();
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                MessageBox.Show("Failed mapping arguments" + Environment.NewLine + ex.Message);
            }
            foreach (var p in workflow.Parameters)
            {
                bool exists = false;
                foreach (var key in dictionary.Keys)
                {
                    if (key.ToString() == p.name)
                    {
                        exists = true;
                    }
                    if (key.GetValue <string>("AnnotationText") == p.name)
                    {
                        exists = true;
                    }
                    if (key.GetValue <string>("Name") == p.name)
                    {
                        exists = true;
                    }
                }
                if (!exists)
                {
                    Type t = OpenRPA.Interfaces.Extensions.FindType(p.type);
                    if (p.type == "System.Data.DataTable")
                    {
                        t = typeof(System.Data.DataTable);
                    }
                    if (t == null)
                    {
                        throw new ArgumentException("Failed resolving type '" + p.type + "'");
                    }

                    //Type atype = typeof(VisualBasicValue<>);
                    //Type constructed = atype.MakeGenericType(t);
                    //object o = Activator.CreateInstance(constructed, p.name);

                    //Log.Information("Checking for variable " + p.name + " of type " + p.type);
                    //designer.GetVariable(p.name, t);

                    Argument a = null;
                    if (p.direction == workflowparameterdirection.@in)
                    {
                        a = Argument.Create(t, ArgumentDirection.In);
                    }
                    if (p.direction == workflowparameterdirection.inout)
                    {
                        a = Argument.Create(t, ArgumentDirection.InOut);
                    }
                    if (p.direction == workflowparameterdirection.@out)
                    {
                        a = Argument.Create(t, ArgumentDirection.Out);
                    }
                    // a.GetType().GetProperties().Where(x => x.Name == "Expression").Last().SetValue(a, o);
                    //a.Expression = o as VisualBasicValue<>;
                    dictionary.Add(p.name, a);
                }
            }
            foreach (var a in dictionary.ToList())
            {
                bool exists = workflow.Parameters.Where(x => x.name == a.Key.ToString()).Count() > 0;
                if (!exists)
                {
                    dictionary.Remove(a.Key);
                }
            }

            var options = new System.Activities.Presentation.DynamicArgumentDesignerOptions()
            {
                Title = "Map Arguments"
            };

            using (ModelEditingScope modelEditingScope = dictionary.BeginEdit())
            {
                if (System.Activities.Presentation.DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options))
                {
                    modelEditingScope.Complete();
                }
                else
                {
                    modelEditingScope.Revert();
                }
            }
        }
Esempio n. 24
0
        private void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (RobotInstance.instance == null)
                {
                    throw new ArgumentException("RobotInstance.instance");
                }
                if (RobotInstance.instance.Projects == null)
                {
                    throw new ArgumentException("RobotInstance.instance.Projects");
                }
                if (RobotInstance.instance.Projects.Count() == 0)
                {
                    throw new ArgumentException("RobotInstance.instance.Projects.Count == 0");
                }
                var       result   = new List <Workflow>();
                var       designer = RobotInstance.instance.Window.Designer;
                var       workflow = ModelItem.GetValue <string>("workflow");
                IWorkflow selected = null;
                if (!string.IsNullOrEmpty(workflow))
                {
                    var workflow2 = workflow.Replace("\\", "/");
                    if (workflow != workflow2)
                    {
                        ModelItem.SetValueInArg("workflow", workflow2);
                    }
                }
                foreach (var w in RobotInstance.instance.Workflows)
                {
                    if (designer != null && designer.Workflow != null)
                    {
                        if (designer.Workflow._id != w._id || w._id == null)
                        {
                            result.Add(w as Workflow);
                        }
                        if (w._id == workflow)
                        {
                            selected = w;
                        }
                        if (w.RelativeFilename == workflow)
                        {
                            selected = w;
                        }
                        // if (w.ProjectAndName == workflow) selected = w;
                    }
                    else
                    {
                        result.Add(w as Workflow);
                    }
                }
                if (selected != null && selected.ProjectAndName != workflow)
                {
                    ModelItem.SetValueInArg("workflow", selected.ProjectAndName);
                }
                // result = result.OrderBy(x => x.name).OrderBy(x => x.Project.name).ToList();
                result = result.OrderBy(x => x.name).OrderBy(x => x.projectid).ToList();
                if (!string.IsNullOrEmpty(workflow))
                {
                    var exists = result.Where(x => x.RelativeFilename == workflow || x.ProjectAndName == workflow).ToList();
                }

                foreach (var w in result)
                {
                    workflows.Add(w);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
Esempio n. 25
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));
        }
        private void Highlight_Click(object sender, RoutedEventArgs e)
        {
            ModelItem   loadFrom = ModelItem.Parent;
            string      loadFromSelectorString = "";
            SAPSelector anchor = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Selector").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    anchor = new SAPSelector(loadFromSelectorString);
                    break;
                }
                loadFrom = loadFrom.Parent;
            }

            HighlightImage = Interfaces.Extensions.GetImageSourceFromResource("search.png");
            NotifyPropertyChanged("HighlightImage");
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresults     = ModelItem.GetValue <int>("MaxResults");

            if (maxresults < 1)
            {
                maxresults = 1;
            }
            var selector = new SAPSelector(SelectorString);

            var elements = new List <SAPElement>();

            if (anchor != null)
            {
                var _base = SAPSelector.GetElementsWithuiSelector(anchor, null, 0, 10, false);
                foreach (var _e in _base)
                {
                    var res = SAPSelector.GetElementsWithuiSelector(selector, _e, 0, maxresults, false);
                    elements.AddRange(res);
                }
            }
            else
            {
                var res = SAPSelector.GetElementsWithuiSelector(selector, null, 0, maxresults, false);
                elements.AddRange(res);
            }
            if (elements.Count() > maxresults && maxresults > 0)
            {
                elements = elements.ToList().Take(maxresults).ToList();
            }
            if (elements.Count() > 0)
            {
                HighlightImage = Interfaces.Extensions.GetImageSourceFromResource("check.png");
            }
            else
            {
                HighlightImage = Interfaces.Extensions.GetImageSourceFromResource(".x.png");
            }
            NotifyPropertyChanged("HighlightImage");
            foreach (var ele in elements)
            {
                ele.Highlight(false, System.Drawing.Color.Red, TimeSpan.FromSeconds(1));
            }
        }
Esempio n. 27
0
 private void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
 {
     search.Text = ModelItem.GetValue <string>("Name");
     //NotifyPropertyChanged("Name");
 }
Esempio n. 28
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();
        }