protected void Open()
        {
            bool          exit;
            DateTime      timeout;
            RPAParameters parameters;

            parameters = new RPAParameters();
            timeout    = DateTime.Now.AddSeconds(60);
            exit       = false;
            do
            {
                cartes.reset(notepad.api()); /* "reset" warns Cartes of changes in
                                              * screen applications. Cartes reduces consumption of C.P.U. with
                                              * this notice. The A.I. of Cartes presupposes these opportune
                                              * notices in your source code. */
                if (timeout < DateTime.Now)
                {
                    throw new Exception("Exhausted timeout opening Notepad.");
                }
                else if (notepad.ComponentExist())
                {
                    parameters.clear();
                    parameters.item[0] = "900";
                    parameters.item[1] = "580";
                    notepad.doroot("resize", parameters); // This code is an example to use RPAParameters,
                    // notepad.Root().ReSize(900, 580); because resizing is easier that way.
                    exit = true;
                }
                else
                {
                    cartes.run("notepad.exe");
                    notepad.waitforcomponent(30);
                }
            } while (!exit);
        }
Beispiel #2
0
        protected virtual string WaitForCartesMethodValue(RPAComponent component, string method, int seconds) /* It waits until the indicated method has
                                                                                                               * value and returns it. Once the waiting time has been exceeded, it throws an exception. */
        {
            RPAParameters parameters = new RPAParameters();
            DateTime      timeout;
            string        result;

            try
            {
                timeout = DateTime.Now.AddSeconds(seconds);
                do
                {
                    CheckAbort();
                    cartes.reset(component.api());
                    Thread.Sleep(400);
                    if (timeout < DateTime.Now)
                    {
                        throw new Exception("Timeout");
                    }
                    else
                    {
                        result = ToString(component.Execute(method, parameters));
                    }
                } while (result.Length == 0);
                return(result);
            }
            catch (Exception e)
            {
                forensic("MyCartes::WaitForCartesMethodValue", e);
                throw;
            }
        }
        static void Main()
        {
            DateTime          start;
            RPAParameters     parameters = new RPAParameters();
            IRPAComponent     notepad;
            RPAWin32Component editor;
            String            workingFile, editorRoute;

            try
            {
                start       = DateTime.Now;
                workingFile = Environment.CurrentDirectory;
                cartes.open(workingFile + "\\library\\notepad.rpa");
                editor = cartes.GetComponent <RPAWin32Component>("$NotePadEditor");
                if (editor.ComponentNotExist())
                {
                    cartes.run("notepad.exe");
                    editor.waitforcomponent(30);
                }
                editorRoute        = editor.route();
                notepad            = editor.Root();
                parameters.item[0] = WalkTree(0, notepad, "");
                notepad.dochild(editorRoute, "TypeFromClipboard", parameters);
                editor.focus();
                cartes.balloon("This example has opened the notepad and has presented you the component tree with its structure.");
                cartes.RegisterIteration(start, "ok", "<task>Put your trace here in xml</task>", 1);
                cartes.forensic("This is a trace for the swarm log, and the Windows event viewer.");
                MessageBox.Show("End");
            }
            finally
            {
                cartes.close();
            }
        }
Beispiel #4
0
        protected virtual void scrollDown(int mouseX, int mouseY, RPAWin32Accessibility component)
        {
            RPAParameters parameters = new RPAParameters();
            DateTime      timeout;
            int           n, y;

            try
            {
                parameters.item[0] = mouseX.ToString();
                parameters.item[1] = mouseY.ToString();
                component.focus();
                component.doroot("SetMouse", parameters);
                n       = 0;
                y       = component.y;
                timeout = DateTime.Now.AddSeconds(30);
                while (component.OffScreen == 1)
                {
                    if (timeout < DateTime.Now)
                    {
                        throw new Exception("Timeout waiting by scrolling.");
                    }
                    CheckAbort();
                    cartes.balloon("Scroll...");
                    component.doroot("SetMouse", parameters);
                    component.down();
                    Thread.Sleep(500);
                    if (n > 3)
                    {
                        throw new Exception("I can not scroll down.");
                    }
                    if (y == component.y)
                    {
                        n++;
                    }
                    else
                    {
                        n = 0;
                    }
                }
            }
            catch (Exception e)
            {
                cartes.forensic("MyCartes.scrollDown(RPAWin32Accessibility)\r\n" + e.Message);
                throw;
            }
        }
Beispiel #5
0
        protected virtual void scrollDown(int mouseX, int y, int height, RPAWin32Component component)
        {
            RPAParameters parametros = new RPAParameters();
            DateTime      timeout;

            try
            {
                parametros.item[0] = mouseX.ToString();
                parametros.item[1] = (y + 2).ToString();
                component.focus();
                component.doroot("SetMouse", parametros);
                timeout = DateTime.Now.AddSeconds(20);
                while (component.y < y)
                {
                    if (timeout < DateTime.Now)
                    {
                        throw new Exception("Timeout waiting by scrolling.");
                    }
                    CheckAbort();
                    cartes.balloon("Scroll up...");
                    component.Up();
                    Thread.Sleep(500);
                }
                while (y + height < component.y + component.height)
                {
                    if (timeout < DateTime.Now)
                    {
                        throw new Exception("Timeout waiting by scrolling.");
                    }
                    CheckAbort();
                    cartes.balloon("Scroll down...");
                    component.down();
                    Thread.Sleep(500);
                }
            }
            catch (Exception e)
            {
                cartes.forensic("MyCartes.scrollDown(RPAWin32Component)\r\n" + e.Message);
                throw;
            }
        }
        public static string WalkTree(int level, RPAWin32Component component)
        {
            RPAParameters param  = new RPAParameters();
            string        margin = "";
            string        result = "";

            int i;

            i = 0;
            while (i < level)
            {
                margin = margin + "  ";
                i      = i + 1;
            }
            result = margin + level + " - " + component.name() + " " + "[" + component.Execute("class", param) + "] = " + component.Wrapper();
            i      = 0;
            while (i < component.descendants)
            {
                result = result + "\r\n" + WalkTree(level + 1, (RPAWin32Component)component.child(i));
                i      = i + 1;
            }
            return(result);
        }
        public static string WalkTree(int level, IRPAComponent component, string path)
        {
            RPAParameters param  = new RPAParameters();
            string        margin = "";
            string        result = "";
            int           i;

            cartes.balloon("Component : " + path + "\r\nClass : " + component.dochild(path, "class", param));
            i = 0;
            while (i < level)
            {
                margin = margin + "  ";
                i      = i + 1;
            }
            result = margin + level + " - " + component.dochild(path, "name", param) + " " + "[" + component.dochild(path, "class", param) + "] = " + component.dochild(path, "wrapper", param);
            i      = 0;
            while (i < int.Parse(component.dochild(path, "descendants", param)))
            {
                result = result + "\r\n" + WalkTree(level + 1, component, path + "\\" + i.ToString());
                i      = i + 1;
            }
            return(result);
        }
        static void Main()
        {
            DateTime          start;
            RPAParameters     parameters = new RPAParameters(), output = null;
            RPAWin32Component notepad = null, notepadclose = null, notepadeditor = null,
                              notepadnosave = null, notepaddialog = null;
            String workingFile, language = "eng", imageCloseButton;

            start            = DateTime.Now;
            workingFile      = Environment.CurrentDirectory;
            imageCloseButton = workingFile + "\\closebutton.bmp";
            cartes.open(workingFile + "\\library\\notepad2.rpa");
            try
            {
                notepad       = cartes.GetComponent <RPAWin32Component>("$Notepad");
                notepadclose  = cartes.GetComponent <RPAWin32Component>("$NotepadClose");
                notepadeditor = cartes.GetComponent <RPAWin32Component>("$NotepadEditor");
                notepadnosave = cartes.GetComponent <RPAWin32Component>("$NotepadNoSave");
                notepaddialog = cartes.GetComponent <RPAWin32Component>("$NotepadDialog");
                if (notepadeditor.componentexist(0) == 0)
                {
                    cartes.run("notepad.exe");
                    notepadeditor.waitforcomponent(30);
                }
                notepad.ReSize(890, 600);
                notepad.Move(1, 5);
                notepad.focus();
                notepad.SaveRectPartToFile(notepadclose.x - notepad.x,
                                           notepadclose.y - notepad.y,
                                           notepadclose.width, notepadclose.height,
                                           imageCloseButton);
                parameters.item[0] = imageCloseButton;
                output             = notepad.FindPicture(parameters);
                if (output.item[0] == "1")
                {
                    notepadeditor.TypeFromClipboard("RESULT : " + output.item[0] + "\r\n" +
                                                    "X      : " + output.item[1] + "\r\n" +
                                                    "Y      : " + output.item[2] + "\r\n" +
                                                    "WIDTH  : " + output.item[3] + "\r\n" +
                                                    "HEIGHT : " + output.item[4] + "\r\n" +
                                                    "INDEX  : " + output.item[5] + "\r\n");
                    // I use the OCR directly on the screen with zoom
                    MessageBox.Show(notepadeditor.RecognitionRatio(language, 1.3, 1));
                    // I use the OCR in an image file
                    Thread.Sleep(2000);
                    notepadeditor.focus();
                    notepadeditor.SaveRectToFile(imageCloseButton);
                    cartes.Execute("$OCR = new OCR;\r\n" +
                                   "ShowMessage($OCR.run(\"" + imageCloseButton + "\", \"" + language + "\"));\r\n");
                    // Closing...
                    notepad.clickon(int.Parse(output.item[1]) + int.Parse(output.item[3]) / 2,
                                    int.Parse(output.item[2]) + int.Parse(output.item[4]) / 2, 1); // I use the "ClickOn" function directly with the coordinates
                    Thread.Sleep(1000);
                    cartes.reset(notepadnosave.api());
                    notepadnosave.waitforcomponent(10);
                    notepaddialog.SaveRectPartToFile(notepadnosave.x - notepaddialog.x,
                                                     notepadnosave.y - notepaddialog.y,
                                                     notepadnosave.width, notepadnosave.height,
                                                     imageCloseButton);
                    notepaddialog.ClickOnImage(true, imageCloseButton);
                }
                cartes.RegisterIteration(start, "ok", "<task>Put your trace here in xml for your swarm</task>", 1);
                cartes.forensic("This is a trace for the swarm log, and the Windows event viewer.");
                cartes.balloon("This example has opened the notepad and has shown how to use image recognition and OCR.");
            }
            finally
            {
                cartes.close();
                MessageBox.Show("End");
            }
        }