Ejemplo n.º 1
0
 public static void parse(Process p, SocketComm comm)
 {
     string line=comm.readLine();//reader.ReadLine();
     while(line.Equals(""))
     {
         line=comm.readLine();
     }
     if(line.Equals("define process"))
     {
         defineProcess(p, comm);
         line="";
         return;
     }
     if(line.Equals("start process"))
     {
         startProcess(p,comm);
         line="";
         return;
     }
     if(line.Equals("stop process"))
     {
         stopProcess(p,comm);
         line="";
         return;
     }
     if(line.Equals("undefine process"))
     {
         undefineProcess(p,comm);
         line="";
         return;
     }
 }
Ejemplo n.º 2
0
 private static void defineProcess(Process p, SocketComm comm)
 {
     string line=comm.readLine();//reader.ReadLine();
     while(!line.Equals(""))
     {
         if(line.StartsWith("status:"))
         {
             line=line.Remove(0,7);
             line=line.Trim();
             if(line.Equals("1"))
             {
                 p.setDefined(true);
                 p.setStatus(Process.Status.Stopped);
             }
             else
                 p.setDefined(false);
         }
         if(line.StartsWith("id:"))
         {
             line=line.Remove(0,3);
             line=line.Trim();
             p.setId(line);
         }
         line=comm.readLine();
     }
 }
Ejemplo n.º 3
0
 public Computer(string name, int port)
 {
     m_name = name;
     m_status = Status.Disconnected;
     m_processes = new ArrayList();
     m_cpcdPort=port;
     m_socket = new SocketComm(m_name,m_cpcdPort);
 }
Ejemplo n.º 4
0
 public Computer(string name, string ip)
 {
     m_ip = ip;
     m_name = name;
     m_status = Status.Disconnected;
     m_processes = new ArrayList();
     m_cpcdPort=1234; //default port
     m_socket = new SocketComm(m_ip,m_cpcdPort);
 }
Ejemplo n.º 5
0
        public static void parse(ArrayList processes, Computer c, SocketComm comm)
        {
            string line=comm.readLine();//reader.ReadLine();
            while(line.Equals(""))
            {
                line=comm.readLine();
            }

            if(line.Equals("start processes"))
            {
                listProcesses(processes, c, comm);
                line="";
                return;
            }
        }
Ejemplo n.º 6
0
        private static void stopProcess(Process p, SocketComm comm)
        {
            string line=comm.readLine();//reader.ReadLine();
            while(!line.Equals(""))
            {
                if(line.StartsWith("status:"))
                {
                    line=line.Remove(0,7);
                    line=line.Trim();
                    if(line.Equals("1"))
                        p.setStatus(NDB_CPC.Process.Status.Stopped);
                    else
                        p.setStatus(NDB_CPC.Process.Status.Unknown);

                }
                if(line.StartsWith("id:"))
                {
                    line=line.Remove(0,3);
                    line=line.Trim();
                    if(p.getId().Equals(line))
                    {
                        ;
                    }
                    else
                    {
                        //damn something is wrong
                        p.setStatus(NDB_CPC.Process.Status.Unknown);
                    }

                }
                line=comm.readLine();
            }
        }
Ejemplo n.º 7
0
        private static void listProcesses(ArrayList processes, Computer c, SocketComm comm)
        {
            bool processExist = false;

            string line=comm.readLine();//reader.ReadLine();
            while(!line.Equals("end processes"))
            {
                if(line.Equals("process"))
                {
                    line=comm.readLine();
                    Process p = new Process();

                    while(!line.Equals(""))
                    {
                        if(line.StartsWith("id:"))
                        {
                            string pid;
                            line=line.Remove(0,3);
                            pid=line.Trim();
                            /*check if process already exist*/
                            processExist=findProcess(processes,pid);
                            if(!processExist)
                            {
                                p.setId(pid);
                            }
                        }

                        if(line.StartsWith("name:"))
                        {

                            line=line.Remove(0,5);
                            line=line.Trim();
                            /*check if process already exist*/
                            if(!processExist)
                            {
                                p.setName(line);
                            }
                        }

                        if(line.StartsWith("path:"))
                        {

                            line=line.Remove(0,5);
                            line=line.Trim();
                            /*check if process already exist*/
                            if(!processExist)
                            {
                                p.setPath(line);
                            }
                        }

                        if(line.StartsWith("args:"))
                        {

                            line=line.Remove(0,5);
                            line=line.Trim();
                            /*check if process already exist*/
                            if(!processExist)
                            {
                                p.setArgs(line);
                            }
                        }

                        if(line.StartsWith("type:"))
                        {

                            line=line.Remove(0,5);
                            line=line.Trim();
                            /*check if process already exist*/
                            if(!processExist)
                            {

                            }
                        }

                        if(line.StartsWith("cwd:"))
                        {

                            line=line.Remove(0,4);
                            line=line.Trim();
                            /*check if process already exist*/
                            if(!processExist)
                            {
                                p.setCwd(line);
                            }
                        }

                        if(line.StartsWith("env:"))
                        {

                            line=line.Remove(0,4);
                            line=line.Trim();
                            /*check if process already exist*/
                            if(!processExist)
                            {
                                p.setEnv(line);
                            }
                        }

                        if(line.StartsWith("owner:"))
                        {

                            line=line.Remove(0,6);
                            line=line.Trim();
                            /*check if process already exist*/
                            if(!processExist)
                            {
                                p.setOwner(line);
                            }
                        }
                        if(line.StartsWith("group:"))
                        {

                            line=line.Remove(0,6);
                            line=line.Trim();
                            /*check if process already exist*/
                            if(!processExist)
                            {
                                p.setDatabase(line);
                            }
                        }

                        if(line.StartsWith("status:"))
                        {

                            line=line.Remove(0,7);
                            line=line.Trim();
                            /*check if process already exist*/
                            //if(!processExist)
                            //{
                                if(line.Equals("0"))
                                    p.setStatus(Process.Status.Stopped);
                                if(line.Equals("1"))
                                    p.setStatus(Process.Status.Running);
                                if(line.Equals("2"))
                                    p.setStatus(Process.Status.Unknown);
                            //}
                        }

                        line=comm.readLine();
                    }
                    if(!processExist)
                    {
                        p.setComputer(c);
                        p.setDefined(true);
                        processes.Add(p);
                    }
                    processExist=false;
                }
                line=comm.readLine();

            }
        }