/// <summary> /// Open a Connection /// </summary> /// <param name="username"></param> /// <param name="password"></param> public override void OnOpenConnection(string username, SecureString password) { try { if (_sessionWindow == null) { throw new ProtocolException(beRemoteExInfoPackage.MajorInformationPackage, "Telnet not initialized!"); } if (SessionWindow.IsSendInputRegistered == false) { SessionWindow.SendInput += SessionWindowSendInput; } //Load the configuration _TelnetTimeout = Convert.ToInt32(GetSessionSettings()["telnet.timeout"].GetProtocolSettingValue().GetValue()); try { //Create Telnet Connection _TelConnection = new TelnetInterface(GetSessionServer().GetRemoteIP().ToString(), GetProtocolPort()); } catch (Exception ea) { Logger.Log(LogEntryType.Warning, "Cannot connect to Telnet-Server.", ea); WriteDisplayText(Environment.NewLine + "***Cannot connect to Telnet-Server."); WriteDisplayText(Environment.NewLine + ea.Message); return; } var telAnswer = ""; //Login, if there is a password given (try autologin) try { if (password != null && password.Length > 0) { telAnswer = _TelConnection.Login(username, Helper.ConvertToUnsecureString(password), _TelnetTimeout); } } catch (Exception ea) { Logger.Log(LogEntryType.Info, "Cannot Login to Telnet-Server", ea); WriteDisplayText(Environment.NewLine + "***Cannot connect to Telnet-Server. Try it without predefined credentials."); WriteDisplayText(Environment.NewLine + ea.Message); } //Show output WriteDisplayText(telAnswer); //Start the ReadInput-Loop ReadSessionInput(); } catch (Exception ea) { Logger.Log(LogEntryType.Warning, "An unknown error occures on starting telnet-session", ea); } }
/// <summary> /// Close the current Connection /// </summary> public override void CloseConnection() { if (_TelConnection.IsConnected) { _TelConnection.WriteLine("exit"); } _TelConnection = null; // Triggering upper close connection event! TriggerCloseConnectionEvent(); CloseTab(); }