Example #1
0
 private static void OnMouseDown(InputEventArgs e)
 {
     try
     {
         if (SAPHook.Instance.Connections.Count() == 0)
         {
             return;
         }
         if (SAPHook.Instance.UIElements.Count() == 0)
         {
             return;
         }
         var Element = System.Windows.Automation.AutomationElement.FromPoint(new System.Windows.Point(e.X, e.Y));
         if (Element != null)
         {
             var ProcessId = Element.Current.ProcessId;
             if (ProcessId < 1)
             {
                 return;
             }
             if (SAPProcessId > 0 && SAPProcessId != ProcessId)
             {
                 return;
             }
             if (SAPProcessId != ProcessId)
             {
                 var p = System.Diagnostics.Process.GetProcessById(ProcessId);
                 if (p.ProcessName.ToLower() == "saplogon")
                 {
                     SAPProcessId = p.Id;
                 }
                 if (p.ProcessName.ToLower() != "saplogon")
                 {
                     return;
                 }
             }
             LastElement = Element;
             SAPEventElement[] elements = new SAPEventElement[] { };
             lock (SAPHook.Instance.UIElements)
             {
                 elements = SAPHook.Instance.UIElements.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
             }
             if (elements.Count() > 0)
             {
                 var      last    = elements.OrderBy(x => x.Id.Length).Last();
                 SAPEvent message = new SAPEvent("mousedown");
                 message.Set(last);
                 form.AddText("[send] " + message.action + " " + last.Id);
                 pipe.PushMessage(message);
             }
             else
             {
                 log("OnMouseDown " + e.X + "," + e.Y + " not found in UI List");
             }
         }
     }
     catch (Exception)
     {
     }
 }
Example #2
0
        private void GetUIElements(List <SAPEventElement> list, GuiSession session, string Parent, GuiComponent Element)
        {
            var msg = new SAPEventElement(Element, session.Info.SystemName, Parent, false);

            list.Add(msg);
            if (Element.ContainerType)
            {
                if (Element is GuiVContainer vcon)
                {
                    for (var i = 0; i < vcon.Children.Count; i++)
                    {
                        GetUIElements(list, session, Element.Id, vcon.Children.ElementAt(i));
                    }
                }
                else if (Element is GuiContainer con)
                {
                    for (var i = 0; i < con.Children.Count; i++)
                    {
                        GetUIElements(list, session, Element.Id, con.Children.ElementAt(i));
                    }
                }
                else if (Element is GuiStatusbar sbar)
                {
                    for (var i = 0; i < sbar.Children.Count; i++)
                    {
                        GetUIElements(list, session, Element.Id, sbar.Children.ElementAt(i));
                    }
                }
            }
        }
Example #3
0
 static void Main(string[] args)
 {
     try
     {
         try
         {
             _ = SAPGuiApiAssembly;
             InputDriver.Instance.OnMouseDown -= OnMouseDown;
         }
         catch (Exception)
         {
             throw;
         }
         form = new MainWindow();
         var SessionId = System.Diagnostics.Process.GetCurrentProcess().SessionId;
         pipe = new NamedPipeServer <SAPEvent>(SessionId + "_openrpa_sapbridge");
         pipe.ClientConnected += Pipe_ClientConnected;
         pipe.ClientMessage   += Server_OnReceivedMessage;
         pipe.Start();
         Task.Run(() => SAPEventElement.PropogateTypeCache());
         System.Windows.Forms.Application.Run(form);
     }
     catch (Exception ex)
     {
         log(ex.ToString());
     }
 }
Example #4
0
        public SAPEventElement(SAPEventElement msg, SAPFEWSELib.GuiGridView grid, string parentpath, int Row, string SystemName)
        {
            Id = grid.Id;
            // Path = parentpath + "/" + key;
            Path = Row.ToString();
            if (string.IsNullOrEmpty(parentpath))
            {
                Path = Row.ToString();
            }
            this.SystemName = SystemName;
            ContainerType   = false;
            type            = "GuiGridView";
            Parent          = grid.Id;
            Name            = Row.ToString();


            var p = new List <SAPElementProperty>();

            p.Add(new SAPElementProperty("Left", grid.Left.ToString(), true));
            p.Add(new SAPElementProperty("Top", grid.Top.ToString(), true));
            p.Add(new SAPElementProperty("ScreenLeft", grid.ScreenLeft.ToString(), true));
            p.Add(new SAPElementProperty("ScreenTop", grid.ScreenTop.ToString(), true));
            p.Add(new SAPElementProperty("Width", grid.Width.ToString(), true));
            p.Add(new SAPElementProperty("Height", grid.Height.ToString(), true));

            _Rectangle = new Rectangle(grid.ScreenLeft, grid.ScreenTop, grid.Width, grid.Height);

            var keys     = grid.ColumnOrder as SAPFEWSELib.GuiCollection;
            var children = new List <SAPEventElement>();

            foreach (string key in keys)
            {
                var column = new SAPEventElement();
                column.Name = key;
                int Left       = grid.GetCellLeft(Row, key);
                int Top        = grid.GetCellTop(Row, key);
                int Width      = grid.GetCellWidth(Row, key);
                int Height     = grid.GetCellHeight(Row, key);
                var ScreenLeft = Left + msg.Rectangle.X;
                var ScreenTop  = Top + msg.Rectangle.Y;

                string Value = grid.GetCellValue(Row, key);

                var properties = new List <SAPElementProperty>();
                properties.Add(new SAPElementProperty("Left", Left.ToString(), true));
                properties.Add(new SAPElementProperty("Top", Top.ToString(), true));
                properties.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                properties.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                properties.Add(new SAPElementProperty("Width", Width.ToString(), true));
                properties.Add(new SAPElementProperty("Height", Height.ToString(), true));
                properties.Add(new SAPElementProperty("Value", Value, false));
                column._Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                column.Properties = properties.ToArray();
                children.Add(column);
            }
            Children = children.ToArray();
        }
Example #5
0
        private void GetUIElements(List <SAPEventElement> list, GuiSession session, string Parent, GuiComponent Element, bool VisibleOnly)
        {
            var ele = new SAPEventElement(session, Element, session.Info.SystemName, false, null, null, false, true, 50, VisibleOnly);

            list.Add(ele);
            foreach (var child in ele.Children)
            {
                GetUIElements(list, session, ele.Id, child, VisibleOnly);
            }
        }
Example #6
0
        private void GetUIElements(List <SAPEventElement> list, GuiSession session, string Parent, GuiComponent Element, bool VisibleOnly)
        {
            var ele = new SAPEventElement(Element, session.Info.SystemName, false, null, null, false, true, 50, VisibleOnly);

            list.Add(ele);
            foreach (var child in ele.Children)
            {
                GetUIElements(list, session, ele.Id, child, VisibleOnly);
            }

            //var msg = new SAPEventElement(Element, session.Info.SystemName, Parent, false);
            //list.Add(msg);
            //if (Element.ContainerType)
            //{
            //    if (Element is GuiVContainer vcon)
            //    {
            //        for (var i = 0; i < vcon.Children.Count; i++)
            //        {
            //            GetUIElements(list, session, Element.Id, vcon.Children.ElementAt(i));
            //        }
            //    }
            //    else if (Element is GuiContainer con)
            //    {
            //        for (var i = 0; i < con.Children.Count; i++)
            //        {
            //            GetUIElements(list, session, Element.Id, con.Children.ElementAt(i));
            //        }
            //    }
            //    else if (Element is GuiStatusbar sbar)
            //    {
            //        for (var i = 0; i < sbar.Children.Count; i++)
            //        {
            //            GetUIElements(list, session, Element.Id, sbar.Children.ElementAt(i));
            //        }
            //    }
            //}
        }
Example #7
0
        private void GetUIElements(List <SAPEventElement> list, SAPEventElement msg, GuiTree tree, string path, string SystemName)
        {
            GuiCollection keys = null;

            if (string.IsNullOrEmpty(path))
            {
                keys = tree.GetNodesCol() as GuiCollection;
            }
            else
            {
                keys = tree.GetSubNodesCol(path) as GuiCollection;
            }
            if (keys != null)
            {
                foreach (string key in keys)
                {
                    var _msg = new SAPEventElement(msg, tree, msg.Path, key, SystemName);
                    _msg.type = "GuiTreeNode";
                    list.Add(_msg);
                    System.Diagnostics.Trace.WriteLine(_msg.ToString());
                    GetUIElements(list, msg, tree, key, SystemName);
                }
            }
        }
Example #8
0
        private static void Server_OnReceivedMessage(NamedPipeConnection <SAPEvent, SAPEvent> connection, SAPEvent message)
        {
            try
            {
                if (message == null)
                {
                    return;
                }
                form.AddText("[resc] " + message.action);
                if (message.action == "beginrecord")
                {
                    try
                    {
                        recordstarting = true;
                        var recinfo = message.Get <SAPToogleRecordingEvent>();
                        var overlay = false;
                        if (recinfo != null)
                        {
                            overlay = recinfo.overlay;
                            StartMonitorMouse(recinfo.mousemove);
                        }
                        SAPHook.Instance.BeginRecord(overlay);
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                        recordstarting = false;
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "endrecord")
                {
                    try
                    {
                        StopMonitorMouse();
                        SAPHook.Instance.EndRecord();
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "login")
                {
                    try
                    {
                        var login = message.Get <SAPLoginEvent>();
                        if (SAPHook.Instance.Login(login))
                        {
                            var session = SAPHook.Instance.GetSession(login.SystemName);
                            if (session == null)
                            {
                                message.error = "Login failed";
                            }
                        }
                        else
                        {
                            message.error = "Login failed";
                        }
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "getconnections")
                {
                    try
                    {
                        var result = new SAPGetSessions();
                        SAPHook.Instance.RefreshSessions();
                        result.Connections = SAPHook.Instance.Connections;
                        message.Set(result);
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }

                if (message.action == "getitems")
                {
                }
                if (message.action == "getitem")
                {
                    try
                    {
                        var msg = message.Get <SAPEventElement>();
                        if (string.IsNullOrEmpty(msg.SystemName))
                        {
                            throw new ArgumentException("System Name is mandatory right now!");
                        }
                        var session = SAPHook.Instance.GetSession(msg.SystemName);
                        if (session != null)
                        {
                            GuiComponent comp = session.GetSAPComponentById <GuiComponent>(msg.Id);
                            if (comp is null)
                            {
                                throw new ArgumentException("Item with id " + msg.Id + " was not found");
                            }

                            msg.Id            = comp.Id; msg.Name = comp.Name;
                            msg.SystemName    = session.Info.SystemName;
                            msg.ContainerType = comp.ContainerType; msg.type = comp.Type;
                            var    p      = comp.Parent as GuiComponent;
                            string parent = (p != null) ? p.Id : null;
                            msg.Parent = parent;
                            // msg.LoadProperties(comp, true);
                            msg.LoadProperties(comp, false);
                            var children = new List <SAPEventElement>();
                            if (comp.ContainerType)
                            {
                                var cont = comp as GuiVContainer;

                                if (comp is GuiVContainer vcon)
                                {
                                    for (var i = 0; i < vcon.Children.Count; i++)
                                    {
                                        GuiComponent Element = vcon.Children.ElementAt(i);
                                        p      = Element.Parent as GuiComponent;
                                        parent = (p != null) ? p.Id : null;
                                        var _newchild = new SAPEventElement(Element, session.Info.SystemName, parent, false);
                                        children.Add(_newchild);
                                    }
                                }
                                else if (comp is GuiContainer con)
                                {
                                    for (var i = 0; i < con.Children.Count; i++)
                                    {
                                        GuiComponent Element = con.Children.ElementAt(i);
                                        p      = Element.Parent as GuiComponent;
                                        parent = (p != null) ? p.Id : null;
                                        children.Add(new SAPEventElement(Element, session.Info.SystemName, parent, false));
                                    }
                                }
                                else if (comp is GuiStatusbar sbar)
                                {
                                    for (var i = 0; i < sbar.Children.Count; i++)
                                    {
                                        GuiComponent Element = sbar.Children.ElementAt(i);
                                        p      = Element.Parent as GuiComponent;
                                        parent = (p != null) ? p.Id : null;
                                        children.Add(new SAPEventElement(Element, session.Info.SystemName, parent, false));
                                    }
                                }
                                else
                                {
                                    throw new Exception("Unknown container type " + comp.Type + "!");
                                }
                            }

                            msg.Children = children.ToArray();
                        }
                        else
                        {
                            message.error = "SAP not running, or session " + msg.SystemName + " not found.";
                        }
                        message.Set(msg);
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "invokemethod" || message.action == "setproperty" || message.action == "getproperty" || message.action == "highlight")
                {
                    try
                    {
                        var step = message.Get <SAPInvokeMethod>();
                        if (step != null)
                        {
                            var session = SAPHook.Instance.GetSession(step.SystemName);
                            if (session != null)
                            {
                                GuiComponent comp = session.GetSAPComponentById <GuiComponent>(step.Id);
                                if (comp == null)
                                {
                                    if (step.Id.Contains("/tbar[1]/"))
                                    {
                                        comp = session.GetSAPComponentById <GuiComponent>(step.Id.Replace("/tbar[1]/", "/tbar[0]/"));
                                    }
                                }
                                if (comp == null)
                                {
                                    throw new Exception(string.Format("Can't find component using id {0}", step.Id));
                                }
                                string typeName = _prefix + comp.Type;
                                Type   t        = SAPGuiApiAssembly.GetType(typeName);
                                if (t == null)
                                {
                                    throw new Exception(string.Format("Can't find type {0}", typeName));
                                }
                                var Parameters = Newtonsoft.Json.JsonConvert.DeserializeObject <object[]>(step.Parameters);

                                if (message.action == "invokemethod")
                                {
                                    step.Result = t.InvokeMember(step.ActionName, System.Reflection.BindingFlags.InvokeMethod, null, comp, Parameters);
                                }
                                if (message.action == "setproperty")
                                {
                                    step.Result = t.InvokeMember(step.ActionName, System.Reflection.BindingFlags.SetProperty, null, comp, Parameters);
                                }
                                if (message.action == "getproperty")
                                {
                                    step.Result = t.InvokeMember(step.ActionName, System.Reflection.BindingFlags.GetProperty, null, comp, Parameters);
                                }
                                var vcomp = comp as GuiVComponent;

                                if (message.action == "highlight" && vcomp != null)
                                {
                                    try
                                    {
                                        if (_lastHighlight != null)
                                        {
                                            _lastHighlight.Visualize(false);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                    _lastHighlight = null;
                                    _lastHighlight = comp as GuiVComponent;
                                    _lastHighlight.Visualize(true);
                                }
                            }
                            else
                            {
                                message.error = "SAP not running, or session " + step.SystemName + " not found.";
                            }
                            message.Set(step);
                        }
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
            }
            catch (Exception ex)
            {
                log(ex.ToString());
                form.AddText(ex.ToString());
            }
        }
Example #9
0
        public void Load(SAPFEWSELib.GuiSession session, SAPFEWSELib.GuiComponent comp, string SystemName, bool all, string Path, string Cell, bool flat, bool LoadChildren, int MaxItem, bool VisibleOnly)
        {
            this.Path    = Path;
            this.Cell    = Cell;
            this.Flat    = flat;
            this.MaxItem = MaxItem;
            if (comp is SAPFEWSELib.GuiTree tree)
            {
                type = "GuiTree";
                SAPFEWSELib.GuiCollection keys = null;

                if (string.IsNullOrEmpty(Path))
                {
                    int Left       = 0;
                    int Top        = 0;
                    int Width      = 0;
                    int Height     = 0;
                    int ScreenLeft = 0;
                    int ScreenTop  = 0;

                    Height = tree.Height;
                    if (Height > 0)
                    {
                        Left       = tree.Left;
                        Top        = tree.Top;
                        Width      = tree.Width;
                        ScreenLeft = tree.ScreenLeft;
                        ScreenTop  = tree.ScreenTop;
                    }
                    var p = new List <SAPElementProperty>();
                    if (Properties == null || Properties.Length == 0)
                    {
                        if (Properties != null)
                        {
                            p.AddRange(Properties);
                        }
                        if (p.Where(x => x.Name == "Left").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("Left", tree.Left.ToString(), true));
                        }
                        p.Add(new SAPElementProperty("Top", tree.Top.ToString(), true));
                        p.Add(new SAPElementProperty("ScreenLeft", tree.ScreenLeft.ToString(), true));
                        p.Add(new SAPElementProperty("ScreenTop", tree.ScreenTop.ToString(), true));
                        p.Add(new SAPElementProperty("Width", tree.Width.ToString(), true));
                        p.Add(new SAPElementProperty("Height", tree.Height.ToString(), true));
                        Properties = p.ToArray();
                    }
                    _Rectangle = new Rectangle(tree.ScreenLeft, tree.ScreenTop, tree.Width, tree.Height);
                    if (Flat)
                    {
                        keys = tree.GetAllNodeKeys() as SAPFEWSELib.GuiCollection;
                    }
                    else
                    {
                        keys = tree.GetNodesCol() as SAPFEWSELib.GuiCollection;
                    }
                    if (keys != null && LoadChildren && (VisibleOnly && Height > 0 || !VisibleOnly))
                    {
                        var _keys = new List <string>();
                        foreach (string key in keys)
                        {
                            _keys.Add(key);
                        }
                        var children = new List <SAPEventElement>();
                        foreach (string key in keys)
                        {
                            var _msg = new SAPEventElement(session, comp, SystemName, all, key, null, Flat, true, MaxItem, VisibleOnly);
                            children.Add(_msg);
                            if (MaxItem > 0)
                            {
                                if (children.Count >= MaxItem)
                                {
                                    break;
                                }
                            }
                        }
                        Children = children.ToArray();
                    }
                }
                else
                {
                    ContainerType = false;
                    type          = "GuiTreeNode";
                    int  Left       = 0;
                    int  Top        = 0;
                    int  Width      = 0;
                    int  Height     = 0;
                    int  ScreenLeft = 0;
                    int  ScreenTop  = 0;
                    bool expanded   = false;
                    if (string.IsNullOrEmpty(Cell))
                    {
                        Height = tree.GetNodeHeight(Path);
                        if (Height > 0)
                        {
                            Left       = tree.GetNodeLeft(Path);
                            Top        = tree.GetNodeTop(Path);
                            Width      = tree.GetNodeWidth(Path);
                            ScreenLeft = Left + tree.ScreenLeft;
                            ScreenTop  = Top + tree.ScreenTop;
                            expanded   = tree.IsFolderExpanded(Path);
                        }
                    }
                    else
                    {
                        Height = tree.GetItemHeight(Path, Cell);
                        if (Height > 0)
                        {
                            Left       = tree.GetItemLeft(Path, Cell);
                            Top        = tree.GetItemTop(Path, Cell);
                            Width      = tree.GetItemWidth(Path, Cell);
                            ScreenLeft = Left + tree.ScreenLeft;
                            ScreenTop  = Top + tree.ScreenTop;
                        }
                    }

                    if (Properties == null || Properties.Length == 0)
                    {
                        var p = new List <SAPElementProperty>();
                        if (Properties != null)
                        {
                            p.AddRange(Properties);
                        }
                        var text = tree.GetNodeTextByKey(Path);
                        if (p.Where(x => x.Name == "Left").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("Left", Left.ToString(), true));
                        }
                        if (p.Where(x => x.Name == "Top").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("Top", Top.ToString(), true));
                        }
                        if (p.Where(x => x.Name == "ScreenLeft").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                        }
                        if (p.Where(x => x.Name == "ScreenTop").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                        }
                        if (p.Where(x => x.Name == "Width").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("Width", Width.ToString(), true));
                        }
                        if (p.Where(x => x.Name == "Height").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("Height", Height.ToString(), true));
                        }
                        if (p.Where(x => x.Name == "Key").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("Key", Path, true));
                        }
                        if (SAPHook.Instance.Recording)
                        {
                            if (string.IsNullOrEmpty(Cell))
                            {
                                try
                                {
                                    if (p.Where(x => x.Name == "Tooltip").Count() == 0)
                                    {
                                        p.Add(new SAPElementProperty("Tooltip", tree.GetNodeToolTip(Path), true));
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                            else
                            {
                                try
                                {
                                    if (p.Where(x => x.Name == "Tooltip").Count() == 0)
                                    {
                                        p.Add(new SAPElementProperty("Tooltip", tree.GetItemToolTip(Path, Cell), true));
                                    }
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(Cell))
                        {
                            if (p.Where(x => x.Name == "Cell").Count() == 0)
                            {
                                p.Add(new SAPElementProperty("Cell", Cell, true));
                            }
                        }
                        if (p.Where(x => x.Name == "Text").Count() == 0)
                        {
                            p.Add(new SAPElementProperty("Text", text, true));
                        }
                        Properties = p.ToArray();
                    }
                    _Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                    if (string.IsNullOrEmpty(Cell) && (VisibleOnly && Height > 0 && expanded || !VisibleOnly))
                    {
                        keys = tree.GetColumnHeaders() as SAPFEWSELib.GuiCollection;
                        if (keys == null)
                        {
                            keys = tree.GetNodeItemHeaders(Path) as SAPFEWSELib.GuiCollection;
                        }
                        if (keys != null)
                        {
                            var children = new List <SAPEventElement>();
                            foreach (string key in keys)
                            {
                                var _msg = new SAPEventElement(session, comp, SystemName, all, Path, key, Flat, true, MaxItem, VisibleOnly);
                                children.Add(_msg);
                                if (MaxItem > 0)
                                {
                                    if (children.Count >= MaxItem)
                                    {
                                        break;
                                    }
                                }
                            }
                            Items = children.ToArray();
                        }
                    }
                    if (!flat && LoadChildren && string.IsNullOrEmpty(Cell) && (VisibleOnly && Height > 0 && expanded || !VisibleOnly))
                    {
                        keys = tree.GetSubNodesCol(Path) as SAPFEWSELib.GuiCollection;
                        if (keys != null && LoadChildren)
                        {
                            var children = new List <SAPEventElement>();
                            foreach (string key in keys)
                            {
                                var _msg = new SAPEventElement(session, comp, SystemName, all, key, null, Flat, false, MaxItem, VisibleOnly);
                                children.Add(_msg);
                                if (MaxItem > 0)
                                {
                                    if (children.Count >= MaxItem)
                                    {
                                        break;
                                    }
                                }
                            }
                            Children = children.ToArray();
                        }
                    }
                }
            }
            else if (comp is SAPFEWSELib.GuiTableControl table)
            {
                type = "GuiTable";
                throw new Exception("Unknown role type GuiTable");
            }
            else if (comp is SAPFEWSELib.GuiGridView grid)
            {
                type = "GuiGrid";
                if (string.IsNullOrEmpty(Path))
                {
                    var p = new List <SAPElementProperty>();
                    p.Add(new SAPElementProperty("Left", grid.Left.ToString(), true));
                    p.Add(new SAPElementProperty("Top", grid.Top.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenLeft", grid.ScreenLeft.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenTop", grid.ScreenTop.ToString(), true));
                    p.Add(new SAPElementProperty("Width", grid.Width.ToString(), true));
                    p.Add(new SAPElementProperty("Height", grid.Height.ToString(), true));
                    if (SAPHook.Instance.Recording)
                    {
                        p.Add(new SAPElementProperty("Tooltip", grid.Tooltip, true));
                        p.Add(new SAPElementProperty("DefaultTooltip", grid.DefaultTooltip, true));
                    }

                    _Rectangle = new Rectangle(grid.ScreenLeft, grid.ScreenTop, grid.Width, grid.Height);
                    Properties = p.ToArray();
                }
                else if (string.IsNullOrEmpty(Cell))
                {
                    ContainerType = false;
                    type          = "GuiGridNode";
                    var p          = new List <SAPElementProperty>();
                    int Left       = 0;
                    int Top        = 0;
                    int Width      = 0;
                    int Height     = 0;
                    int ScreenLeft = 0;
                    int ScreenTop  = 0;
                    var index      = int.Parse(Path);
                    Height = grid.GetCellHeight(index, Cell);
                    if (Height > 0)
                    {
                        //Width = grid.GetCellWidth(index, Cell);
                        Width      = grid.Width;
                        Left       = grid.GetCellLeft(index, Cell);
                        Top        = grid.GetCellTop(index, Cell);
                        ScreenLeft = Left + grid.ScreenLeft;
                        ScreenTop  = Top + grid.ScreenTop;
                    }
                    p.Add(new SAPElementProperty("Left", Left.ToString(), true));
                    p.Add(new SAPElementProperty("Top", Top.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                    p.Add(new SAPElementProperty("Width", Width.ToString(), true));
                    p.Add(new SAPElementProperty("Height", Height.ToString(), true));
                    p.Add(new SAPElementProperty("Key", Path, true));
                    if (SAPHook.Instance.Recording)
                    {
                        p.Add(new SAPElementProperty("Tooltip", grid.GetColumnTooltip(Path), true));
                    }

                    if (!string.IsNullOrEmpty(Cell))
                    {
                        p.Add(new SAPElementProperty("Cell", Cell, true));
                    }
                    //var text = tree.GetNodeTextByKey(Path);
                    //p.Add(new SAPElementProperty("Text", text, true));
                    Properties = p.ToArray();
                    _Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                }
                else
                {
                    ContainerType = false;
                    type          = "GuiGridCell";

                    var properties = new List <SAPElementProperty>();
                    properties.Add(new SAPElementProperty("Key", Cell, true));

                    var index = int.Parse(Path);
                    properties.Add(new SAPElementProperty("Index", index.ToString(), true));
                    //var tooltip = grid.GetCellTooltip(index, Cell);
                    //properties.Add(new SAPElementProperty("Title", title, true));
                    string Value      = null;
                    int    Left       = 0;
                    int    Top        = 0;
                    int    Width      = 0;
                    int    Height     = 0;
                    var    ScreenLeft = 0;
                    var    ScreenTop  = 0;
                    try
                    {
                        Value = grid.GetCellValue(index, Cell);
                        if (string.IsNullOrEmpty(Value))
                        {
                            grid.SetCurrentCell(index, Cell);
                            //grid.PressButton(index, Cell);
                            //grid.SelectedRows = Path;
                            Value = grid.GetCellValue(index, Cell);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    properties.Add(new SAPElementProperty("Value", Value, false));
                    //string title = grid.GetDisplayedColumnTitle(Cell);
                    //properties.Add(new SAPElementProperty("ToolTip", tooltip, true));
                    try
                    {
                        Height = grid.GetCellHeight(index, Cell);
                        if (Height > 0)
                        {
                            Left       = grid.GetCellLeft(index, Cell);
                            Top        = grid.GetCellTop(index, Cell);
                            Width      = grid.GetCellWidth(index, Cell);
                            ScreenLeft = Left + grid.ScreenLeft;
                            ScreenTop  = Top + grid.ScreenTop;
                        }
                    }
                    catch (Exception)
                    {
                    }
                    properties.Add(new SAPElementProperty("Left", Left.ToString(), true));
                    properties.Add(new SAPElementProperty("Top", Top.ToString(), true));
                    properties.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                    properties.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                    properties.Add(new SAPElementProperty("Width", Width.ToString(), true));
                    properties.Add(new SAPElementProperty("Height", Height.ToString(), true));
                    if (SAPHook.Instance.Recording)
                    {
                        properties.Add(new SAPElementProperty("Tooltip", grid.GetCellTooltip(index, Cell), true));
                    }

                    _Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                    Properties = properties.ToArray();
                }

                if (string.IsNullOrEmpty(Path))
                {
                    var children = new List <SAPEventElement>();
                    if (string.IsNullOrEmpty(Cell) && LoadChildren)
                    {
                        int from = 0;
                        int to   = grid.RowCount;

                        if (VisibleOnly)
                        {
                            from = grid.FirstVisibleRow;
                            to   = grid.FirstVisibleRow + grid.VisibleRowCount;
                        }
                        for (var i = from; i < to; i++)
                        {
                            var _msg = new SAPEventElement(session, comp, SystemName, all, i.ToString(), null, Flat, true, MaxItem, VisibleOnly);
                            //var _msg = new SAPEventElement(comp, SystemName, Parent, false);
                            children.Add(_msg);
                            if (MaxItem > 0)
                            {
                                if (children.Count >= MaxItem)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    Children = children.ToArray();
                }
                else if (LoadChildren)
                {
                    var children = new List <SAPEventElement>();
                    var keys     = grid.ColumnOrder as SAPFEWSELib.GuiCollection;
                    foreach (string key in keys)
                    {
                        var _msg = new SAPEventElement(session, comp, SystemName, all, Path, key, Flat, false, MaxItem, VisibleOnly);
                        children.Add(_msg);
                        if (MaxItem > 0)
                        {
                            if (children.Count >= MaxItem)
                            {
                                break;
                            }
                        }
                    }
                    Items = children.ToArray();
                }
            }
            else if (comp is SAPFEWSELib.GuiRadioButton radio)
            {
                var p = new List <SAPElementProperty>();
                p.Add(new SAPElementProperty("Selected", radio.Selected.ToString(), false));
                type = "GuiRadioButton";
                int Left       = 0;
                int Top        = 0;
                int Width      = 0;
                int Height     = 0;
                int ScreenLeft = 0;
                int ScreenTop  = 0;
                Height = radio.Height;
                if (Height > 0)
                {
                    Left       = radio.Left;
                    Top        = radio.Top;
                    Width      = radio.Width;
                    ScreenLeft = radio.ScreenLeft;
                    ScreenTop  = radio.ScreenTop;
                }
                p.Add(new SAPElementProperty("Left", Left.ToString(), true));
                p.Add(new SAPElementProperty("Top", Top.ToString(), true));
                p.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                p.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                p.Add(new SAPElementProperty("Width", Width.ToString(), true));
                p.Add(new SAPElementProperty("Height", Height.ToString(), true));
                if (SAPHook.Instance.Recording)
                {
                    p.Add(new SAPElementProperty("Tooltip", radio.Tooltip, true));
                    p.Add(new SAPElementProperty("DefaultTooltip", radio.DefaultTooltip, true));
                }

                Properties = p.ToArray();
                _Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                var children = new List <SAPEventElement>();
                var keys     = radio.GroupMembers as SAPFEWSELib.GuiCollection;
                if (keys != null && LoadChildren)
                {
                    for (var i = 0; i < keys.Count; i++)
                    {
                        var ele  = keys.ElementAt(i) as SAPFEWSELib.GuiComboBoxEntry;
                        var _msg = new SAPEventElement(ele, SystemName, radio.Id, all);
                        children.Add(_msg);
                        if (MaxItem > 0)
                        {
                            if (children.Count >= MaxItem)
                            {
                                break;
                            }
                        }
                    }
                }
                Items = children.ToArray();
            }
            else if (comp is SAPFEWSELib.GuiComboBox combobox)
            {
                var children = new List <SAPEventElement>();
                var keys     = combobox.Entries as SAPFEWSELib.GuiCollection;
                var p        = new List <SAPElementProperty>();
                p.Add(new SAPElementProperty("Value", combobox.Value, false));
                type = "GuiComboBox";
                int Left       = 0;
                int Top        = 0;
                int Width      = 0;
                int Height     = 0;
                int ScreenLeft = 0;
                int ScreenTop  = 0;
                Height = combobox.Height;
                if (Height > 0)
                {
                    Left       = combobox.Left;
                    Top        = combobox.Top;
                    Width      = combobox.Width;
                    ScreenLeft = combobox.ScreenLeft;
                    ScreenTop  = combobox.ScreenTop;
                }
                p.Add(new SAPElementProperty("Left", Left.ToString(), true));
                p.Add(new SAPElementProperty("Top", Top.ToString(), true));
                p.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                p.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                p.Add(new SAPElementProperty("Width", Width.ToString(), true));
                p.Add(new SAPElementProperty("Height", Height.ToString(), true));
                if (SAPHook.Instance.Recording)
                {
                    p.Add(new SAPElementProperty("Tooltip", combobox.Tooltip, true));
                    p.Add(new SAPElementProperty("DefaultTooltip", combobox.DefaultTooltip, true));
                }
                Properties = p.ToArray();
                _Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                if (LoadChildren)
                {
                    for (var i = 0; i < keys.Count; i++)
                    {
                        var ele  = keys.ElementAt(i) as SAPFEWSELib.GuiComboBoxEntry;
                        var _msg = new SAPEventElement(ele, SystemName, combobox.Id, all);
                        children.Add(_msg);
                        if (MaxItem > 0)
                        {
                            if (children.Count >= MaxItem)
                            {
                                break;
                            }
                        }
                    }
                }
                Items = children.ToArray();
            }
            else if (comp is SAPFEWSELib.GuiAbapEditor)
            {
                type = "GuiAbapEditor";
            }
            else if (comp is SAPFEWSELib.GuiTextedit)
            {
                type = "GuiTextedit";
            }
            else if (comp is SAPFEWSELib.GuiTextField)
            {
                type = "GuiTextField";
            }
            else if (comp.ContainerType)
            {
                if (comp is SAPFEWSELib.GuiVContainer vcon && LoadChildren)
                {
                    var children = new List <SAPEventElement>();
                    for (var i = 0; i < vcon.Children.Count; i++)
                    {
                        SAPFEWSELib.GuiComponent Element = vcon.Children.ElementAt(i);
                        var p         = Element.Parent as SAPFEWSELib.GuiComponent;
                        var parent    = (p != null) ? p.Id : null;
                        var _newchild = new SAPEventElement(Element, SystemName, parent, false);
                        children.Add(_newchild);
                        if (MaxItem > 0)
                        {
                            if (children.Count >= MaxItem)
                            {
                                break;
                            }
                        }
                    }
                    Children = children.ToArray();
                }
                else if (comp is SAPFEWSELib.GuiSession session2 && LoadChildren)
                {
                    var children = new List <SAPEventElement>();
                    if (VisibleOnly)
                    {
                        SAPFEWSELib.GuiComponent Element = session2.ActiveWindow as SAPFEWSELib.GuiComponent;
                        var p      = Element.Parent as SAPFEWSELib.GuiComponent;
                        var parent = (p != null) ? p.Id : null;
                        children.Add(new SAPEventElement(Element, SystemName, parent, false));
                    }
                    else
                    {
                        for (var i = 0; i < session2.Children.Count; i++)
                        {
                            SAPFEWSELib.GuiComponent Element = session2.Children.ElementAt(i);
                            var p      = Element.Parent as SAPFEWSELib.GuiComponent;
                            var parent = (p != null) ? p.Id : null;
                            children.Add(new SAPEventElement(Element, SystemName, parent, false));
                            if (MaxItem > 0)
                            {
                                if (children.Count >= MaxItem)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    Children = children.ToArray();
                }
Example #10
0
 private void GetUIElements(List <SAPEventElement> list, GuiSession session, string Parent, SAPEventElement ele, bool VisibleOnly)
 {
     list.Add(ele);
     if (!string.IsNullOrEmpty(ele.Path))
     {
         System.Diagnostics.Trace.WriteLine(ele.ToString() + " " + ele.Rectangle);
     }
     if (ele.Children == null)
     {
         ele.Load(VisibleOnly);
     }
     if (ele.Children != null)
     {
         foreach (var child in ele.Children)
         {
             GetUIElements(list, session, ele.Id, child, VisibleOnly);
         }
     }
 }
Example #11
0
        private static void Server_OnReceivedMessage(NamedPipeConnection <SAPEvent, SAPEvent> connection, SAPEvent message)
        {
            try
            {
                if (message == null)
                {
                    return;
                }
                form.AddText("[resc] " + message.action);
                if (message.action == "beginrecord")
                {
                    try
                    {
                        recordstarting = true;
                        var recinfo = message.Get <SAPToogleRecordingEvent>();
                        var overlay = false;
                        if (recinfo != null)
                        {
                            overlay = recinfo.overlay;
                            //StartMonitorMouse(recinfo.mousemove);
                            form.AddText("StartMonitorMouse::begin");
                            StartMonitorMouse(true);
                            form.AddText("StartMonitorMouse::end");
                        }
                        form.AddText("BeginRecord::begin");
                        SAPHook.Instance.BeginRecord(overlay);
                        form.AddText("BeginRecord::end");
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                        recordstarting = false;
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "endrecord")
                {
                    try
                    {
                        StopMonitorMouse();
                        SAPHook.Instance.EndRecord();
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "login")
                {
                    try
                    {
                        var  login   = message.Get <SAPLoginEvent>();
                        bool dologin = true;
                        if (SAPHook.Instance.Sessions != null)
                        {
                            foreach (var session in SAPHook.Instance.Sessions)
                            {
                                if (session.Info.SystemName.ToLower() == login.SystemName.ToLower())
                                {
                                    dologin = false; break;
                                }
                            }
                        }
                        if (dologin)
                        {
                            if (SAPHook.Instance.Login(login))
                            {
                                var session = SAPHook.Instance.GetSession(login.SystemName);
                                if (session == null)
                                {
                                    message.error = "Login failed";
                                }
                            }
                            else
                            {
                                message.error = "Login failed";
                            }
                        }
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "getconnections")
                {
                    try
                    {
                        var result = new SAPGetSessions();
                        SAPHook.Instance.RefreshSessions();
                        result.Connections = SAPHook.Instance.Connections;
                        message.Set(result);
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }

                if (message.action == "getitems")
                {
                    try
                    {
                        var msg         = message.Get <SAPEventElement>();
                        var session     = SAPHook.Instance.GetSession(msg.SystemName);
                        var sapelements = new List <GuiComponent>();
                        msg.Id = StripSession(msg.Id);
                        var paths = msg.Id.Split(new string[] { "/" }, StringSplitOptions.None);
                        for (var i = 0; i < paths.Length; i++)
                        {
                            string part  = paths[i];
                            int    index = ExtractIndex(ref part);
                            if (i == 0)
                            {
                                if (index > -1)
                                {
                                    sapelements.Add(session.Children.ElementAt(index));
                                }
                                if (index == -1)
                                {
                                    for (var x = 0; x < session.Children.Count; x++)
                                    {
                                        sapelements.Add(session.Children.ElementAt(x));
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "getitem")
                {
                    try
                    {
                        var msg = message.Get <SAPEventElement>();
                        // if (string.IsNullOrEmpty(msg.SystemName)) throw new ArgumentException("System Name is mandatory right now!");
                        var session = SAPHook.Instance.GetSession(msg.SystemName);
                        if (session == null)
                        {
                            msg.Id = null;
                            message.Set(msg);
                            form.AddText("[send] " + message.action);
                            pipe.PushMessage(message);
                            return;
                        }
                        // msg.Id = StripSession(msg.Id);
                        GuiComponent comp = session.GetSAPComponentById <GuiComponent>(msg.Id);
                        if (comp is null)
                        {
                            msg.Id = null;
                            message.Set(msg);
                            form.AddText("[send] " + message.action);
                            pipe.PushMessage(message);
                            return;
                        }
                        msg = new SAPEventElement(comp, session.Info.SystemName, msg.GetAllProperties, msg.Path, msg.Cell, msg.Flat, true, msg.MaxItem, msg.VisibleOnly);
                        message.Set(msg);
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
                if (message.action == "invokemethod" || message.action == "setproperty" || message.action == "getproperty" || message.action == "highlight")
                {
                    try
                    {
                        var step = message.Get <SAPInvokeMethod>();
                        if (step != null)
                        {
                            var session = SAPHook.Instance.GetSession(step.SystemName);
                            if (session != null)
                            {
                                GuiComponent comp = session.GetSAPComponentById <GuiComponent>(step.Id);
                                if (comp == null)
                                {
                                    if (step.Id.Contains("/tbar[1]/"))
                                    {
                                        comp = session.GetSAPComponentById <GuiComponent>(step.Id.Replace("/tbar[1]/", "/tbar[0]/"));
                                    }
                                }
                                if (comp == null)
                                {
                                    throw new Exception(string.Format("Can't find component using id {0}", step.Id));
                                }
                                string typeName = _prefix + comp.Type;
                                Type   t        = SAPGuiApiAssembly.GetType(typeName);
                                if (t == null)
                                {
                                    throw new Exception(string.Format("Can't find type {0}", typeName));
                                }
                                var Parameters = Newtonsoft.Json.JsonConvert.DeserializeObject <object[]>(step.Parameters);

                                if (message.action == "invokemethod")
                                {
                                    step.Result = t.InvokeMember(step.ActionName, System.Reflection.BindingFlags.InvokeMethod, null, comp, Parameters);
                                }
                                if (message.action == "setproperty")
                                {
                                    step.Result = t.InvokeMember(step.ActionName, System.Reflection.BindingFlags.SetProperty, null, comp, Parameters);
                                }
                                if (message.action == "getproperty")
                                {
                                    step.Result = t.InvokeMember(step.ActionName, System.Reflection.BindingFlags.GetProperty, null, comp, Parameters);
                                }
                                var vcomp = comp as GuiVComponent;

                                if (message.action == "highlight" && vcomp != null)
                                {
                                    try
                                    {
                                        if (_lastHighlight != null)
                                        {
                                            _lastHighlight.Visualize(false);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                    _lastHighlight = null;
                                    _lastHighlight = comp as GuiVComponent;
                                    _lastHighlight.Visualize(true);
                                }
                            }
                            else
                            {
                                message.error = "SAP not running, or session " + step.SystemName + " not found.";
                            }
                            message.Set(step);
                        }
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                    catch (Exception ex)
                    {
                        message.error = ex.Message;
                        if (ex.InnerException != null)
                        {
                            message.error = ex.InnerException.Message;
                        }
                        form.AddText("[send] " + message.action);
                        pipe.PushMessage(message);
                    }
                }
            }
            catch (Exception ex)
            {
                log(ex.ToString());
                form.AddText(ex.ToString());
            }
        }
Example #12
0
        private static void OnMouseMove(InputEventArgs e)
        {
            lock (_lock)
            {
                if (isMoving)
                {
                    return;
                }
                isMoving = true;
            }
            try
            {
                if (SAPHook.Instance.Connections.Count() == 0 || SAPHook.Instance.UIElements.Count() == 0)
                {
                    lock (_lock)
                    {
                        isMoving = false;
                    }
                    return;
                }
                var Element = System.Windows.Automation.AutomationElement.FromPoint(new System.Windows.Point(e.X, e.Y));
                if (Element != null)
                {
                    var ProcessId = Element.Current.ProcessId;
                    if (ProcessId < 1)
                    {
                        lock (_lock)
                        {
                            isMoving = false;
                        }
                        return;
                    }
                    if (SAPProcessId > 0 && SAPProcessId != ProcessId)
                    {
                        lock (_lock)
                        {
                            isMoving = false;
                        }
                        return;
                    }
                    if (SAPProcessId != ProcessId)
                    {
                        var p = System.Diagnostics.Process.GetProcessById(ProcessId);
                        if (p.ProcessName.ToLower() == "saplogon")
                        {
                            SAPProcessId = p.Id;
                        }
                        if (p.ProcessName.ToLower() != "saplogon")
                        {
                            lock (_lock)
                            {
                                isMoving = false;
                            }
                            return;
                        }
                    }
                    if (SAPHook.Instance.Connections.Count() == 0)
                    {
                        SAPHook.Instance.RefreshSessions();
                    }
                    if (SAPHook.Instance.UIElements.Count() == 0)
                    {
                        SAPHook.Instance.RefreshUIElements(true);
                    }
                    SAPEventElement[] elements = new SAPEventElement[] { };
                    lock (SAPHook.Instance.UIElements)
                    {
                        elements = SAPHook.Instance.UIElements.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                    }
                    if (elements.Count() > 0)
                    {
                        //Program.log("[mousemove] " + e.X + " " + e.Y);
                        //foreach(var ele in elements)
                        //{
                        //    Program.log("[element] " + ele.ToString());
                        //}
                        var found = elements.OrderBy(x => x.IdPathCell.Length).Last();
                        if (found.Items != null && found.Items.Length > 0)
                        {
                            elements = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                            if (elements != null && elements.Length > 0)
                            {
                                found = elements.OrderBy(x => x.IdPathCell.Length).Last();
                            }
                        }
                        //Program.log("[element] " + found.ToString() + " " + found.Rectangle.ToString());

                        if (found.Items != null && found.Items.Length > 0)
                        {
                            var found2 = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                            if (found2.Length > 0)
                            {
                                found = found2.First();
                            }
                        }

                        if (LastElement != null && (found.Id == LastElement.Id && found.Path == LastElement.Path && found.Cell == LastElement.Cell))
                        {
                            // form.AddText("[SKIP] mousemove " + LastElement.ToString());
                            lock (_lock)
                            {
                                isMoving = false;
                            }
                            return;
                        }
                        LastElement = found;
                        SAPEvent message = new SAPEvent("mousemove");
                        message.Set(LastElement);
                        form.AddText("[send] " + message.action + " " + LastElement.ToString() + " " + LastElement.Rectangle.ToString());
                        pipe.PushMessage(message);
                    }
                    else
                    {
                        log("Mouseover " + e.X + "," + e.Y + " not found in UI List");
                    }
                }
            }
            catch (Exception)
            {
            }
            lock (_lock)
            {
                isMoving = false;
            }
        }
Example #13
0
        public SAPEventElement(SAPEventElement msg, SAPFEWSELib.GuiTree tree, string parentpath, string key, string SystemName)
        {
            Id = tree.Id;
            // Path = parentpath + "/" + key;
            Path = key;
            if (string.IsNullOrEmpty(parentpath))
            {
                Path = key;
            }
            this.SystemName = SystemName;
            ContainerType   = false;
            type            = "GuiTreeNode";
            Parent          = tree.Id;
            Name            = key;
            if (string.IsNullOrEmpty(Path))
            {
                var p = new List <SAPElementProperty>();
                p.Add(new SAPElementProperty("Left", tree.Left.ToString(), true));
                p.Add(new SAPElementProperty("Top", tree.Top.ToString(), true));
                p.Add(new SAPElementProperty("ScreenLeft", tree.ScreenLeft.ToString(), true));
                p.Add(new SAPElementProperty("ScreenTop", tree.ScreenTop.ToString(), true));
                p.Add(new SAPElementProperty("Width", tree.Width.ToString(), true));
                p.Add(new SAPElementProperty("Height", tree.Height.ToString(), true));

                _Rectangle = new Rectangle(tree.ScreenLeft, tree.ScreenTop, tree.Width, tree.Height);
                Properties = p.ToArray();
            }
            else
            {
                int Left       = tree.GetNodeLeft(key);
                int Top        = tree.GetNodeTop(key);
                int Width      = tree.GetNodeWidth(key);
                int Height     = tree.GetNodeHeight(key);
                var ScreenLeft = Left + msg.Rectangle.X;
                var ScreenTop  = Top + msg.Rectangle.Y;
                var p          = new List <SAPElementProperty>();
                p.Add(new SAPElementProperty("Left", Left.ToString(), true));
                p.Add(new SAPElementProperty("Top", Top.ToString(), true));
                p.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                p.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                p.Add(new SAPElementProperty("Width", Width.ToString(), true));
                p.Add(new SAPElementProperty("Height", Height.ToString(), true));
                _Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                Properties = p.ToArray();
            }


            // SAPFEWSELib.GuiCollection keys = tree.GetColumnNames() as SAPFEWSELib.GuiCollection;
            // SAPFEWSELib.GuiCollection keys = tree.GetColumnTitles() as SAPFEWSELib.GuiCollection;
            SAPFEWSELib.GuiCollection keys = tree.GetColumnHeaders() as SAPFEWSELib.GuiCollection;
            var children = new List <SAPEventElement>();

            //foreach (string _key in keys)
            if (keys != null)
            {
                for (var i = 1; i <= keys.Count; i++)
                {
                    string _key   = i.ToString();
                    var    column = new SAPEventElement();
                    column.Name = tree.GetItemText(key, _key);
                    column.Id   = Id;
                    column.Path = Path;
                    if (string.IsNullOrEmpty(column.Name))
                    {
                        column.Name = _key;
                    }

                    int Left       = tree.GetItemLeft(key, _key);
                    int Top        = tree.GetItemTop(key, _key);
                    int Width      = tree.GetItemWidth(key, _key);
                    int Height     = tree.GetItemHeight(key, _key);
                    var ScreenLeft = Left + msg.Rectangle.X;
                    var ScreenTop  = Top + msg.Rectangle.Y;
                    column._Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                    var _p = new List <SAPElementProperty>();
                    _p.Add(new SAPElementProperty("Left", Left.ToString(), true));
                    _p.Add(new SAPElementProperty("Top", Top.ToString(), true));
                    _p.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                    _p.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                    _p.Add(new SAPElementProperty("Width", Width.ToString(), true));
                    _p.Add(new SAPElementProperty("Height", Height.ToString(), true));
                    column.Properties = _p.ToArray();
                    children.Add(column);
                }
            }
            Children = children.ToArray();
        }
Example #14
0
        private static void OnMouseMove(InputEventArgs e)
        {
            if (_isMoving)
            {
                return;
            }
            try
            {
                _isMoving = true;
                var app = SAPHook.Instance.app;
                if (app != null && app.Children != null)
                {
                    for (int x = 0; x < app.Children.Count; x++)
                    {
                        var con = app.Children.ElementAt(x) as GuiConnection;
                        if (con.Sessions.Count == 0)
                        {
                            continue;
                        }

                        for (int j = 0; j < con.Sessions.Count; j++)
                        {
                            var session    = con.Children.ElementAt(j) as GuiSession;
                            var SystemName = session.Info.SystemName.ToLower();
                            // var ele = session as GuiComponent;
                            GuiCollection keys = null;
                            try
                            {
                                if (System.Threading.Monitor.TryEnter(_lock, 1))
                                {
                                    try
                                    {
                                        var _y = session.ActiveWindow.Top;
                                        var _x = session.ActiveWindow.Left;
                                        var w  = session.ActiveWindow.Width;
                                        var h  = session.ActiveWindow.Height;
                                        if (e.X < _x || e.Y < _y)
                                        {
                                            return;
                                        }
                                        if (e.X > (_x + w) || e.Y > (_y + h))
                                        {
                                            return;
                                        }
                                        keys = session.FindByPosition(e.X, e.Y);
                                    }
                                    finally
                                    {
                                        System.Threading.Monitor.Exit(_lock);
                                    }
                                }
                                else
                                {
                                    return;
                                }
                            }
                            catch (System.Runtime.InteropServices.COMException ex)
                            {
                                // OnMouseMove(e);
                            }
                            catch (Exception ex)
                            {
                                log(ex.Message);
                            }
                            if (keys == null)
                            {
                                return;
                            }
                            var _keys = new List <string>();
                            foreach (string key in keys)
                            {
                                _keys.Add(key);
                            }

                            SAPEventElement[] elements = new SAPEventElement[] { };

                            log("**************************");
                            var          children = new List <SAPEventElement>();
                            GuiComponent last     = null;
                            foreach (string key in keys)
                            {
                                log(key.ToString());
                                if (string.IsNullOrEmpty(key))
                                {
                                    continue;
                                }
                                if (!key.Contains("?"))
                                {
                                    var ele = session.FindById(key);
                                    if (ele == null)
                                    {
                                        continue;
                                    }
                                    last = ele as GuiComponent;
                                    // last = ele as GuiVComponent;
                                    // if(last != null) last.Visualize(true);
                                    var _msg = new SAPEventElement(ele, SystemName, "", false);
                                    children.Add(_msg);
                                }
                            }
                            if (last != null)
                            {
                                foreach (string key in keys)
                                {
                                    if (string.IsNullOrEmpty(key))
                                    {
                                        continue;
                                    }
                                    if (key.Contains("?"))
                                    {
                                        if (LastElement == null)
                                        {
                                            continue;
                                        }
                                        var _key = key.Substring(0, key.IndexOf("?"));
                                        log(_key);
                                        var msg = new SAPEventElement(session, last, session.Info.SystemName, false, _key, "", false, false, 1, false);
                                        if (msg != null)
                                        {
                                            children.Add(msg);
                                            LastElement = msg;
                                        }
                                    }
                                }
                            }
                            LastElement = children.LastOrDefault();
                            if (LastElement != null)
                            {
                                SAPEvent message = new SAPEvent("mousemove");
                                message.Set(LastElement);
                                if (log_send_message)
                                {
                                    form.AddText("[send] " + message.action + " " + LastElement.ToString() + " " + LastElement.Rectangle.ToString());
                                }
                                pipe.PushMessage(message);
                            }
                        }
                    }
                }


                // elements = children.ToArray();

                //if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //{
                //    try
                //    {
                //        if (isMoving) return;
                //        isMoving = true;
                //    }
                //    finally
                //    {
                //        System.Threading.Monitor.Exit(_lock);
                //    }
                //}
                //try
                //{
                //    if (SAPHook.Instance.Connections.Count() == 0 || SAPHook.Instance.UIElements.Count() == 0)
                //    {
                //        if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //        {
                //            try
                //            {
                //                isMoving = false;
                //            }
                //            finally
                //            {
                //                System.Threading.Monitor.Exit(_lock);
                //            }
                //        }
                //        return;
                //    }
                //    var Element = System.Windows.Automation.AutomationElement.FromPoint(new System.Windows.Point(e.X, e.Y));
                //    if (Element != null)
                //    {
                //        var ProcessId = Element.Current.ProcessId;
                //        if (ProcessId < 1)
                //        {
                //            if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //            {
                //                try
                //                {
                //                    isMoving = false;
                //                }
                //                finally
                //                {
                //                    System.Threading.Monitor.Exit(_lock);
                //                }
                //            }
                //            return;
                //        }
                //        if (SAPProcessId > 0 && SAPProcessId != ProcessId)
                //        {
                //            if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //            {
                //                try
                //                {
                //                    isMoving = false;
                //                }
                //                finally
                //                {
                //                    System.Threading.Monitor.Exit(_lock);
                //                }
                //            }
                //            return;
                //        }
                //        if (SAPProcessId != ProcessId)
                //        {
                //            using (var p = System.Diagnostics.Process.GetProcessById(ProcessId))
                //            {
                //                if (p.ProcessName.ToLower() == "saplogon") SAPProcessId = p.Id;
                //                if (p.ProcessName.ToLower() != "saplogon")
                //                {
                //                    if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //                    {
                //                        try
                //                        {
                //                            isMoving = false;
                //                        }
                //                        finally
                //                        {
                //                            System.Threading.Monitor.Exit(_lock);
                //                        }
                //                    }
                //                    return;
                //                }
                //            }
                //        }
                //        if (SAPHook.Instance.Connections.Count() == 0) SAPHook.Instance.RefreshSessions();
                //        if (SAPHook.Instance.UIElements.Count() == 0) SAPHook.Instance.RefreshUIElements(true);
                //        SAPEventElement[] elements = new SAPEventElement[] { };
                //        if (System.Threading.Monitor.TryEnter(SAPHook.Instance.UIElements, 10000))
                //        {
                //            try
                //            {
                //                elements = SAPHook.Instance.UIElements.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                //            }
                //            finally
                //            {
                //                System.Threading.Monitor.Exit(SAPHook.Instance.UIElements);
                //            }
                //        }
                //        if (elements.Count() > 0)
                //        {
                //            //Program.log("[mousemove] " + e.X + " " + e.Y);
                //            //foreach(var ele in elements)
                //            //{
                //            //    Program.log("[element] " + ele.ToString());
                //            //}
                //            var found = elements.OrderBy(x => x.IdPathCell.Length).Last();
                //            if (found.Items != null && found.Items.Length > 0)
                //            {
                //                elements = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                //                if (elements != null && elements.Length > 0) found = elements.OrderBy(x => x.IdPathCell.Length).Last();

                //            }
                //            //Program.log("[element] " + found.ToString() + " " + found.Rectangle.ToString());

                //            if (found.Items != null && found.Items.Length > 0)
                //            {
                //                var found2 = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                //                if (found2.Length > 0)
                //                {
                //                    found = found2.First();
                //                }
                //            }

                //            if (LastElement != null && (found.Id == LastElement.Id && found.Path == LastElement.Path && found.Cell == LastElement.Cell))
                //            {
                //                // form.AddText("[SKIP] mousemove " + LastElement.ToString());
                //                if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //                {
                //                    try
                //                    {
                //                        isMoving = false;
                //                    }
                //                    finally
                //                    {
                //                        System.Threading.Monitor.Exit(_lock);
                //                    }
                //                }
                //                return;
                //            }
                //            LastElement = found;
                //            SAPEvent message = new SAPEvent("mousemove");
                //            message.Set(LastElement);
                //            if (log_send_message) form.AddText("[send] " + message.action + " " + LastElement.ToString() + " " + LastElement.Rectangle.ToString());
                //            pipe.PushMessage(message);
                //        }
                //        else
                //        {
                //            // log("Mouseover " + e.X + "," + e.Y + " not found in UI List");
                //        }
                //    }
                //}
                //catch (Exception)
                //{
                //}
                //if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //{
                //    try
                //    {
                //        isMoving = false;
                //    }
                //    finally
                //    {
                //        System.Threading.Monitor.Exit(_lock);
                //    }
                //}
            }
            finally
            {
                _isMoving = false;
            }
        }
Example #15
0
        public SAPEventElement(SAPFEWSELib.GuiComponent comp, string SystemName, bool all, string Path, string Cell, bool flat, bool loadChildren, int MaxItem)
        {
            this.Path       = Path;
            this.Cell       = Cell;
            this.Flat       = flat;
            this.MaxItem    = MaxItem;
            Id              = comp.Id;
            this.SystemName = SystemName;
            if (comp.Parent != null)
            {
                Parent = ((SAPFEWSELib.GuiComponent)comp.Parent).Id;
            }
            ContainerType = comp.ContainerType;
            type          = comp.Type;
            if (comp is SAPFEWSELib.GuiTree tree)
            {
                type = "GuiTree";
                SAPFEWSELib.GuiCollection keys = null;

                if (string.IsNullOrEmpty(Path))
                {
                    var p = new List <SAPElementProperty>();
                    p.Add(new SAPElementProperty("Left", tree.Left.ToString(), true));
                    p.Add(new SAPElementProperty("Top", tree.Top.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenLeft", tree.ScreenLeft.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenTop", tree.ScreenTop.ToString(), true));
                    p.Add(new SAPElementProperty("Width", tree.Width.ToString(), true));
                    p.Add(new SAPElementProperty("Height", tree.Height.ToString(), true));

                    _Rectangle = new Rectangle(tree.ScreenLeft, tree.ScreenTop, tree.Width, tree.Height);
                    Properties = p.ToArray();
                    if (Flat)
                    {
                        keys = tree.GetAllNodeKeys() as SAPFEWSELib.GuiCollection;
                    }
                    else
                    {
                        keys = tree.GetNodesCol() as SAPFEWSELib.GuiCollection;
                    }
                    if (keys != null && loadChildren)
                    {
                        var _keys = new List <string>();
                        foreach (string key in keys)
                        {
                            _keys.Add(key);
                        }
                        var children = new List <SAPEventElement>();
                        foreach (string key in keys)
                        {
                            var _msg = new SAPEventElement(comp, SystemName, all, key, null, Flat, true, MaxItem);
                            children.Add(_msg);
                            if (MaxItem > 0)
                            {
                                if (children.Count >= MaxItem)
                                {
                                    break;
                                }
                            }
                        }
                        Children = children.ToArray();
                    }
                }
                else
                {
                    ContainerType = false;
                    type          = "GuiTreeNode";
                    int Left       = tree.GetNodeLeft(Path);
                    int Top        = tree.GetNodeTop(Path);
                    int Width      = tree.GetNodeWidth(Path);
                    int Height     = tree.GetNodeHeight(Path);
                    var ScreenLeft = Left + tree.ScreenLeft;
                    var ScreenTop  = Top + tree.ScreenTop;
                    var p          = new List <SAPElementProperty>();
                    var text       = tree.GetNodeTextByKey(Path);

                    p.Add(new SAPElementProperty("Left", Left.ToString(), true));
                    p.Add(new SAPElementProperty("Top", Top.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                    p.Add(new SAPElementProperty("Width", Width.ToString(), true));
                    p.Add(new SAPElementProperty("Height", Height.ToString(), true));
                    p.Add(new SAPElementProperty("Key", Path, true));
                    if (!string.IsNullOrEmpty(Cell))
                    {
                        p.Add(new SAPElementProperty("Cell", Cell, true));
                    }
                    p.Add(new SAPElementProperty("Text", text, true));
                    Properties = p.ToArray();
                    _Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                    if (string.IsNullOrEmpty(Cell))
                    {
                        keys = tree.GetColumnHeaders() as SAPFEWSELib.GuiCollection;
                        if (keys == null)
                        {
                            keys = tree.GetNodeItemHeaders(Path) as SAPFEWSELib.GuiCollection;
                        }
                        if (keys != null)
                        {
                            var children = new List <SAPEventElement>();
                            foreach (string key in keys)
                            {
                                var _msg = new SAPEventElement(comp, SystemName, all, Path, key, Flat, true, MaxItem);
                                children.Add(_msg);
                                if (MaxItem > 0)
                                {
                                    if (children.Count >= MaxItem)
                                    {
                                        break;
                                    }
                                }
                            }
                            Items = children.ToArray();
                        }
                    }
                    if (!flat && loadChildren)
                    {
                        keys = tree.GetSubNodesCol(Path) as SAPFEWSELib.GuiCollection;
                        if (keys != null && loadChildren)
                        {
                            var children = new List <SAPEventElement>();
                            foreach (string key in keys)
                            {
                                var _msg = new SAPEventElement(comp, SystemName, all, Path, key, Flat, false, MaxItem);
                                children.Add(_msg);
                                if (MaxItem > 0)
                                {
                                    if (children.Count >= MaxItem)
                                    {
                                        break;
                                    }
                                }
                            }
                            Children = children.ToArray();
                        }
                    }
                }
            }
            else if (comp is SAPFEWSELib.GuiTableControl table)
            {
                type = "GuiTable";
                throw new Exception("Unknown role type GuiTable");
            }
            else if (comp is SAPFEWSELib.GuiGridView grid)
            {
                type = "GuiGrid";
                if (string.IsNullOrEmpty(Path))
                {
                    var p = new List <SAPElementProperty>();
                    p.Add(new SAPElementProperty("Left", grid.Left.ToString(), true));
                    p.Add(new SAPElementProperty("Top", grid.Top.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenLeft", grid.ScreenLeft.ToString(), true));
                    p.Add(new SAPElementProperty("ScreenTop", grid.ScreenTop.ToString(), true));
                    p.Add(new SAPElementProperty("Width", grid.Width.ToString(), true));
                    p.Add(new SAPElementProperty("Height", grid.Height.ToString(), true));
                    _Rectangle = new Rectangle(grid.ScreenLeft, grid.ScreenTop, grid.Width, grid.Height);
                    Properties = p.ToArray();
                }
                else if (string.IsNullOrEmpty(Cell))
                {
                    ContainerType = false;
                    type          = "GuiGridNode";
                    var p = new List <SAPElementProperty>();
                    // Properties = p.ToArray();
                    //grid.SelectedColumns = new object[] { Path };
                    // grid.SelectedRows sele.SelectColumn(Path);
                    //long numrRow = grid.CurrentCellRow;
                    //grid.SelectedRows = numrRow.ToString();
                }
                else
                {
                    ContainerType = false;
                    type          = "GuiGridCell";

                    var properties = new List <SAPElementProperty>();
                    properties.Add(new SAPElementProperty("Key", Cell, true));

                    var index = int.Parse(Path);
                    properties.Add(new SAPElementProperty("Index", index.ToString(), true));
                    //var tooltip = grid.GetCellTooltip(index, Cell);
                    //properties.Add(new SAPElementProperty("Title", title, true));
                    string Value = grid.GetCellValue(index, Cell);
                    if (string.IsNullOrEmpty(Value))
                    {
                        grid.SetCurrentCell(index, Cell);
                        //grid.PressButton(index, Cell);
                        //grid.SelectedRows = Path;
                        Value = grid.GetCellValue(index, Cell);
                    }
                    properties.Add(new SAPElementProperty("Value", Value, false));
                    //string title = grid.GetDisplayedColumnTitle(Cell);
                    //properties.Add(new SAPElementProperty("ToolTip", tooltip, true));

                    //int Left = grid.GetCellLeft(index, Cell);
                    //int Top = grid.GetCellTop(index, Cell);
                    //int Width = grid.GetCellWidth(index, Cell);
                    //int Height = grid.GetCellHeight(index, Cell);
                    //var ScreenLeft = Left + grid.ScreenLeft;
                    //var ScreenTop = Top + grid.ScreenTop;
                    //properties.Add(new SAPElementProperty("Left", Left.ToString(), true));
                    //properties.Add(new SAPElementProperty("Top", Top.ToString(), true));
                    //properties.Add(new SAPElementProperty("ScreenLeft", ScreenLeft.ToString(), true));
                    //properties.Add(new SAPElementProperty("ScreenTop", ScreenTop.ToString(), true));
                    //properties.Add(new SAPElementProperty("Width", Width.ToString(), true));
                    //properties.Add(new SAPElementProperty("Height", Height.ToString(), true));

                    // _Rectangle = new Rectangle(ScreenLeft, ScreenTop, Width, Height);
                    Properties = properties.ToArray();
                }

                if (string.IsNullOrEmpty(Path))
                {
                    var children = new List <SAPEventElement>();
                    if (string.IsNullOrEmpty(Cell) && loadChildren)
                    {
                        for (var i = 0; i < grid.RowCount; i++)
                        {
                            var _msg = new SAPEventElement(comp, SystemName, all, i.ToString(), null, Flat, true, MaxItem);
                            //var _msg = new SAPEventElement(comp, SystemName, Parent, false);
                            children.Add(_msg);
                            if (MaxItem > 0)
                            {
                                if (children.Count >= MaxItem)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    Children = children.ToArray();
                }
                else if (loadChildren)
                {
                    var children = new List <SAPEventElement>();
                    var keys     = grid.ColumnOrder as SAPFEWSELib.GuiCollection;
                    foreach (string key in keys)
                    {
                        var _msg = new SAPEventElement(comp, SystemName, all, Path, key, Flat, false, MaxItem);
                        children.Add(_msg);
                        if (MaxItem > 0)
                        {
                            if (children.Count >= MaxItem)
                            {
                                break;
                            }
                        }
                    }
                    Items = children.ToArray();
                }
            }
            else if (comp.ContainerType)
            {
                if (comp is SAPFEWSELib.GuiVContainer vcon && loadChildren)
                {
                    var children = new List <SAPEventElement>();
                    for (var i = 0; i < vcon.Children.Count; i++)
                    {
                        SAPFEWSELib.GuiComponent Element = vcon.Children.ElementAt(i);
                        var p         = Element.Parent as SAPFEWSELib.GuiComponent;
                        var parent    = (p != null) ? p.Id : null;
                        var _newchild = new SAPEventElement(Element, SystemName, parent, false);
                        children.Add(_newchild);
                        if (MaxItem > 0)
                        {
                            if (children.Count >= MaxItem)
                            {
                                break;
                            }
                        }
                    }
                    Children = children.ToArray();
                }
                else if (comp is SAPFEWSELib.GuiContainer con && loadChildren)
                {
                    var children = new List <SAPEventElement>();
                    for (var i = 0; i < con.Children.Count; i++)
                    {
                        SAPFEWSELib.GuiComponent Element = con.Children.ElementAt(i);
                        var p      = Element.Parent as SAPFEWSELib.GuiComponent;
                        var parent = (p != null) ? p.Id : null;
                        children.Add(new SAPEventElement(Element, SystemName, parent, false));
                        if (MaxItem > 0)
                        {
                            if (children.Count >= MaxItem)
                            {
                                break;
                            }
                        }
                    }
                    Children = children.ToArray();
                }