//------------------------------------------------------------------------ public bool IsFileRunning(int sequence) { SymCommand cmd; bool running = false; cmd = new SymCommand("Misc"); cmd.SetParam("InfoType", "BatchQueues"); Write(cmd); cmd = ReadCommand(); while(!cmd.HasParam("Done")) { if((cmd.GetParam("Action")=="QueueEntry") && (int.Parse(cmd.GetParam("Seq")) == sequence)) running = true; cmd = ReadCommand(); } return running; }
//======================================================================== public void FileWrite(string name, SymFile.Type type, string content) { int chunkMax = 1024; SymCommand cmd = new SymCommand("File"); cmd.SetParam("Action", "Store"); cmd.SetParam("Type" , SymFile.TypeString(type)); cmd.SetParam("Name" , name); WakeUp(); Write(cmd); cmd = ReadCommand(); int wtf_is_this = 0; while(cmd.data.IndexOf("BadCharList") == -1) { cmd = ReadCommand(); wtf_is_this++; if(wtf_is_this > 5) throw new Exception("Null Pointer"); } if(cmd.data.IndexOf("MaxBuff") > -1) chunkMax = int.Parse(cmd.GetParam("MaxBuff")); if(content.Length > (999*chunkMax)) throw new Exception("File Too Large"); if(cmd.GetParam("Status").IndexOf("Filename is too long") != -1) throw new Exception("Filename Too Long"); string[] badChars = cmd.GetParam("BadCharList").Split(new char[] { ',' }); for(int i=0; i<badChars.Length; i++) content = content.Replace(((char)int.Parse(badChars[i]))+"", ""); int sent=0, block=0; string blockStr; byte[] resp; while(sent < content.Length) { int chunkSize = (content.Length - sent); if(chunkSize > chunkMax) chunkSize = chunkMax; string chunk = content.Substring(sent, chunkSize); string chunkStr = chunkSize.ToString("D5"); blockStr = block.ToString("D3"); resp = new byte[]{0x4E,0x4E,0x4E,0x4E,0x4E,0x4E,0x4E,0x4E,0x4E,0x4E,0x4E}; while(resp[7] == 0x4E) { Write("PROT"+blockStr+"DATA"+chunkStr); Write(chunk); resp = Read(16); } block++; sent += chunkSize; } blockStr = block.ToString("D3"); Write("PROT"+blockStr+"EOF\u0020\u0020\u0020\u0020\u0020\u0020"); resp = Read(16); cmd = ReadCommand(); WakeUp(); }
//------------------------------------------------------------------------ public FMRunNfo FMRun(string inpTitle, FMType fmtype, FileRun_Status callStatus, int queue) { callStatus(1,"Initializing..."); SymCommand cmd; string outTitle = "PwrIDE FM - " + new Random().Next(8388608).ToString("D7"); Write("mm0\u001B"); cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); callStatus(2,"Writing Commands..."); Write("1\r"); cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write("24\r"); //Misc. Processing cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write("5\r"); //Batch FM cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write(((int)fmtype).ToString()+"\r"); //FM File Type cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write("0\r"); //Undo a Posting? (NO) cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write(inpTitle+"\r"); //Title of Batch Report Output to Use as FM Script cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write("1\r"); //Number of Search Days? (1) cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); if(fmtype == FMType.Account) { Write("1\r"); //Record FM History (YES) cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); } Write(outTitle+"\r"); //Name of Posting (needed to lookup later) cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write("1\r"); //Produce Empty Report If No Exceptions? (YES) cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write("0\r"); //Batch Options? (NO) //get queues callStatus(4, "Getting Queue List"); cmd = ReadCommand(); Dictionary<int,int> queAvailable = new Dictionary<int,int>(); while(cmd.command != "Input") { if((cmd.GetParam("Action") == "DisplayLine") && (cmd.GetParam("Text").Contains("Batch Queues Available:"))) { string line = cmd.GetParam("Text"); string[] strQueues = line.Substring(line.IndexOf(':')+1).Split(new char[]{','}); for(int i=0; i<strQueues.Length; i++) { strQueues[i] = strQueues[i].Trim(); if(strQueues[i].Contains("-")) { int pos = strQueues[i].IndexOf('-'); int start = int.Parse(strQueues[i].Substring(0,pos)); int end = int.Parse(strQueues[i].Substring(pos+1)); for(int c=start; c<=end; c++) queAvailable.Add(c,0); } else queAvailable.Add(int.Parse(strQueues[i]),0); } } cmd = ReadCommand(); } //get queue counts callStatus(5, "Getting Queue Counts"); cmd = new SymCommand("Misc"); cmd.SetParam("InfoType", "BatchQueues"); Write(cmd); cmd = ReadCommand(); while(!cmd.HasParam("Done")) { if((cmd.GetParam("Action") == "QueueEntry") && (cmd.GetParam("Stat") == "Running")) queAvailable[int.Parse(cmd.GetParam("Queue"))]++; cmd = ReadCommand(); } if(queue == -1) //auto select lowest pending queue, or last available Zero queue { queue = 0; foreach(KeyValuePair<int, int> Q in queAvailable) if(Q.Value <= queAvailable[queue]) queue = Q.Key; } callStatus(7, "Writing Final Commands"); Write(queue.ToString()+"\r"); //write queue cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); Write("1\r"); //Okay (to Proceed)? (YES) cmd=ReadCommand(); while(cmd.command!="Input") cmd=ReadCommand(); //get queues again callStatus(8, "Finding FM Sequence"); cmd = new SymCommand("Misc"); cmd.SetParam("InfoType", "BatchQueues"); Write(cmd); int newestTime = 0; int sequenceNo = -1; cmd = ReadCommand(); while(!cmd.HasParam("Done")) { if(cmd.GetParam("Action") == "QueueEntry") { int currTime = 0; string timeStr = cmd.GetParam("Time"); currTime = int.Parse(timeStr.Substring(timeStr.LastIndexOf(':')+1)); currTime += 60 * int.Parse(timeStr.Substring(timeStr.IndexOf(':')+1, 2)); currTime += 3600 * int.Parse(timeStr.Substring(0, timeStr.IndexOf(':'))); if(currTime >= newestTime) { newestTime = currTime; sequenceNo = int.Parse(cmd.GetParam("Seq")); } } cmd = ReadCommand(); } callStatus(9, "Running.."); return new FMRunNfo(sequenceNo, outTitle); }
//------------------------------------------------------------------------ public RepRunErr FileRun(SymFile file, FileRun_Status callStatus, FileRun_Prompt callPrompt, int queue) { if (file.type != SymFile.Type.REPGEN) throw new Exception("Cannot Run a " + file.TypeString() + " File"); SymCommand cmd; callStatus(0,"Initializing..."); Write("mm0\u001B"); cmd = ReadCommand(); while(cmd.command != "Input") cmd = ReadCommand(); callStatus(1,"Writing Commands..."); Write("1\r"); cmd = ReadCommand(); while(cmd.command != "Input") cmd = ReadCommand(); callStatus(2,"Writing Commands..."); Write("11\r"); cmd = ReadCommand(); while(cmd.command != "Input") cmd = ReadCommand(); callStatus(3,"Writing Commands..."); Write(file.name + "\r"); bool erroredOut = false; while(true) { cmd = ReadCommand(); if((cmd.command == "Input") && (cmd.GetParam("HelpCode")=="20301")) break; if(cmd.command == "Input") { callStatus(4,"Please Enter Prompts"); string result = callPrompt(cmd.GetParam("Prompt")); if(result == null) //cancelled { Write("\u001B"); cmd = ReadCommand(); while(cmd.command != "Input") cmd = ReadCommand(); return RepRunErr.Cancelled(); } else Write(result.Trim()+'\r'); } else if(cmd.command == "Bell") callStatus(4, "Invalid Prompt Input, Please Re-Enter"); else if((cmd.command == "Batch") && (cmd.GetParam("Text")=="No such file or directory")) { cmd = ReadCommand(); while(cmd.command != "Input") cmd = ReadCommand(); return RepRunErr.NotFound(); } else if(cmd.command == "SpecfileErr") erroredOut = true; else if(erroredOut && (cmd.command == "Batch") && (cmd.GetParam("Action") == "DisplayLine")) { string err = cmd.GetParam("Text"); cmd = ReadCommand(); while (cmd.command != "Input") cmd = ReadCommand(); return RepRunErr.Errored(err); } else if((cmd.command == "Batch") && (cmd.GetParam("Action") == "DisplayLine")) callStatus(5, cmd.GetParam("Text")); } Write("\r"); cmd = ReadCommand(); while(cmd.command != "Input") cmd = ReadCommand(); callStatus(6, "Getting Queue List"); Write("0\r"); cmd = ReadCommand(); Dictionary<int,int> queAvailable = new Dictionary<int,int>(); while(cmd.command != "Input") { if((cmd.GetParam("Action") == "DisplayLine") && (cmd.GetParam("Text").Contains("Batch Queues Available:"))) { string line = cmd.GetParam("Text"); string[] strQueues = line.Substring(line.IndexOf(':')+1).Split(new char[]{','}); for(int i=0; i<strQueues.Length; i++) { strQueues[i] = strQueues[i].Trim(); if(strQueues[i].Contains("-")) { int pos = strQueues[i].IndexOf('-'); int start = int.Parse(strQueues[i].Substring(0,pos)); int end = int.Parse(strQueues[i].Substring(pos+1)); for(int c=start; c<=end; c++) queAvailable.Add(c,0); } else queAvailable.Add(int.Parse(strQueues[i]),0); } } cmd = ReadCommand(); } callStatus(7, "Getting Queue Counts"); cmd = new SymCommand("Misc"); cmd.SetParam("InfoType", "BatchQueues"); Write(cmd); cmd = ReadCommand(); while(!cmd.HasParam("Done")) { if((cmd.GetParam("Action") == "QueueEntry") && (cmd.GetParam("Stat") == "Running")) queAvailable[int.Parse(cmd.GetParam("Queue"))]++; cmd = ReadCommand(); } if(queue == -1) //auto select lowest pending queue, or last available Zero queue { queue = 0; foreach(KeyValuePair<int, int> Q in queAvailable) if(Q.Value <= queAvailable[queue]) queue = Q.Key; } Write(queue.ToString()+"\r"); cmd = ReadCommand(); while(cmd.command != "Input") cmd = ReadCommand(); callStatus(8, "Getting Sequence Numbers"); Write("1\r"); cmd = ReadCommand(); while(cmd.command != "Input") cmd = ReadCommand(); cmd = new SymCommand("Misc"); cmd.SetParam("InfoType", "BatchQueues"); Write(cmd); int newestTime = 0; int sequenceNo = -1; cmd = ReadCommand(); while(!cmd.HasParam("Done")) { if(cmd.GetParam("Action") == "QueueEntry") { int currTime = 0; string timeStr = cmd.GetParam("Time"); currTime = int.Parse(timeStr.Substring(timeStr.LastIndexOf(':')+1)); currTime += 60 * int.Parse(timeStr.Substring(timeStr.IndexOf(':')+1, 2)); currTime += 3600 * int.Parse(timeStr.Substring(0, timeStr.IndexOf(':'))); if(currTime >= newestTime) { newestTime = currTime; sequenceNo = int.Parse(cmd.GetParam("Seq")); } } cmd = ReadCommand(); } callStatus(9, "Running.."); return RepRunErr.Okay(sequenceNo, newestTime); }
//======================================================================== public void FileRename(string oldName, SymFile.Type type, string newName) { SymCommand cmd = new SymCommand("File"); cmd.SetParam("Action" , "Rename"); cmd.SetParam("Type" , SymFile.TypeString(type)); cmd.SetParam("Name" , oldName); cmd.SetParam("NewName", newName); Write(cmd); cmd = ReadCommand(2000); if(cmd.HasParam("Status")) { if(cmd.GetParam("Status").IndexOf("No such file or directory") != -1) throw new FileNotFoundException("File \""+oldName+"\" Not Found"); else throw new Exception("Filename Too Long"); } else if(cmd.HasParam("Done")) return; else throw new Exception("Unknown Renaming Error"); }
//======================================================================== public string FileRead(string name, SymFile.Type type) { StringBuilder content = new StringBuilder(); SymCommand cmd = new SymCommand("File"); cmd.SetParam("Action", "Retrieve"); cmd.SetParam("Type" , SymFile.TypeString(type)); cmd.SetParam("Name" , name); Write(cmd); while(true) { cmd = ReadCommand(); if(cmd.HasParam("Status")) { if(cmd.GetParam("Status").IndexOf("No such file or directory") != -1) throw new FileNotFoundException("File \""+name+"\" Not Found"); else if(cmd.GetParam("Status").IndexOf("Cannot view a blank report") != -1) return ""; else throw new Exception("Filename Too Long"); } string chunk = cmd.GetFileData(); if((chunk.Length > 0) || (type == SymFile.Type.REPORT)) { content.Append(chunk); if(type==SymFile.Type.REPORT) content.Append('\n'); } if(cmd.HasParam("Done")) break; } return content.ToString(); }
//======================================================================== public List<SymFile> FileList(string pattern, SymFile.Type type) { List<SymFile> files = new List<SymFile>(); SymCommand cmd = new SymCommand("File"); cmd.SetParam("Type" , SymFile.TypeDescriptor[(int)type]); cmd.SetParam("Name" , pattern); cmd.SetParam("Action", "List"); Write(cmd); while(true) { cmd = ReadCommand(2000); if(cmd.HasParam("Status")) break; if(cmd.HasParam("Name")) files.Add(new SymFile(server, sym, cmd.GetParam("Name"), cmd.GetParam("Date"), cmd.GetParam("Time"), int.Parse(cmd.GetParam("Size")), type)); if(cmd.HasParam("Done")) break; } return files; }
//------------------------------------------------------------------------ private List<int> GetPrintSequences(string which) { List<int> seqs = new List<int>(); SymCommand cmd; cmd = new SymCommand("File"); cmd.SetParam("Action" , "List"); cmd.SetParam("MaxCount", "50"); cmd.SetParam("Query" , "LAST 20 \"+"+which+"+\""); cmd.SetParam("Type" , "Report"); Write(cmd); cmd = ReadCommand(); while(!cmd.HasParam("Done")) { if(cmd.HasParam("Sequence")) seqs.Add(int.Parse(cmd.GetParam("Sequence"))); cmd = ReadCommand(); } seqs.Sort(); seqs.Reverse(); return seqs; }