public GuiSession GetSession() { CSapROTWrapper sapRotWrapper = new CSapROTWrapper(); object sapGuilRot = sapRotWrapper.GetROTEntry("SAPGUI"); if (sapGuilRot == null) { throw new NoSapGuiFoundException("No rot object found - is Sap Gui running?"); } object engine = sapGuilRot.GetType().InvokeMember( "GetScriptingEngine", BindingFlags.InvokeMethod, null, sapGuilRot, null); if (engine == null) { throw new NoSapGuiFoundException("no engine - wie kann das sein?"); } GuiApplication sapGuiApp = engine as GuiApplication; GuiConnection connection = sapGuiApp?.Children.Cast <GuiConnection>().ElementAt(index); if (connection == null) { throw new NoSapGuiFoundException("no connection - Are you logged into any system?"); } foreach (SAPFEWSELib.GuiSession session in connection.Sessions) { return(new SapGuiSession(session)); } return(null); }
private void ep_Session_Expanded(object sender, RoutedEventArgs e) { _app = null; try { _app = SAPTestHelper.GetSAPGuiApp(1); List <SAPSessionVM> sessions = new List <SAPSessionVM>(); for (int i = 0; i < _app.Children.Count; i++) { GuiConnection cn = _app.Children.ElementAt(i) as GuiConnection; for (int j = 0; j < cn.Children.Count; j++) { GuiSession s = cn.Children.ElementAt(j) as GuiSession; if (!s.Busy) { sessions.Add(new SAPSessionVM() { Id = s.Id, System = s.Info.SystemName, Transaction = s.Info.Transaction }); } } } lv_Sessions.ItemsSource = sessions; } catch { } }
public void OpenConnection(string server, int secondsOfTimeout = 10) { if (System.Threading.Monitor.TryEnter(_lockObj, 1000)) { try { var Application = SAPHook.Instance.app; try { Application.OpenConnectionByConnectionString(server); } catch (Exception ex) { throw new Exception("Open Connection Failed, is ip/fqdn correct? is server alive and running? " + ex.Message); } var index = Application.Connections.Count - 1; this.Connection = Application.Children.ElementAt(index) as GuiConnection; index = Connection.Sessions.Count - 1; if (Connection.Sessions.Count == 0) { throw new Exception("New session not found, did you forget to enable scripting on the server side ?"); } this.Session = Connection.Children.Item(index) as GuiSession; } finally { System.Threading.Monitor.Exit(_lockObj); } } }
public static GuiSession GetCurrentSession() { GuiConnection connection = SAPGui.GetConnection(); GuiSession session = connection.Children.ElementAt(0) as GuiSession; return(session); }
public static GuiSession NewSession(GuiSession currentSession) { if (currentSession == null) { currentSession = GetCurrentSession(); } GuiConnection connection = SAPGui.GetConnection(); int currNumSessions = connection.Children.Count; GuiSession session = currentSession; session.CreateSession(); System.Threading.Thread.Sleep(500); int count = 0; while (connection.Children.Count <= currNumSessions && count < 20) { System.Threading.Thread.Sleep(500); count++; connection = SAPGui.GetConnection(); } return(connection.Children.ElementAt(connection.Children.Count - 1) as GuiSession); }
public void SetSession(GuiApplication application, GuiConnection connection, GuiSession session) { this._sapGuiApplication = application; this._sapGuiConnection = connection; this._sapGuiSession = session; _currentScreen = new ScreenData(session.Info.SystemName, session.Info.Transaction, session.Info.Program, session.Info.ScreenNumber, session.ActiveWindow.Text); hookSessionEvent(); }
public static void testConnection() { SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper(); object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI"); object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null); GuiConnection connection = (engine as GuiApplication).OpenConnection("BOX DESCRIPTION"); GuiSession session = connection.Children.ElementAt(0) as GuiSession; }
public static T FindDescendantByProperty <T>(this GuiConnection Connection, Func <T, bool> Property = null) where T : class { if (Property == null) { Property = new Func <T, bool>(t => true); } return(findDescendantByPropertyTemplate <T>(Connection.Children, Property)); }
public static void KeepOneSessionSAP() { GuiConnection connection = SAPGui.GetConnection(); for (int count = connection.Sessions.Count - 1; count > 0; count--) { connection.CloseSession(connection.Sessions.ElementAt(count).Id); } }
public void OpenConnection(string server, int secondsOfTimeout = 10) { lock (_lockObj) { _sapGuiApplication = GetSAPGuiApp(secondsOfTimeout); _sapGuiApplication.OpenConnectionByConnectionString(server); var index = _sapGuiApplication.Connections.Count - 1; this._sapGuiConnection = _sapGuiApplication.Children.ElementAt(index) as GuiConnection; index = _sapGuiConnection.Sessions.Count - 1; this._sapGuiSession = _sapGuiConnection.Children.Item(index) as GuiSession; } }
public static GuiSession GetObjSessionById(string id) { CSapROTWrapper sapROTWrapper = new CSapROTWrapper(); object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI"); object engine = SapGuilRot.GetType().InvokeMember("GetSCriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null); GuiConnection connection = (engine as GuiApplication).Connections.ElementAt(0) as GuiConnection; GuiSession session = connection.FindById(id) as GuiSession; return(session); }
public void OpenConnection(string server, int secondsOfTimeout = 10) { lock (_lockObj) { var Application = SAPHook.Instance.app; Application.OpenConnectionByConnectionString(server); var index = Application.Connections.Count - 1; this.Connection = Application.Children.ElementAt(index) as GuiConnection; index = Connection.Sessions.Count - 1; if (Connection.Sessions.Count == 0) { throw new Exception("New session not found, did you forget to enable scripting on the server side ?"); } this.Session = Connection.Children.Item(index) as GuiSession; } }
public ActiveSession() { GetApplication().CreateSession += delegate(SAPFEWSELib.GuiSession session) { session.StartRequest += DelegateOnStartRequest; session.FocusChanged += DelegateOnFocusChanged; }; GuiConnection connection = GetApplication().Children.Cast <GuiConnection>().FirstOrDefault(); if (connection != null) { foreach (SAPFEWSELib.GuiSession session in connection?.Sessions) { session.StartRequest += DelegateOnStartRequest; session.FocusChanged += DelegateOnFocusChanged; } } }
private (IMethod method, IMethodOptions methodOptions) PrepareToSolve(CancellationToken token) { var(methodType, methodOptionType) = algorithms[AlgorithmChangeComboBox.SelectedIndex]; var method = Activator.CreateInstance(methodType) as IMethod; methodOptions = Activator.CreateInstance(methodOptionType) as IMethodOptions; methodOptions.Data = data; var userDefinedOptions = methodOptionType.GetProperties().Where(x => x.GetCustomAttribute(typeof(UserDefined)) != null).ToList(); var guiConnection = new GuiConnection(); foreach (var option in userDefinedOptions) { var userDefined = option.GetCustomAttribute(typeof(UserDefined)) as UserDefined; var value = FindValueInDataGridView(userDefined.ParameterFormalName); if (option.Name.Equals("ShouldLogText") && (bool)value) { guiConnection.LogText = LogText; } if (option.Name.Equals("ShouldLogGraphics") && (bool)value) { guiConnection.LogGraphics = LogGraphics; } if (option.PropertyType.IsEnum) { value = Enum.Parse(userDefined.Type, value.ToString()); } else { if (value.GetType() != option.PropertyType) { value = Convert.ChangeType(value, option.PropertyType); } option.SetValue(methodOptions, value); } } methodOptions.GuiConnection = guiConnection; methodOptions.CancellationToken = token; methodOptions = method.Prepare(methodOptions); return(method, methodOptions); }
public void SetSession(string BoxName) { var application = SAPTestHelper.GetSAPGuiApp(); GuiConnection connection = null; GuiSession session = null; int index = application.Connections.Count - 1; if (index < 0) { throw new Exception("No SAP GUI Connections found"); } for (int i = 0; i < application.Children.Count; i++) { var con = application.Children.ElementAt(i) as GuiConnection; index = con.Sessions.Count - 1; if (index < 0) { throw new Exception("No SAP GUI Session Found"); } for (int j = 0; j < con.Sessions.Count; j++) { var ses = con.Children.ElementAt(j) as GuiSession; if (ses.Info.SystemName.ToLower() == BoxName.ToLower()) { session = ses; break; } } if (session != null) { connection = con; break; } } if (session != null) { SetSession(application, connection, session); } else { throw new Exception("No SAP GUI Session Found"); } }
public ConnectionStateSegmented( GuiConnection c ) { conn = c; }
public static void DestroySession(object currentSession) { GuiConnection connection = SAPGui.GetConnection(); connection.CloseSession((currentSession as GuiSession).Id); }
public static IEnumerable <T> FindDescendantsByProperty <T>(this GuiConnection Connection, Func <T, bool> Property = null) where T : class { return(findDescendantsByPropertyTemplate <T>(Connection.Children, Property)); }
public void NewRelation( UmlRelation rel ) { GuiClass c1 = FindClass(rel.src), c2 = FindClass(rel.dest); if( c1 != null && c2 != null ) { int ux1 = 1, ux2 = 3; float uy1 = .5f, uy2 = .5f; if( rel.type == UmlRelationType.Association ) { ux1 = 0; uy1 = c1.get_empty_point_on_edge( ux1 ); ux2 = 2; uy2 = c2.get_empty_point_on_edge( ux2 ); } else if( rel.type == UmlRelationType.Realization || rel.type == UmlRelationType.Inheritance ) { uy2 = c2.get_empty_point_on_edge( ux2 ); } GuiConnection c = new GuiConnection( new GuiConnectionPoint( c1, ux1, uy1, 0 ), new GuiConnectionPoint( c2, ux2, uy2, 1 ), rel.type, this, rel.type == UmlRelationType.Attachment ? GuiConnectionStyle.Line : MouseAgent.conn_style ); if( rel.type == UmlRelationType.Association ) c.nav = GuiConnectionNavigation.Left; c.relation_id = rel.ID; c.first.UpdatePosition( true ); c.second.UpdatePosition( true ); c.DoCreationFixup(); c.ConnectionCreated( this, rel.src_role, rel.dest_role, rel.name, rel.stereo ); Undo.Push( new CreateOperation( c ), false ); } }
private void btn_run_Click(object sender, EventArgs e) { if (tb_id.Text == "" || tb_plant.Text == "") { return; } if (tb_id.TextLength > 4) { MessageBox.Show("ID item not valid", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (tb_plant.TextLength != 4) { MessageBox.Show("Centro inválido", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //INICIAR ALTERAÇÃO #region if (dataGridView1.RowCount == 1) { return; } try { //Get the Windows Running Object Table SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper(); //Get the ROT Entry for the SAP Gui to connect to the COM object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI"); //Get the reference to the Scripting Engine object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null); //Get the reference to the running SAP Application Window GuiApplication GuiApp = (GuiApplication)engine; //Get the reference to the first open connection GuiConnection connection = (GuiConnection)GuiApp.Connections.ElementAt(0); //get the first available session GuiSession session = (GuiSession)connection.Children.ElementAt(0); //Get the reference to the main "Frame" in which to send virtual key commandss //GuiFrameWindow frame = session.ActiveWindow; GuiFrameWindow frame = (GuiFrameWindow)session.FindById("wnd[0]"); //((GuiFrameWindow)frame.FindById("wnd[0]")); ((GuiOkCodeField)frame.FindById("wnd[0]/tbar[0]/okcd")).Text = "/nztvc025"; frame.SendVKey(0); int linhas1 = dataGridView1.RowCount; int i; ((GuiTextField)frame.FindById("wnd[0]/usr/ctxtP_PRFID")).Text = "0001"; ((GuiTextField)frame.FindById("wnd[0]/usr/ctxtP_WERKS")).Text = tb_plant.Text; for (i = 0; i < linhas1 - 1; i++) { try { ((GuiButton)frame.FindByName("btn[8]", "GuiButton")).Press(); string material = dataGridView1.Rows[i].Cells[0].Value.ToString(); int tam = material.Length; string component1 = dataGridView1.Rows[i].Cells[1].Value.ToString(); if (tam == 11) { ((GuiTextField)session.ActiveWindow.FindById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[1,21]")).Text = material; } else { ((GuiTextField)session.ActiveWindow.FindById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]")).Text = material; } ((GuiButton)frame.FindByName("btn[0]", "GuiButton")).Press(); ((GuiToolbarControl)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[0]")).PressButton("&FIND"); ((GuiTextField)session.ActiveWindow.FindById("wnd[1]/usr/txtLVC_S_SEA-STRING")).Text = tb_id.Text.ToString(); ((GuiButton)frame.FindByName("btn[0]", "GuiButton")).Press(); ((GuiButton)frame.FindByName("btn[0]", "GuiButton")).Press(); if (session.Children.Count != 2) { dataGridView1.Rows[i].Cells[2].Value = "N/A"; goto acabou; } ((GuiButton)frame.FindByName("btn[0]", "GuiButton")).Press(); for (int j = 1; j < 100; j++) { string esp; if (j < 10) { esp = " "; } else { esp = " "; } ((GuiTree)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[1]")).SelectItem(esp + j, "&Hierarchy"); ((GuiTree)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[1]")).EnsureVisibleHorizontalItem(esp + j, "&Hierarchy"); ((GuiTree)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[1]")).DoubleClickItem(esp + j, "&Hierarchy"); if (((GuiCTextField)session.ActiveWindow.FindByName("ZTBVC_657-ID_ITEM", "GuiCTextField")).Text == tb_id.Text.ToString()) { ((GuiToolbarControl)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[0]")).PressButton("EDIT_ESP"); ((GuiTextField)frame.FindById("wnd[0]/usr/subSUBSCR_ESPEC:SAPLZRVC_ZBOM_POS_ESP:0300/subSUBSCR_ESP:SAPLZRVC_ZBOM_POS_ESP:0340/ctxtZTBVC_658-IDNRK")).Text = component1; ((GuiButton)frame.FindByName("btn[8]", "GuiButton")).Press(); dataGridView1.Rows[i].Cells[2].Value = "OK"; break; } } acabou : ((GuiButton)frame.FindByName("btn[2]", "GuiButton")).Press(); } catch { ((GuiButton)frame.FindByName("btn[2]", "GuiButton")).Press(); } #endregion } MessageBox.Show("Alteração Concluída", "Alteração Concluída", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } catch { MessageBox.Show("Erro ao conectar com SAP", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public void OpenConnection(string server, int secondsOfTimeout = 10) { _sapGuiApplication = SAPTestHelper.GetSAPGuiApp(secondsOfTimeout); _sapGuiApplication.OpenConnectionByConnectionString(server); var index = _sapGuiApplication.Connections.Count - 1; this._sapGuiConnection = _sapGuiApplication.Children.ElementAt(index) as GuiConnection; index = _sapGuiConnection.Sessions.Count - 1; this._sapGuiSession = _sapGuiConnection.Children.Item(index) as GuiSession; }
public static T FindById <T>(this GuiConnection Connection, string Id) where T : class { return(findByIdTemplate <T>(Id, Connection.FindById)); }
public SAPGuiSession(SAPLogon logon) { this.app = logon.Application; this.connection = logon.Connection; this.session = logon.Session; }
public bool validate_connection( IAcceptConnection obj, GuiConnection connection ) { return true; }
public ConnectionStateQuadric( GuiConnection c ) { conn = c; }
public override void MouseDown( int x, int y, MouseButtons b, Keys modif, int realx, int realy ) { // Left mouse button if( action != MouseAction.None ) return; if( b == MouseButtons.Left ) { if( current_operation == MouseOperation.DrawComment || current_operation == MouseOperation.DrawPackage ) { switch( current_operation ) { case MouseOperation.DrawComment: moveitem = GuiElementFactory.CreateMemo( parent, x, y ); break; case MouseOperation.DrawPackage: moveitem = GuiElementFactory.CreatePackage( parent, x, y ); break; } first_move = true; moveux = 0; moveuy = 0; action = MouseAction.Move; } else if( (modif & Keys.Control) == Keys.Control || current_operation == MouseOperation.DrawConnection ) { conn_item = parent.FindItem( x, y, out moveux, out moveuy, true ) as IAcceptConnection; if( conn_item == null ) { action = MouseAction.Scroll; selx = x; sely = y; return; } int ux; float uy; conn_item.coord_nearest( x, y, out ux, out uy ); action = MouseAction.CreateConnection; conn = new GuiConnection( new GuiConnectionPoint( conn_item, ux, uy, 0 ), new GuiConnectionPoint( x, y, 1 ), conn_type, parent, conn_type == UmlRelationType.Attachment ? GuiConnectionStyle.Line : conn_style ); conn.first.item.coord_nearest( x, y, out conn.first.ux, out conn.first.uy ); conn.first.UpdatePosition( true ); conn.DoCreationFixup(); conn.InvalidateTemporary(); conn.Invalidate(); } else if( ( modif & Keys.Shift) == Keys.Shift ) { GuiObject obj = parent.FindItem( x, y, false ); if( obj != null ) { parent.SelectedObjects.Add( obj ); obj.Invalidate(); } } else { // Left button click: // select // move, move multiple GuiObject s = parent.FindItem( x, y, out moveux, out moveuy, false ); if( s == null ) { parent.SelectedObjects.Clear(); action = MouseAction.Select; selx = x; sely = y; return; } if( !s.selected ) { parent.SelectedObjects.Clear(); parent.SelectedObjects.Add( s ); } // deciding: to move, or not ... moveitem = null; movelist = null; movestates.Clear(); original_selected = null; GuiObject t = parent.FindItem( x, y, out moveux, out moveuy, true ); if( t != null ) { if( t is IMoveRedirect ) { if( t.selected ) original_selected = t; moveitem = (t as IMoveRedirect).MoveRedirect( ref moveux, ref moveuy ); } else if( t is IMoveMultiple && (t as IMoveMultiple).CanMoveInGroup ) { movelist = new ArrayList(); if( !t.selected ) movelist.Add( t ); foreach( GuiObject o in parent.SelectedObjects ) if( o is IMoveMultiple && (o as IMoveMultiple).CanMoveInGroup ) movelist.Add( o ); selx = x; sely = y; } else if( t is IMoveable && (t as IMoveable).IsMoveable( x, y ) ) moveitem = t as IMoveable; if( moveitem != null || movelist != null ) { first_move = true; action = MouseAction.Move; } else if( t is IClickable ) { (t as IClickable).LeftClick( false, x, y ); } } } } else if( b == MouseButtons.Right ) { ISelectable obj = parent.FindItem( x, y, true ) as ISelectable; if( obj != null ) { if( obj is IDropMenu ) { parent.SelectedObjects.Clear(); parent.SelectedObjects.Add( obj as GuiObject ); System.Windows.Forms.ContextMenu m = new ContextMenu(); (obj as IDropMenu).AddMenuItems( m, x, y ); if( m.MenuItems.Count > 0 ) m.Show( parent.cview, new Point( realx, realy ) ); } } else { action = MouseAction.Scroll; Cursor.Current = Cursors.Hand; selx = x; sely = y; menurealx = realx; menurealy = realy; first_move = true; } } }
/// <summary> /// This function will login into the SAP with provided credentials(same as manual login) /// </summary> /// <param name="SapSession"></param> /// <param name="myclient"></param> /// <param name="mylogin"></param> /// <param name="mypass"></param> /// <param name="mylang"></param> public string login(string servername, string myclient, string mylogin, System.Security.SecureString mypass, string mylang) { //GuiApplication appSAP = (GuiApplication)Marshal.GetActiveObject("SAPGUI"); //GuiConnection connSAP = appSAP.OpenConnection(server, Sync: true); //GuiSession SapSession = (GuiSession)connSAP.Sessions.Item(0); // System.IO.StreamWriter m_fswLogFile; //DateTime m_dtLastTimeLog = DateTime.MinValue; //int m_intTimeLogInterVal; //String strFilePath = "D:\\AA_Log_SAPAUto_Metabot.txt"; //if (!System.IO.File.Exists(strFilePath)) { // System.IO.File.Create(strFilePath).Close(); //} ////Open the log file //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true); //m_fswLogFile.AutoFlush = true; //m_fswLogFile.WriteLine("Parameters"); //m_fswLogFile.WriteLine(server); //m_fswLogFile.WriteLine(mylogin); //m_fswLogFile.WriteLine(mypass); //m_fswLogFile.WriteLine(mylang); //m_fswLogFile.WriteLine(SAPWindowName); //m_fswLogFile.Close(); //m_fswLogFile = null; //Close the SAP if its opened, then open the new process KillProcess("saplogon"); //Set the Exe Path and SAP Window name string strSAPLoginPadPath = @"C:\Program Files (x86)\SAP\FrontEnd\SapGui\saplogon.exe"; FileVersionInfo fi2 = FileVersionInfo.GetVersionInfo(strSAPLoginPadPath); string strVersion = fi2.ProductVersion.Substring(0, 3); String strloginWindowName = "SAP Logon " + strVersion; //Open the SAP Logon Window StartProcess(strSAPLoginPadPath); //Wait for the window to be loaded. System.Threading.Thread.Sleep(1000); AutomationElement desktop = AutomationElement.RootElement; AutomationElement ele = null; while (ele is null) { try { ele = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, strloginWindowName)); } catch { } } CSapROTWrapper sapROTWrapper = new CSapROTWrapper(); object rot = sapROTWrapper.GetROTEntry("SAPGUI"); object engine = rot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, rot, null); GuiConnection connection = (engine as GuiApplication).OpenConnection(servername); GuiSession SapSession = connection.Children.ElementAt(0) as GuiSession; //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true); //m_fswLogFile.AutoFlush = true; //m_fswLogFile.WriteLine("Going to get the controls for login"); //m_fswLogFile.Close(); //m_fswLogFile = null; GuiTextField client = (GuiTextField)SapSession.ActiveWindow.FindByName("RSYST-MANDT", "GuiTextField"); GuiTextField login = (GuiTextField)SapSession.ActiveWindow.FindByName("RSYST-BNAME", "GuiTextField"); GuiTextField pass = (GuiTextField)SapSession.ActiveWindow.FindByName("RSYST-BCODE", "GuiPasswordField"); GuiTextField language = (GuiTextField)SapSession.ActiveWindow.FindByName("RSYST-LANGU", "GuiTextField"); //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true); //m_fswLogFile.AutoFlush = true; //m_fswLogFile.WriteLine("Enter credentials for login"); //m_fswLogFile.Close(); //m_fswLogFile = null; client.SetFocus(); client.Text = myclient; login.SetFocus(); login.Text = mylogin; pass.SetFocus(); pass.Text = new System.Net.NetworkCredential(string.Empty, mypass).Password; language.SetFocus(); language.Text = mylang; //m_fswLogFile = new System.IO.StreamWriter(strFilePath, true); //m_fswLogFile.AutoFlush = true; //m_fswLogFile.WriteLine("click login"); //m_fswLogFile.Close(); //m_fswLogFile = null; //Press the green checkmark button which is about the same as the enter key GuiButton btn = (GuiButton)SapSession.FindById("/app/con[0]/ses[0]/wnd[0]/tbar[0]/btn[0]"); btn.SetFocus(); btn.Press(); //Validate whether the login successfull or Not //If the error is "Already logged in by the same user, then click GuiStatusbar statusBar = (GuiStatusbar)SapSession.FindById("wnd[0]/sbar"); string strMsg = statusBar.Text; string strMsgType = statusBar.MessageType; if (strMsg.Contains("User already logged on at another terminal") == true || strMsg.Contains("用户已经登录到其它终端") == true)//(strMsg == "W" || strMsgType == "E" ) //'Warning or Error { //Check whether is it showing the same terminal or different terminal string strWinText = ((GuiFrameWindow)SapSession.FindById("wnd[1]")).Text; strWinText = Environment.MachineName; if (strWinText.Contains(Environment.MachineName) == true) { //This represents, the login in the same machine, then click continue with current login option ((GuiRadioButton)SapSession.FindById("wnd[1]/usr/radMULTI_LOGON_OPT1")).Select(); ((GuiButton)SapSession.FindById("wnd[1]/tbar[0]/btn[0]")).Press(); } else { SapSession.ActiveWindow.Close(); return("SAP Error while logging in the SAP system, Error:\n" + strMsg); } } else if (strMsg.Length > 0 && strMsgType == "E") { SapSession.ActiveWindow.Close(); return("SAP Error while logging in the SAP system, Error:\n" + strMsg); } return("success"); }
public ConnectionStateLine( GuiConnection c ) { conn = c; }
public string login_SSO(string servername) { //Close the SAP if its opened, then open the new process KillProcess("saplogon"); //Set the Exe Path and SAP Window name string strSAPLoginPadPath = @"C:\Program Files (x86)\SAP\FrontEnd\SapGui\saplogon.exe"; FileVersionInfo fi2 = FileVersionInfo.GetVersionInfo(strSAPLoginPadPath); string strVersion = fi2.ProductVersion.Substring(0, 3); String strloginWindowName = "SAP Logon " + strVersion; //Start SAP Login Window StartProcess(strSAPLoginPadPath); //Wait for the window to be loaded. System.Threading.Thread.Sleep(1000); AutomationElement desktop = AutomationElement.RootElement; AutomationElement ele = null; while (ele is null) { try { ele = desktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, strloginWindowName)); } catch { } } CSapROTWrapper sapROTWrapper = new CSapROTWrapper(); object rot = sapROTWrapper.GetROTEntry("SAPGUI"); object engine = rot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, rot, null); GuiConnection connection = (engine as GuiApplication).OpenConnection(servername); GuiSession SapSession = connection.Children.ElementAt(0) as GuiSession; //Validate whether the login successfull or Not //If the error is "Already logged in by the same user, then click GuiStatusbar statusBar = (GuiStatusbar)SapSession.FindById("wnd[0]/sbar"); string strMsg = statusBar.Text; string strMsgType = statusBar.MessageType; if (strMsg.Contains("User already logged on at another terminal") == true || strMsg.Contains("用户已经登录到其它终端") == true)//(strMsg == "W" || strMsgType == "E" ) //'Warning or Error { //Check whether is it showing the same terminal or different terminal string strWinText = ((GuiFrameWindow)SapSession.FindById("wnd[1]")).Text; strWinText = Environment.MachineName; if (strWinText.Contains(Environment.MachineName) == true) { //This represents, the login in the same machine, then click continue with current login option ((GuiRadioButton)SapSession.FindById("wnd[1]/usr/radMULTI_LOGON_OPT1")).Select(); ((GuiButton)SapSession.FindById("wnd[1]/tbar[0]/btn[0]")).Press(); } else { //SapSession.ActiveWindow.Close(); throw new Exception("SAP Error while logging in the SAP system, Error:\n" + strMsg); } } else if (strMsg.Length > 0 && strMsgType == "E") { //SapSession.ActiveWindow.Close(); throw new Exception("SAP Error while logging in the SAP system, Error:\n" + strMsg); } return("success"); }
public static T FindChildByProperty <T>(this GuiConnection Connection, Func <T, bool> Property = null) where T : class { return(findChildByPropertyTemplate <T>(Connection.Children, Property)); }
public override void MouseUp(MouseButtons b) { if( scroll_active ) { StopScrolling(); } parent.SetDefaultDrawingMode(); original_selected = null; switch( action ) { case MouseAction.Scroll: Cursor.Current = Cursors.Arrow; if( first_move ) { System.Windows.Forms.ContextMenu m = new ContextMenu(); parent.AddMenuItems( m ); if( m.MenuItems.Count > 0 ) m.Show( parent.cview, new Point( menurealx, menurealy ) ); } break; case MouseAction.CreateConnection: if( conn.second.item == null ) conn.Invalidate(); else { conn.ConnectionCreated( parent, null, null, null, null ); parent.Undo.Push( new CreateOperation( conn ), false ); } conn = null; break; case MouseAction.Move: ArrayList movedobjects = new ArrayList(); foreach( GuiObject o in movestates.Keys ) if( o is IAroundObject ) movedobjects.Add( o ); if( movedobjects.Count > 0 ) parent.AroundObjectsMoved( movedobjects, movestates ); foreach( IMoveable o in movestates.Keys ) o.Moved(); if( movestates.Count == 1 ) { foreach( IStateObject t in movestates.Keys ) parent.Undo.Push( new StateOperation( t, movestates[t] as ObjectState, t.GetState() ), false ); } else if( movestates.Count > 1 ) { MultipleOperation p = new MultipleOperation(); foreach( IStateObject t in movestates.Keys ) p.l.Add( new StateOperation( t, movestates[t] as ObjectState, t.GetState() ) ); parent.Undo.Push( p, false ); } movestates.Clear(); moveitem = null; movelist = null; break; case MouseAction.Select: parent.SelectedObjects.Clear(); parent.SelectInRectangle( selrect ); parent.cview.InvalidatePage( selrect ); selrect = Rectangle.Empty; break; } action = MouseAction.None; }
public string GetConnectionIndex() { GuiConnection connection = (GuiConnection)session.Parent; return(connection.Name); }