public void RunPilot() { try { IPEndPoint ip = new IPEndPoint(IPAddress.Parse(m_serverIP), m_port); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.Connect(ip); byte[] buf = new byte[1024]; //int received = 0; // server.Receive(buf); string str = string.Empty; // Encoding.UTF8.GetString(buf, 0, received); //if (QABOT_SERVER_WELCOME_MESSAGE == str) { //Scripter.ServerOutput(str); server.Send(Encoding.UTF8.GetBytes("RUN_PILOT")); /* * received = server.Receive(buf); * * str = Encoding.UTF8.GetString(buf, 0, received); * * if ("PONG" == str) * return true; * } * return false; */ } } catch (Exception ex) { UtilSys.MessageBox(ex.Message); } }
public void UploadFile(string fileName, string fileData) { const string FILE_UPLOAD = "FILE_UPLOAD"; const string FILE_UPLOAD_COMPLETED = "FILE_UPLOAD_COMPLETED"; try { IPEndPoint ip = new IPEndPoint(IPAddress.Parse(m_serverIP), m_port); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.Connect(ip); byte[] buf = new byte[1024]; int received = server.Receive(buf); string str = Encoding.UTF8.GetString(buf, 0, received); if (QABOT_SERVER_WELCOME_MESSAGE == str) { //Scripter.ServerOutput(str); byte[] b = Encoding.ASCII.GetBytes(FILE_UPLOAD); server.Send(b, b.Length, SocketFlags.None); received = server.Receive(buf); str = Encoding.UTF8.GetString(buf, 0, received); if (str == "I am ready to receive file") { //Scripter.ServerOutput(str); using (NetworkStream ns = new NetworkStream(server)) { string input = "<File=" + fileName + ">\n" + fileData + "\n<FileEnd>"; if (ns.CanWrite) { ns.Write(Encoding.UTF8.GetBytes(input), 0, input.Length); ns.Flush(); } } byte[] b1 = Encoding.ASCII.GetBytes(FILE_UPLOAD_COMPLETED); server.Send(b1, b1.Length, SocketFlags.None); } else { UtilSys.MessageBox("Server is unable to receive file"); } server.Close(); } } catch (Exception ex) { UtilSys.MessageBox(ex.Message); } }
public bool CheckForUpdates(string path) { IPEndPoint ip = new IPEndPoint(IPAddress.Parse(m_serverIP), m_port); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.Connect(ip); byte[] buf = new byte[1024]; int received = server.Receive(buf); string str = Encoding.UTF8.GetString(buf, 0, received); if (QABOT_SERVER_WELCOME_MESSAGE == str) { string msg = "GET_CREATION|" + path; byte[] b = Encoding.UTF8.GetBytes(msg); server.Send(b, b.Length, SocketFlags.None); received = server.Receive(buf); str = Encoding.UTF8.GetString(buf, 0, received); if ("ERROR" == str) { server.Close(); UtilSys.MessageBox(str); return(false); } FileInfo fi = new FileInfo(path); DateTime dtLocal = fi.LastWriteTime; string temp = dtLocal.Year.ToString() + "-" + dtLocal.Month.ToString() + "-" + dtLocal.Day.ToString() + "-" + dtLocal.Hour.ToString() + "-" + dtLocal.Minute.ToString() + "-" + dtLocal.Second.ToString(); string[] arrServer = str.Split('-'); DateTime dtServer = new DateTime(Convert.ToInt32(arrServer[0]), // year Convert.ToInt32(arrServer[1]), // month Convert.ToInt32(arrServer[2]), // day Convert.ToInt32(arrServer[3]), // hour Convert.ToInt32(arrServer[4]), // minute Convert.ToInt32(arrServer[5])); // second if (dtLocal < dtServer) { server.Close(); return(true); } } server.Close(); return(false); }
public static void Master() { string path = Path.Combine(Application.StartupPath, "QABOT-Master.exe"); if (File.Exists(path)) { System.Diagnostics.Process.Start(path); } else { UtilSys.MessageBox("'QABOT-Master.exe' does not exist on '" + path + "'"); } }
void e_Completed(object sender, SocketAsyncEventArgs e) { if (null == server) { return; } if (!server.Connected) { suppress = true; timer_connection.Stop(); timer_connection.Dispose(); timer_connection = null; if (null != server) { server.Close(); } server = null; UtilSys.MessageBox("Connection Timeout"); return; } //Scripter.ServerOutput("Connection Established"); byte[] buf = new byte[128]; int received = server.Receive(buf); string msg = Encoding.UTF8.GetString(buf, 0, received); if (QABOT_SERVER_WELCOME_MESSAGE == msg) { //Scripter.ServerOutput(msg); byte[] b = Encoding.UTF8.GetBytes("ping"); server.Send(b, b.Length, SocketFlags.None); received = server.Receive(buf); msg = Encoding.UTF8.GetString(buf, 0, received); if ("PONG" == msg) { timer_connection.Stop(); timer_connection.Dispose(); timer_connection = null; MessageBox.Show("Successful connection to the server at [" + e.RemoteEndPoint + "]", "QABOT-Scripter", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
// role of this function is to ensure that // required folder structure under QABOT is created public static bool CreateFolderStructure(string path) { string dir = string.Empty; string[] dirs = { "log", "mru", "projects", "scripts", "settings", "screenshots", "doc", "templates", }; string dirData = Path.Combine(path, "data"); try { if (!Directory.Exists(dirData)) { Directory.CreateDirectory(dirData); } for (int i = 0; i < dirs.Length; ++i) { dir = Path.Combine(dirData, dirs[i]); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } } catch (Exception ex) { UtilSys.MessageBoxError(ex.Message); return(false); } return(true); }
public static List <string> ReadFile(string path2file) { List <string> buffer = new List <string>(); try { using (FileStream fileStream = new FileStream(path2file, FileMode.Open, FileAccess.Read)) using (StreamReader streamReader = new StreamReader(fileStream)) { while (streamReader.Peek() >= 0) { buffer.Add(streamReader.ReadLine()); } } } catch (Exception ex) { UtilSys.MessageBox(ex.Message); } return(buffer); }
public void New() { try { using (StreamWriter SW = File.CreateText(path)) { } DateTime dt = DateTime.Now; string dateStr = UtilSys.GetDateTime(); string head = "<" + m_name + " version=\"" + m_version + "\" date=\"" + dateStr + "\">"; m_bIsOK = true; Write(head); } catch { m_bIsOK = false; } }
public static void Pilot(Form hostForm, string path2Script, string path2Data, bool minimizeHostApp, bool autorun) { string path2Pilot = Path.Combine(Application.StartupPath, "QABOT-Pilot.exe"); // no pilot.exe if (!File.Exists(path2Pilot)) { UtilSys.MessageBox("'QABOT-Pilot.exe' does not exist on '" + path2Pilot + "' path."); return; } // no script file if (!File.Exists(path2Script)) { System.Diagnostics.Process.Start(path2Pilot); } else // at this point pilot and script file exists now let's check if there is a data file { string cmdLineArgs = Support.SurrondItWith(path2Script, "\""); if (File.Exists(path2Data)) { cmdLineArgs += " " + Support.SurrondItWith(path2Data, "\""); } if (autorun) { cmdLineArgs += " run"; } System.Diagnostics.Process.Start(path2Pilot, cmdLineArgs); } if (minimizeHostApp) { hostForm.WindowState = FormWindowState.Minimized; } }
public void Test() { try { if (null != timer_connection) { return; } IPEndPoint ip = new IPEndPoint(IPAddress.Parse(m_serverIP.Trim()), m_port); server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); SocketAsyncEventArgs e = new SocketAsyncEventArgs(); e.RemoteEndPoint = ip; e.UserToken = server; e.Completed += new EventHandler <SocketAsyncEventArgs>(e_Completed); server.ConnectAsync(e); if (timer_connection != null) { timer_connection.Dispose(); } else { timer_connection = new Timer(); } suppress = false; timer_connection.Interval = 2000; timer_connection.Tick += new EventHandler(timer_connection_Tick); timer_connection.Start(); } catch (SocketException ex) { UtilSys.MessageBox(ex.Message); } }
public void UploadFileBinary(string path, string downloadTo, bool silent, bool decoreteServerPath) { string szPath = downloadTo; if (decoreteServerPath) { szPath = path.Replace(downloadTo + "\\", ""); } if (!File.Exists(path)) { if (!silent) { UtilSys.MessageBox("Unable to upload\nFile does not exist: [" + path + "]"); } return; } try { IPEndPoint ip = new IPEndPoint(IPAddress.Parse(m_serverIP), m_port); Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); server.Connect(ip); byte[] buf = new byte[1024]; int received = server.Receive(buf); string str = Encoding.UTF8.GetString(buf, 0, received); if (QABOT_SERVER_WELCOME_MESSAGE == str) { byte[] b = Encoding.UTF8.GetBytes("PUT_FILE|" + szPath); server.Send(b, b.Length, SocketFlags.None); received = server.Receive(buf); str = Encoding.UTF8.GetString(buf, 0, received); if (str == "I am ready to receive file") { using (NetworkStream ns = new NetworkStream(server)) { if (ns.CanWrite) { byte[] bbb = File.ReadAllBytes(path); ns.Write(bbb, 0, bbb.Length); ns.Flush(); } } } server.Close(); if (!silent) { UtilSys.MessageBoxInfo("Successfully uploaded file: " + path); } } } catch (Exception ex) { if (!silent) { UtilSys.MessageBox(ex.Message); } } }
public static void ShowMessageNoCurrentElement() { UtilSys.MessageBox("No Current Element, unable to execute action."); }
public static void ShowMessageNoTargetWindow() { UtilSys.MessageBox("TargetWindow not set, cannot perform action."); }