private async void btn_ShowAll_Click(object sender, RoutedEventArgs e) { _lastHighlight = null; try { _isExpand = false; xDoc = new XmlDocument(); XmlElement root = xDoc.CreateElement("Node"); root.SetAttribute("name", "root"); Task loopNodeTask = new Task(() => { var comp = SAPAutomationHelper.Current.SAPGuiSession as GuiComponent; //WrapComp comp = new WrapComp() { Comp = SAPAutomationHelper.Current.SAPGuiSession as GuiComponent }; SAPAutomationHelper.Current.LoopSAPComponents <XmlElement>(comp, root, 0, _maxCount, addNode); xDoc.AppendChild(root.FirstChild); }); //setWorking(true); loopNodeTask.Start(); await loopNodeTask; tv_Elements.DataContext = xDoc; //setWorking(false); } catch (Exception ex) { //setWorking(false); MessageBox.Show(ex.Message); } }
public static void HighLight(this GuiComponent comp) { GuiVComponent vComp = comp as GuiVComponent; if (vComp != null) { vComp.Visualize(true); } }
private static bool isMatch(GuiFrameWindow window, GuiVComponent comp, int X1, int Y1, int X2, int Y2) { int x1 = comp.ScreenLeft - window.ScreenLeft; int y1 = comp.ScreenTop - window.ScreenTop; int x2 = x1 + comp.Width; int y2 = y1 + comp.Height; if (x1 >= X1 && y1 >= Y1 && x2 <= X2 && y2 <= Y2) { return(true); } return(false); }
void _sapGuiSession_Change(GuiSession Session, GuiComponent Component, object CommandArray) { if (_currentScreen != null) { SAPGuiElement comp = new SAPGuiElement() { Id = Component.Id, Type = Component.Type, Name = Component.Name, }; GuiVComponent vC = Component as GuiVComponent; if (vC != null) { comp.Left = vC.Left; comp.Top = vC.Top; comp.Width = vC.Width; comp.Height = vC.Height; comp.AbsoluteLeft = vC.ScreenLeft - _sapGuiSession.ActiveWindow.ScreenLeft; comp.AbsoluteTop = vC.ScreenTop - _sapGuiSession.ActiveWindow.ScreenTop; } object[] objs = CommandArray as object[]; objs = objs[0] as object[]; switch (objs[0].ToString().ToLower()) { case "m": comp.Action = BindingFlags.InvokeMethod; break; case "sp": comp.Action = BindingFlags.SetProperty; break; } var action = objs[1].ToString(); upperFirstChar(ref action); comp.ActionName = action; var count = objs.Count(); if (count > 2) { comp.ActionValues = new object[count - 2]; for (int i = 2; i < count; i++) { comp.ActionValues[i - 2] = objs[i]; } } _currentScreen.SAPGuiElements.Add(comp); } }
private void tv_Elements_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { try { XmlElement element = tv_Elements.SelectedItem as XmlElement; GuiVComponent comp = SAPAutomationHelper.Current.GetSAPComponentById <GuiVComponent>(element.GetAttribute("id")); if (_lastHighlight != null) { _lastHighlight.Visualize(false); } _lastHighlight = comp; _lastHighlight.Visualize(true); } catch { } }
public static void SetFocus(string id, GuiVComponent component, GuiSession session) { if (component == null && string.IsNullOrEmpty(id)) { throw new Exception("Parameters for the Target object not provided: id or GuiVComponent object"); } if (session == null) { throw new Exception("SAP session parameter is required and was not provided."); } if (component == null) { component = (GuiVComponent)(session).FindById(id); } component.SetFocus(); }
public static void SetText(string id, GuiVComponent component, GuiSession session, string text) { //string name = this.Name.Get(context); //object[] args = { name, typeof(TargetType).Name }; //((GuiVComponent)(typeof(SourceType).InvokeMember("FindByName", BindingFlags.InvokeMethod, null, this.Source.Get(context), args))).Text = this.Text.Get(context); if (component == null && string.IsNullOrEmpty(id)) { throw new Exception("Parameters for the Target object not provided: id or GuiVComponent object"); } if (session == null) { throw new Exception("SAP session parameter is required and was not provided."); } if (component == null) { component = (GuiVComponent)(session).FindById(id); } component.Text = text; }
public ClassVariableColumnIndexDefinition(GuiTableControl table, ClassVariableColumnNameDefinition definition) { for (int i = 0; i < table.Columns.Count; i++) { GuiVComponent component = table.GetCell(i, 0); string columnName = component.Name; if (columnName.Equals(definition.GetTypingColumn())) { typingIndex = i; } if (columnName.Equals(definition.GetTypingColumn())) { typeIndex = i; } if (columnName.Equals(definition.GetTypingColumn())) { visibilityIndex = i; } if (columnName.Equals(definition.GetTypingColumn())) { nameIndex = i; } } }
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()); } }
public void OnFocusChanged(GuiSession session, GuiVComponent newFocusedComponent) { System.Diagnostics.Debug.WriteLine(session.ToString()); // output.WriteLine(session.ToString()); }
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()); } }
private void DelegateOnFocusChanged(SAPFEWSELib.GuiSession currentSession, GuiVComponent newFocusedControl) { FocusChanged?.Invoke(GetSession(), newFocusedControl); }
public GuiVComponent GetInFocus() { GuiVComponent focus = session.ActiveWindow.GuiFocus; return(focus); }