Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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 + "'");
            }
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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);
                }
            }
        }
Exemplo n.º 10
0
 public static void ShowMessageNoCurrentElement()
 {
     UtilSys.MessageBox("No Current Element, unable to execute action.");
 }
Exemplo n.º 11
0
 public static void ShowMessageNoTargetWindow()
 {
     UtilSys.MessageBox("TargetWindow not set, cannot perform action.");
 }