Conductor.Components.TelnetConnection InitializeServer() { LogEvent("Starting new process"); Process process = new Process(); process.StartInfo.CreateNoWindow = true; process.StartInfo.Arguments = "-s"; process.StartInfo.FileName = Path.Combine(ExePath(), this.Profile.ExeName); if (!File.Exists(process.StartInfo.FileName)) { return(null); } process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); int tryCount = 1; int maxTry = 10; Conductor.Components.TelnetConnection connection = null; while (tryCount < maxTry) { connection = GetConnection(false); if (connection != null) { return(connection); } System.Threading.Thread.Sleep(500); tryCount++; LogEvent("Waiting for server to become available...cycle " + tryCount.ToString()); } LogEvent("Unable to acquire a connection within " + maxTry.ToString() + " attempts."); return(null); }
bool TryConnect(bool ForceNew = false) { if (_tc == null || !_tc.IsConnected || ForceNew) { if (_tc != null) { _tc.DataReceived -= _tc_DataReceived; } // MessageBox.Show("PORT: " + this.Profile.Port.ToString()); _tc = Conductor.Components.TelnetConnection.GetLocalConnectionOnPort(this.Profile.Port); if (_tc != null) { _tc.DataReceived += new Conductor.Components.TelnetConnection.DataReceivedEventHandler(_tc_DataReceived); } LogEvent("New telnet connection to port " + this.Profile.Port + ((_tc != null) ? " succeeded" : " failed")); } return(_tc != null); }
Conductor.Components.TelnetConnection GetConnection(bool StartServerIfNeeded = true) { Conductor.Components.TelnetConnection connection = null; if (!IsProcessRunning() && StartServerIfNeeded) { LogEvent("DataPaq server process not running, starting up"); connection = InitializeServer(); } else { connection = Conductor.Components.TelnetConnection.GetLocalConnectionOnPort(this.Profile.Port); } if (connection == null) { string error = "Unable to obtain a connection to the DataPaq. Ensure software is installed and configured."; LogEvent(error); GenerateError(error); } else { string startup = connection.Read(); if (startup.Contains("ERR")) { LogEvent("Communication error: " + startup); GenerateError("Communication error: " + startup); connection = null; } else { LogEvent("Connection response:" + startup); } } return(connection); }