Beispiel #1
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);
        }
Beispiel #2
0
        //========================================================================
        public RepErr FileInstall(SymFile file)
        {
            if(file.type != SymFile.Type.REPGEN)
            throw new Exception("Cannot Install a "+file.TypeString()+" File");

              Write("mm3\u001B");    ReadCommand();
              Write("8\r");          ReadCommand(); ReadCommand();
              Write(file.name+'\r');

              SymCommand cmd = ReadCommand();
              if(cmd.HasParam("Warning") || cmd.HasParam("Error"))
              {
            ReadCommand();
            throw new Exception("File \""+file.name+"\" Not Found");
              }

              if(cmd.command=="SpecfileData")
              {
            ReadCommand();
            Write("1\r");
            ReadCommand(); ReadCommand();
            return RepErr.None(int.Parse(cmd.GetParam("Size").Replace(",","")));
              }

              int errRow = 0, errCol = 0;
              string errFile = "", errText = "";
              if (cmd.GetParam("Action") == "Init")
              {
            errFile = cmd.GetParam("FileName");
            cmd = ReadCommand();
            while (cmd.GetParam("Action") != "DisplayEdit")
            {
              if (cmd.GetParam("Action") == "FileInfo")
              {
            errRow = int.Parse(cmd.GetParam("Line").Replace(",", ""));
            errCol = int.Parse(cmd.GetParam("Col").Replace(",", ""));
              }
              else if (cmd.GetParam("Action") == "ErrText")
            errText += cmd.GetParam("Line") + " ";
              cmd = ReadCommand();
            }
            ReadCommand();

            return new RepErr(file, errFile, errText, errRow, errCol);
              }

              throw new Exception("Unknown Install Error");
        }