Example #1
0
        //------------------------------------------------------------------------
        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);
        }
Example #2
0
        //------------------------------------------------------------------------
        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);
        }