コード例 #1
0
        public List <File> FileList(string pattern, FileType type)
        {
            var files = new List <File>();

            ISymCommand cmd = new SymCommand("File");

            cmd.Set("Type", Utilities.FileTypeString(type));
            cmd.Set("Name", pattern);
            cmd.Set("Action", "List");
            _socket.Write(cmd);

            while (true)
            {
                cmd = _socket.ReadCommand();
                if (cmd.HasParameter("Status"))
                {
                    break;
                }
                if (cmd.HasParameter("Name"))
                {
                    files.Add(new File(_socket.Server, SymDirectory.ToString(), cmd.Get("Name"), type,
                                       cmd.Get("Date"), cmd.Get("Time"),
                                       int.Parse(cmd.Get("Size"))));
                }
                if (cmd.HasParameter("Done"))
                {
                    break;
                }
            }
            return(files);
        }
コード例 #2
0
ファイル: RunReport.cs プロジェクト: kochste77/SymSharp
        private List <int> GetPrintSequences(string searchTerm)
        {
            var         seqs = new List <int>();
            ISymCommand cmd;

            cmd = new SymCommand("File");
            cmd.Set("Action", "List");
            cmd.Set("MaxCount", "50");
            cmd.Set("Query", "LAST 20 \"+" + searchTerm + "+\"");
            cmd.Set("Type", "Report");
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if (cmd.HasParameter("Sequence"))
                {
                    seqs.Add(int.Parse(cmd.Get("Sequence")));
                }
                cmd = _socket.ReadCommand();
            }

            seqs.Sort();
            seqs.Reverse();
            return(seqs);
        }
コード例 #3
0
        public void FileRename(string oldName, string newName, FileType type)
        {
            ISymCommand cmd = new SymCommand("File");

            cmd.Set("Action", "Rename");
            cmd.Set("Type", Utilities.FileTypeString(type));
            cmd.Set("Name", oldName);
            cmd.Set("NewName", newName);
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            if (cmd.HasParameter("Status"))
            {
                if (cmd.Get("Status").IndexOf("No such file or directory") != -1)
                {
                    throw new FileNotFoundException();
                }
                else
                {
                    throw new Exception("Filename Too Long");
                }
            }

            if (cmd.HasParameter("Done"))
            {
                return;
            }

            throw new Exception("Unknown Renaming Error");
        }
コード例 #4
0
        private int GetOpenQueue(Dictionary <int, int> availableQueues)
        {
            int         queue;
            ISymCommand cmd = new SymCommand();

            if (availableQueues == null || availableQueues.Count == 0)
            {
                availableQueues = GetQueueList(cmd);
            }

            //get queue counts
            cmd = new SymCommand("Misc");
            cmd.Set("InfoType", "BatchQueues");
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if ((cmd.Get("Action") == "QueueEntry") && (cmd.Get("Stat") == "Running"))
                {
                    availableQueues[int.Parse(cmd.Get("Queue"))]++;
                }
                cmd = _socket.ReadCommand();
            }

            // Get queue with lowest pending
            int lowestPending = 0;

            queue = 0;
            foreach (var Q in availableQueues)
            {
                if (Q.Value == 0)
                {
                    return(Q.Key);
                }

                if (Q.Value < lowestPending)
                {
                    lowestPending = Q.Value;
                    queue         = Q.Key;
                }
            }

            return(queue);
        }
コード例 #5
0
ファイル: RunReport.cs プロジェクト: kochste77/SymSharp
        public bool IsFileRunning(int sequence)
        {
            if (sequence <= 0)
            {
                throw new ArgumentOutOfRangeException("sequence");
            }

            ISymCommand cmd;
            bool        running = false;

            cmd = new SymCommand("Misc");
            cmd.Set("InfoType", "BatchQueues");
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if ((cmd.Get("Action") == "QueueEntry") && (int.Parse(cmd.Get("Seq")) == sequence))
                {
                    running = true;
                }
                else if (cmd.Get("Action") == "Close")
                {
                    Reconnect();
                    cmd = new SymCommand("Misc");
                    cmd.Set("InfoType", "BatchQueues");
                    _socket.Write(cmd);
                }
                else if (cmd.Command == "")
                {
                    cmd = new SymCommand("Misc");
                    cmd.Set("InfoType", "BatchQueues");
                    _socket.Write(cmd);
                }

                cmd = _socket.ReadCommand();
            }

            return(running);
        }
コード例 #6
0
        public string FileRead(string name, FileType type)
        {
            var content = new StringBuilder();

            ISymCommand cmd = new SymCommand("File");

            cmd.Set("Action", "Retrieve");
            cmd.Set("Type", Utilities.FileTypeString(type));
            cmd.Set("Name", name);
            _socket.Write(cmd);

            while (true)
            {
                cmd = _socket.ReadCommand();

                if (cmd.HasParameter("Status"))
                {
                    string status = cmd.Get("Status");
                    if (status.Contains("No such file or directory"))
                    {
                        throw new FileNotFoundException();
                    }

                    if (status.Contains("Cannot view a blank report"))
                    {
                        return("");
                    }

                    throw new Exception("Filename Too Long");
                }

                string chunk = cmd.Data;
                if (!string.IsNullOrEmpty(chunk))
                {
                    content.Append(chunk);
                    if (type == FileType.Report)
                    {
                        content.Append('\n');
                    }
                }

                if (cmd.HasParameter("Done"))
                {
                    break;
                }
            }
            return(content.ToString());
        }
コード例 #7
0
ファイル: FileHandling.cs プロジェクト: jdeering/SymSharp
        public void FileDelete(string name, FileType type)
        {
            ISymCommand cmd = new SymCommand("File");
            cmd.Set("Action", "Delete");
            cmd.Set("Type", Utilities.FileTypeString(type));
            cmd.Set("Name", name);
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            if (cmd.HasParameter("Status"))
            {
                if (cmd.Get("Status").IndexOf("No such file or directory") != -1)
                    throw new FileNotFoundException();
                else
                    throw new Exception("Filename Too Long");
            }
            if (cmd.HasParameter("Done"))
                return;

            throw new Exception("Unknown Deletion Error");
        }
コード例 #8
0
ファイル: FileHandling.cs プロジェクト: jdeering/SymSharp
        public List<File> FileList(string pattern, FileType type)
        {
            var files = new List<File>();

            ISymCommand cmd = new SymCommand("File");
            cmd.Set("Type", Utilities.FileTypeString(type));
            cmd.Set("Name", pattern);
            cmd.Set("Action", "List");
            _socket.Write(cmd);

            while (true)
            {
                cmd = _socket.ReadCommand();
                if (cmd.HasParameter("Status"))
                    break;
                if (cmd.HasParameter("Name"))
                {
                    files.Add(new File(_socket.Server, SymDirectory.ToString(), cmd.Get("Name"), type,
                                       cmd.Get("Date"), cmd.Get("Time"),
                                       int.Parse(cmd.Get("Size"))));
                }
                if (cmd.HasParameter("Done"))
                    break;
            }
            return files;
        }
コード例 #9
0
ファイル: FileHandling.cs プロジェクト: jdeering/SymSharp
        public void FileWrite(string name, FileType type, string content)
        {
            int chunkMax = 1024; // 1 MB max file size by default

            ISymCommand cmd = new SymCommand("File");
            cmd.Set("Action", "Store");
            cmd.Set("Type", Utilities.FileTypeString(type));
            cmd.Set("Name", name);
            _socket.WakeUp();
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            int wtf_is_this = 0;
            while (!cmd.Data.Contains("BadCharList"))
            {
                cmd = _socket.ReadCommand();
                wtf_is_this++;
                if (wtf_is_this > 5)
                    throw new NullReferenceException();
            }

            if (cmd.Data.Contains("MaxBuff"))
                chunkMax = int.Parse(cmd.Get("MaxBuff"));

            if (content.Length > (999*chunkMax))
                throw new FileLoadException("File too large");

            if (cmd.Get("Status").Contains("Filename is too long"))
                throw new Exception("Filename Too Long");

            content = SanitizeFileContent(content, cmd.Get("BadCharList").Split(','));

            int bytesSent = 0;
            int block = 0;
            string blockStr;
            byte[] response;

            while (bytesSent < content.Length)
            {
                int chunkSize = (content.Length - bytesSent);
                if (chunkSize > chunkMax)
                    chunkSize = chunkMax;
                string chunk = content.Substring(bytesSent, chunkSize);
                string chunkStr = chunkSize.ToString("D5");
                blockStr = block.ToString("D3");

                response = new byte[] {0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E};
                while (response[7] == 0x4E)
                {
                    _socket.Write("PROT" + blockStr + "DATA" + chunkStr);
                    _socket.Write(chunk);
                    response = Convert.FromBase64String(_socket.Read());
                }

                block++;
                bytesSent += chunkSize;
            }

            blockStr = block.ToString("D3");
            _socket.Write("PROT" + blockStr + "EOF\u0020\u0020\u0020\u0020\u0020\u0020");
            _socket.Read();

            _socket.ReadCommand();
            _socket.WakeUp();
        }
コード例 #10
0
        public void FileWrite(string name, FileType type, string content)
        {
            int chunkMax = 1024; // 1 MB max file size by default

            ISymCommand cmd = new SymCommand("File");

            cmd.Set("Action", "Store");
            cmd.Set("Type", Utilities.FileTypeString(type));
            cmd.Set("Name", name);
            _socket.WakeUp();
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            int wtf_is_this = 0;

            while (!cmd.Data.Contains("BadCharList"))
            {
                cmd = _socket.ReadCommand();
                wtf_is_this++;
                if (wtf_is_this > 5)
                {
                    throw new NullReferenceException();
                }
            }

            if (cmd.Data.Contains("MaxBuff"))
            {
                chunkMax = int.Parse(cmd.Get("MaxBuff"));
            }

            if (content.Length > (999 * chunkMax))
            {
                throw new FileLoadException("File too large");
            }

            if (cmd.Get("Status").Contains("Filename is too long"))
            {
                throw new Exception("Filename Too Long");
            }

            content = SanitizeFileContent(content, cmd.Get("BadCharList").Split(','));

            int    bytesSent = 0;
            int    block     = 0;
            string blockStr;

            byte[] response;

            while (bytesSent < content.Length)
            {
                int chunkSize = (content.Length - bytesSent);
                if (chunkSize > chunkMax)
                {
                    chunkSize = chunkMax;
                }
                string chunk    = content.Substring(bytesSent, chunkSize);
                string chunkStr = chunkSize.ToString("D5");
                blockStr = block.ToString("D3");

                response = new byte[] { 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E };
                while (response[7] == 0x4E)
                {
                    _socket.Write("PROT" + blockStr + "DATA" + chunkStr);
                    _socket.Write(chunk);
                    response = Convert.FromBase64String(_socket.Read());
                }

                block++;
                bytesSent += chunkSize;
            }

            blockStr = block.ToString("D3");
            _socket.Write("PROT" + blockStr + "EOF\u0020\u0020\u0020\u0020\u0020\u0020");
            _socket.Read();

            _socket.ReadCommand();
            _socket.WakeUp();
        }
コード例 #11
0
ファイル: RunReport.cs プロジェクト: jdeering/SymSharp
        public RepgenRunResult FileRun(File file, FileRunStatus callStatus, FileRunPrompt callPrompt, int queue, RunWorkerCompletedEventHandler Notify = null)
        {
            if (file.Type != FileType.RepGen)
                throw new InvalidOperationException("Cannot run a " + file.FileTypeString() + " file");

            ISymCommand cmd;
            callStatus(RunState.Initializing, file);

            _socket.Write("mm0\u001B");

            WaitForCommand("Input");
            _socket.Write("1\r");

            WaitForCommand("Input");
            _socket.Write("11\r");

            WaitForPrompt("Specification File");
            _socket.Write(file.Name + "\r");
            bool erroredOut = false;
            while (true)
            {
                cmd = _socket.ReadCommand();

                if (cmd.Command == "Input")
                {
                    if (cmd.Get("HelpCode") == "20301") break;

                    callStatus(RunState.Prompts, file);

                    string result = callPrompt(cmd.Get("Prompt"));
                    if (result == null) //cancelled
                    {
                        _socket.Write("\u001B");
                        cmd = _socket.ReadCommand();
                        while (cmd.Command != "Input")
                            cmd = _socket.ReadCommand();
                        callStatus(RunState.Cancelled, file);
                        return RepgenRunResult.Cancelled();
                    }

                    _socket.Write(result.Trim() + '\r');
                }
                else if (cmd.Command == "Bell")
                    callStatus(RunState.Prompts, "Invalid Prompt Input, Please Re-Enter");
                else if ((cmd.Command == "Batch") && (cmd.Get("Text") == "No such file or directory"))
                {
                    cmd = _socket.ReadCommand();
                    while (cmd.Command != "Input")
                        cmd = _socket.ReadCommand();
                    callStatus(RunState.Failed, "File not found");
                    return RepgenRunResult.FileNotFound();
                }
                else if (cmd.Command == "SpecfileErr")
                    erroredOut = true;
                else if (erroredOut && (cmd.Command == "Batch") && (cmd.Get("Action") == "DisplayLine"))
                {
                    string err = cmd.Get("Text");
                    cmd = _socket.ReadCommand();
                    while (cmd.Command != "Input")
                        cmd = _socket.ReadCommand();
                    callStatus(RunState.Failed, err);
                    return RepgenRunResult.Error(err);
                }
                else if ((cmd.Command == "Batch") && (cmd.Get("Action") == "DisplayLine"))
                    callStatus(RunState.Initializing, cmd.Get("Text"));
            }

            while (cmd.Get("Prompt").Contains("Specification File"))
            {
                _socket.Write("\r");
                cmd = _socket.ReadCommand();
            }

            WaitForPrompt("Batch Options");
            _socket.Write("0\r");

            Dictionary<int, int> availableQueues = GetQueueList(cmd);

            if (queue < 0)
                queue = GetOpenQueue(availableQueues);

            WaitForPrompt("Batch Queue");
            _socket.Write(queue + "\r");

            WaitForCommand("Input");

            _socket.Write("1\r");
            cmd = _socket.ReadCommand();
            while (cmd.Command != "Input")
                cmd = _socket.ReadCommand();

            cmd = new SymCommand("Misc");
            cmd.Set("InfoType", "BatchQueues");
            _socket.Write(cmd);

            int newestTime = 0;
            int sequenceNo = -1;
            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if (cmd.Get("Action") == "QueueEntry")
                {
                    int currTime = Utilities.ConvertTime(cmd.Get("Time"));

                    if (currTime >= newestTime)
                    {
                        newestTime = currTime;
                        sequenceNo = int.Parse(cmd.Get("Seq"));
                    }
                }
                cmd = _socket.ReadCommand();
            }

            callStatus(RunState.Running, sequenceNo);

            if (Notify != null)
            {
                var worker = new BackgroundWorker();

                worker.DoWork += (sender, eventArgs) =>
                    {
                        Thread.Sleep(5000); // Wait 5 seconds before first check
                        while (IsFileRunning(sequenceNo))
                        {
                            Thread.Sleep(15000);
                        }

                        object[] result = new object[3];
                        result[0] = file.Name;
                        result[1] = sequenceNo;
                        result[2] = GetBatchOutputSequence(file.Name, newestTime);

                        eventArgs.Result = result;
                    };

                worker.RunWorkerCompleted += Notify;

                worker.RunWorkerAsync();
            }

            return RepgenRunResult.Okay(sequenceNo, newestTime);
        }
コード例 #12
0
ファイル: RunReport.cs プロジェクト: jdeering/SymSharp
        private List<int> GetPrintSequences(string searchTerm)
        {
            var seqs = new List<int>();
            ISymCommand cmd;

            cmd = new SymCommand("File");
            cmd.Set("Action", "List");
            cmd.Set("MaxCount", "50");
            cmd.Set("Query", "LAST 20 \"+" + searchTerm + "+\"");
            cmd.Set("Type", "Report");
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if (cmd.HasParameter("Sequence"))
                    seqs.Add(int.Parse(cmd.Get("Sequence")));
                cmd = _socket.ReadCommand();
            }

            seqs.Sort();
            seqs.Reverse();
            return seqs;
        }
コード例 #13
0
ファイル: RunReport.cs プロジェクト: jdeering/SymSharp
        public bool IsFileRunning(int sequence)
        {
            if (sequence <= 0)
                throw new ArgumentOutOfRangeException("sequence");

            ISymCommand cmd;
            bool running = false;

            cmd = new SymCommand("Misc");
            cmd.Set("InfoType", "BatchQueues");
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if ((cmd.Get("Action") == "QueueEntry") && (int.Parse(cmd.Get("Seq")) == sequence))
                    running = true;
                else if (cmd.Get("Action") == "Close")
                {
                    Reconnect();
                    cmd = new SymCommand("Misc");
                    cmd.Set("InfoType", "BatchQueues");
                    _socket.Write(cmd);
                }
                else if (cmd.Command == "")
                {
                    cmd = new SymCommand("Misc");
                    cmd.Set("InfoType", "BatchQueues");
                    _socket.Write(cmd);
                }

                cmd = _socket.ReadCommand();
            }

            return running;
        }
コード例 #14
0
ファイル: FileHandling.cs プロジェクト: jdeering/SymSharp
        public string FileRead(string name, FileType type)
        {
            var content = new StringBuilder();

            ISymCommand cmd = new SymCommand("File");
            cmd.Set("Action", "Retrieve");
            cmd.Set("Type", Utilities.FileTypeString(type));
            cmd.Set("Name", name);
            _socket.Write(cmd);

            while (true)
            {
                cmd = _socket.ReadCommand();

                if (cmd.HasParameter("Status"))
                {
                    string status = cmd.Get("Status");
                    if (status.Contains("No such file or directory"))
                        throw new FileNotFoundException();

                    if (status.Contains("Cannot view a blank report"))
                        return "";

                    throw new Exception("Filename Too Long");
                }

                string chunk = cmd.Data;
                if (!string.IsNullOrEmpty(chunk))
                {
                    content.Append(chunk);
                    if (type == FileType.Report)
                        content.Append('\n');
                }

                if (cmd.HasParameter("Done")) break;
            }
            return content.ToString();
        }
コード例 #15
0
ファイル: RunReport.cs プロジェクト: kochste77/SymSharp
        public RepgenRunResult FileRun(File file, FileRunStatus callStatus, FileRunPrompt callPrompt, int queue, RunWorkerCompletedEventHandler Notify = null)
        {
            if (file.Type != FileType.RepGen)
            {
                throw new InvalidOperationException("Cannot run a " + file.FileTypeString() + " file");
            }

            ISymCommand cmd;

            callStatus(RunState.Initializing, file);

            _socket.Write("mm0\u001B");

            WaitForCommand("Input");
            _socket.Write("1\r");

            WaitForCommand("Input");
            _socket.Write("11\r");

            WaitForPrompt("Specification File");
            _socket.Write(file.Name + "\r");
            bool erroredOut = false;

            while (true)
            {
                cmd = _socket.ReadCommand();

                if (cmd.Command == "Input")
                {
                    if (cmd.Get("HelpCode") == "20301")
                    {
                        break;
                    }

                    callStatus(RunState.Prompts, file);

                    string result = callPrompt(cmd.Get("Prompt"));
                    if (result == null) //cancelled
                    {
                        _socket.Write("\u001B");
                        cmd = _socket.ReadCommand();
                        while (cmd.Command != "Input")
                        {
                            cmd = _socket.ReadCommand();
                        }
                        callStatus(RunState.Cancelled, file);
                        return(RepgenRunResult.Cancelled());
                    }

                    _socket.Write(result.Trim() + '\r');
                }
                else if (cmd.Command == "Bell")
                {
                    callStatus(RunState.Prompts, "Invalid Prompt Input, Please Re-Enter");
                }
                else if ((cmd.Command == "Batch") && (cmd.Get("Text") == "No such file or directory"))
                {
                    cmd = _socket.ReadCommand();
                    while (cmd.Command != "Input")
                    {
                        cmd = _socket.ReadCommand();
                    }
                    callStatus(RunState.Failed, "File not found");
                    return(RepgenRunResult.FileNotFound());
                }
                else if (cmd.Command == "SpecfileErr")
                {
                    erroredOut = true;
                }
                else if (erroredOut && (cmd.Command == "Batch") && (cmd.Get("Action") == "DisplayLine"))
                {
                    string err = cmd.Get("Text");
                    cmd = _socket.ReadCommand();
                    while (cmd.Command != "Input")
                    {
                        cmd = _socket.ReadCommand();
                    }
                    callStatus(RunState.Failed, err);
                    return(RepgenRunResult.Error(err));
                }
                else if ((cmd.Command == "Batch") && (cmd.Get("Action") == "DisplayLine"))
                {
                    callStatus(RunState.Initializing, cmd.Get("Text"));
                }
            }

            while (cmd.Get("Prompt").Contains("Specification File"))
            {
                _socket.Write("\r");
                cmd = _socket.ReadCommand();
            }

            WaitForPrompt("Batch Options");
            _socket.Write("0\r");

            Dictionary <int, int> availableQueues = GetQueueList(cmd);

            if (queue < 0)
            {
                queue = GetOpenQueue(availableQueues);
            }

            WaitForPrompt("Batch Queue");
            _socket.Write(queue + "\r");

            WaitForCommand("Input");

            _socket.Write("1\r");
            cmd = _socket.ReadCommand();
            while (cmd.Command != "Input")
            {
                cmd = _socket.ReadCommand();
            }

            cmd = new SymCommand("Misc");
            cmd.Set("InfoType", "BatchQueues");
            _socket.Write(cmd);

            int newestTime = 0;
            int sequenceNo = -1;

            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if (cmd.Get("Action") == "QueueEntry")
                {
                    int currTime = Utilities.ConvertTime(cmd.Get("Time"));

                    if (currTime >= newestTime)
                    {
                        newestTime = currTime;
                        sequenceNo = int.Parse(cmd.Get("Seq"));
                    }
                }
                cmd = _socket.ReadCommand();
            }

            callStatus(RunState.Running, sequenceNo);

            if (Notify != null)
            {
                var worker = new BackgroundWorker();

                worker.DoWork += (sender, eventArgs) =>
                {
                    Thread.Sleep(5000);     // Wait 5 seconds before first check
                    while (IsFileRunning(sequenceNo))
                    {
                        Thread.Sleep(15000);
                    }

                    object[] result = new object[3];
                    result[0] = file.Name;
                    result[1] = sequenceNo;
                    result[2] = GetBatchOutputSequence(file.Name, newestTime);

                    eventArgs.Result = result;
                };

                worker.RunWorkerCompleted += Notify;

                worker.RunWorkerAsync();
            }

            return(RepgenRunResult.Okay(sequenceNo, newestTime));
        }
コード例 #16
0
        public ReportInfo FMRun(string reportName, FileMaintenanceType fmtype, FileRunStatus callStatus, int queue, RunWorkerCompletedEventHandler Notify = null)
        {
            callStatus(RunState.Initializing, reportName);
            ISymCommand cmd;
            string      outTitle = "FM - " + new Random().Next(8388608).ToString("D7");

            _socket.Write("mm0\u001B");
            cmd = WaitForCommand("Input");

            _socket.Write("1\r");
            cmd = WaitForCommand("Input");

            _socket.Write("24\r"); //Misc. Processing
            cmd = WaitForCommand("Input");

            _socket.Write("5\r"); //Batch FM
            cmd = WaitForCommand("Input");

            _socket.Write(((int)fmtype).ToString() + "\r");  //FM File Type
            cmd = WaitForCommand("Input");

            _socket.Write("0\r"); //Undo a Posting? (NO)
            cmd = WaitForCommand("Input");

            _socket.Write(reportName + "\r"); //Title of Batch Report Output to Use as FM Script
            cmd = WaitForCommand("Input");

            _socket.Write("1\r"); //Number of Search Days? (1)
            cmd = WaitForCommand("Input");

            if (fmtype == FileMaintenanceType.Account)
            {
                _socket.Write("1\r"); //Record FM History (YES)
                cmd = WaitForCommand("Input");
            }

            _socket.Write(outTitle + "\r"); //Name of Posting (needed to lookup later)
            cmd = WaitForCommand("Input");

            _socket.Write("1\r"); //Produce Empty Report If No Exceptions? (YES)
            cmd = WaitForCommand("Input");

            _socket.Write("0\r"); //Batch Options? (NO)

            if (queue < 0)
            {
                queue = GetOpenQueue(null);
            }

            _socket.Write(queue.ToString() + "\r"); //write queue
            cmd = WaitForCommand("Input");

            _socket.Write("1\r"); //Okay (to Proceed)? (YES)
            cmd = WaitForCommand("Input");

            //get queues again
            callStatus(RunState.Initializing, "Finding FM Sequence");
            cmd = new SymCommand("Misc");
            cmd.Set("InfoType", "BatchQueues");
            _socket.Write(cmd);

            int newestTime = 0;
            int sequenceNo = -1;

            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if (cmd.Get("Action") == "QueueEntry")
                {
                    int    currTime = 0;
                    string timeStr  = cmd.Get("Time");

                    string[] tokens = timeStr.Split(':');
                    string   seconds = tokens[2], minutes = tokens[1], hours = tokens[0];

                    currTime  = int.Parse(seconds);
                    currTime += 60 * int.Parse(minutes);
                    currTime += 3600 * int.Parse(hours);

                    if (currTime >= newestTime)
                    {
                        newestTime = currTime;
                        sequenceNo = int.Parse(cmd.Get("Seq"));
                    }
                }
                cmd = _socket.ReadCommand();
            }

            callStatus(RunState.Running, sequenceNo);

            if (Notify != null)
            {
                var worker = new BackgroundWorker();

                worker.DoWork += (sender, eventArgs) =>
                {
                    while (IsFileRunning(sequenceNo))
                    {
                        Thread.Sleep(15000);
                    }

                    eventArgs.Result = GetFileMaintenanceSequence(reportName);
                };

                worker.RunWorkerCompleted += Notify;

                worker.RunWorkerAsync();
            }

            return(new ReportInfo(sequenceNo, outTitle));
        }
コード例 #17
0
ファイル: FileMaintenance.cs プロジェクト: jdeering/SymSharp
        public ReportInfo FMRun(string reportName, FileMaintenanceType fmtype, FileRunStatus callStatus, int queue, RunWorkerCompletedEventHandler Notify = null)
        {
            callStatus(RunState.Initializing, reportName);
            ISymCommand cmd;
            string outTitle = "FM - " + new Random().Next(8388608).ToString("D7");

            _socket.Write("mm0\u001B");
            cmd = WaitForCommand("Input");

            _socket.Write("1\r");
            cmd = WaitForCommand("Input");

            _socket.Write("24\r"); //Misc. Processing
            cmd = WaitForCommand("Input");

            _socket.Write("5\r"); //Batch FM
            cmd = WaitForCommand("Input");

            _socket.Write(((int) fmtype).ToString() + "\r"); //FM File Type
            cmd = WaitForCommand("Input");

            _socket.Write("0\r"); //Undo a Posting? (NO)
            cmd = WaitForCommand("Input");

            _socket.Write(reportName + "\r"); //Title of Batch Report Output to Use as FM Script
            cmd = WaitForCommand("Input");

            _socket.Write("1\r"); //Number of Search Days? (1)
            cmd = WaitForCommand("Input");

            if (fmtype == FileMaintenanceType.Account)
            {
                _socket.Write("1\r"); //Record FM History (YES)
                cmd = WaitForCommand("Input");
            }

            _socket.Write(outTitle + "\r"); //Name of Posting (needed to lookup later)
            cmd = WaitForCommand("Input");

            _socket.Write("1\r"); //Produce Empty Report If No Exceptions? (YES)
            cmd = WaitForCommand("Input");

            _socket.Write("0\r"); //Batch Options? (NO)

            if (queue < 0)
            {
                queue = GetOpenQueue(null);
            }

            _socket.Write(queue.ToString() + "\r"); //write queue
            cmd = WaitForCommand("Input");

            _socket.Write("1\r"); //Okay (to Proceed)? (YES)
            cmd = WaitForCommand("Input");

            //get queues again
            callStatus(RunState.Initializing, "Finding FM Sequence");
            cmd = new SymCommand("Misc");
            cmd.Set("InfoType", "BatchQueues");
            _socket.Write(cmd);

            int newestTime = 0;
            int sequenceNo = -1;
            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if (cmd.Get("Action") == "QueueEntry")
                {
                    int currTime = 0;
                    string timeStr = cmd.Get("Time");

                    string[] tokens = timeStr.Split(':');
                    string seconds = tokens[2], minutes = tokens[1], hours = tokens[0];

                    currTime = int.Parse(seconds);
                    currTime += 60*int.Parse(minutes);
                    currTime += 3600*int.Parse(hours);

                    if (currTime >= newestTime)
                    {
                        newestTime = currTime;
                        sequenceNo = int.Parse(cmd.Get("Seq"));
                    }
                }
                cmd = _socket.ReadCommand();
            }

            callStatus(RunState.Running, sequenceNo);

            if (Notify != null)
            {
                var worker = new BackgroundWorker();

                worker.DoWork += (sender, eventArgs) =>
                {
                    while (IsFileRunning(sequenceNo))
                    {
                        Thread.Sleep(15000);
                    }

                    eventArgs.Result = GetFileMaintenanceSequence(reportName);
                };

                worker.RunWorkerCompleted += Notify;

                worker.RunWorkerAsync();
            }

            return new ReportInfo(sequenceNo, outTitle);
        }
コード例 #18
0
ファイル: FileMaintenance.cs プロジェクト: jdeering/SymSharp
        private int GetOpenQueue(Dictionary<int, int> availableQueues)
        {
            int queue;
            ISymCommand cmd = new SymCommand();

            if (availableQueues == null || availableQueues.Count == 0)
                availableQueues = GetQueueList(cmd);

            //get queue counts
            cmd = new SymCommand("Misc");
            cmd.Set("InfoType", "BatchQueues");
            _socket.Write(cmd);

            cmd = _socket.ReadCommand();
            while (!cmd.HasParameter("Done"))
            {
                if ((cmd.Get("Action") == "QueueEntry") && (cmd.Get("Stat") == "Running"))
                    availableQueues[int.Parse(cmd.Get("Queue"))]++;
                cmd = _socket.ReadCommand();
            }

            // Get queue with lowest pending
            int lowestPending = 0;
            queue = 0;
            foreach (var Q in availableQueues)
            {
                if (Q.Value == 0) return Q.Key;

                if (Q.Value < lowestPending)
                {
                    lowestPending = Q.Value;
                    queue = Q.Key;
                }
            }

            return queue;
        }