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; } }
public int defineProcess(Process p) { string define = "define process \n"; define = define + "name:" + p.getName() + "\n"; define = define + "group:" + p.getDatabase() + "\n"; define = define + "env:" + "NDB_CONNECTSTRING="+p.getConnectString() ; if(p.getEnv().Equals("")) define = define + "\n"; else define = define + " " + p.getEnv() + "\n"; //if(p.getPath().EndsWith("\\")) // define = define + "path:" + p.getPath()+ "ndb" + "\n"; //else define = define + "path:" + p.getPath() + "\n"; define = define + "args:" + p.getArgs() + "\n"; define = define + "type:" + "permanent" + "\n"; define = define + "cwd:" + p.getCwd() + "\n"; define = define + "owner:" + "ejohson" + "\n\n"; if(!sendMessage(define)) return -2; SimpleCPCParser.parse(p, m_socket); if(p.isDefined()) return 1; else return -1; }
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(); } }
public void addProcessCheck(Process process) { if(m_processes==null) return; if(m_processes.Count>0) { foreach (Process p in m_processes) { if(process.getId().Equals(p.getId())) return; } } m_processes.Add(process); }
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(); } }
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(); } }
public void addProcess(Process process) { m_processes.Add(process); }
public int undefineProcess(Process p) { if(!p.isDefined()) { return -4; //process not defined } string undefine= "undefine process \n"; undefine = undefine + "id:" + p.getId() + "\n\n"; if(!sendMessage(undefine)) return -2; SimpleCPCParser.parse(p, m_socket); if(!p.isDefined()) { return 1; } return -1; }
public int stopProcess(Process p) { if(!p.isDefined()) { return -4; //process not defined } string stop= "stop process \n"; stop = stop + "id:" + p.getId() + "\n\n"; if(!sendMessage(stop)) return -2; SimpleCPCParser.parse(p, m_socket); if(p.getStatus().Equals(Process.Status.Stopped)) return 1; else return -1; }
public int startProcess(Process p) { if(!p.isDefined()) { this.defineProcess(p); if(!p.isDefined()) return -4; //process misconfigured } string start= "start process \n"; start = start + "id:" + p.getId() + "\n\n"; if(!sendMessage(start)) return -2; SimpleCPCParser.parse(p, m_socket); if(p.getStatus().Equals(Process.Status.Running)) return 1; else return -1; }