コード例 #1
0
        /// <summary>
        /// parse from current byte forward in the InputArray. Will either parse a
        /// telnet command or a workstation command.
        /// Route what was parsed to either the FromQueue or the MasterThread. Send to
        /// the FromQueue if still receiving telnet commands. Otherwise, send to the
        /// MasterThread.
        /// </summary>
        /// <param name="InputArray"></param>
        /// <param name="WipCmdList"></param>
        /// <returns></returns>
        private Tuple <WorkstationCommandList, bool> ParseAndPostInputArray(
            InputByteArray InputArray, WorkstationCommandList WipCmdList)
        {
            WorkstationCommandList wipCmdList = null;
            bool gotSomething = false;

            if (WipCmdList == null)
            {
                var telCmd = InputArray.NextTelnetCommand();
                if (telCmd != null)
                {
                    this.TelnetQueue.Enqueue(telCmd);
                    gotSomething = true;
                }
            }

            if (gotSomething == false)
            {
                // peek at the input stream from server. Classify the data that is next
                // to receive.
                var typeData = ServerDataStream.PeekServerCommand(InputArray);
                if (typeData != null)
                {
                    var rv = Process5250.ParseWorkstationCommandList(
                        InputArray, this.SessionSettings);

                    var dsh = rv.Item1;
                    var workstationCmdList = rv.Item2;
                    var gotEOR             = rv.Item3;
                    var needMoreBytes      = rv.Item4;

                    // update connectionComplete flag and typeDevice depending on the stream
                    // code of the datastream header.
                    if ((this.ConnectionComplete == false) && (dsh != null) && (dsh.StreamCode != null))
                    {
                        this.ConnectionComplete = true;
                        if (dsh.StreamCode.Value == DataStreamCode.Terminal)
                        {
                            this.TypeDevice = TypeTelnetDevice.Terminal;
                        }
                        else
                        {
                            this.TypeDevice = TypeTelnetDevice.Printer;
                        }

                        // post message to telnet queue so that the ConnectionThread on the
                        // other end will know to shutdown.
                        var message = new TelnetDeviceAttrMessage(this.TypeDevice.Value);
                        this.TelnetQueue.Enqueue(message);
                    }

                    // got data stream header.
                    if (dsh != null)
                    {
                        if (this.ConnectionComplete == false)
                        {
                            this.TelnetQueue.Enqueue(dsh);
                        }
                        else
                        {
                            var message = new DataStreamHeaderMessage(dsh);
                            PostToProcessQueue(message);
                        }
                        gotSomething = true;
                    }

                    if (workstationCmdList != null)
                    {
                        gotSomething = true;
                    }

                    // accum the workstationCmdList
                    if (WipCmdList == null)
                    {
                        wipCmdList = workstationCmdList;
                    }
                    else
                    {
                        wipCmdList = WipCmdList;
                        wipCmdList.AddRange(workstationCmdList);
                    }

                    // got EOR.  store the now completed workstationCmdList.
                    if ((gotEOR == true) && (wipCmdList != null))
                    {
                        var msg = new WorkstationCommandListMessage(wipCmdList);
                        PostToProcessQueue(msg);
                        gotSomething = true;
                        wipCmdList   = null;
                    }
                }
            }

            return(new Tuple <WorkstationCommandList, bool>(wipCmdList, gotSomething));
        }
コード例 #2
0
        ParseDataStream(
            InputByteArray inputArray, SessionSettings sessionSettings,
            string DataStreamName, TypeTelnetDevice?TypeDevice = null)
        {
            var accumCmdList                   = new WorkstationCommandList();
            var responseItemList               = new ResponseItemList();
            TelnetCommandList   telList        = null;
            ResponseHeader      curRespHeader  = null;
            ResponseHeader      nextRespHeader = null;
            DataStreamHeader    dsh            = null;
            ControlFunctionList funcList       = null;

            bool didParse = true;

            while ((didParse == true) && (inputArray.RemainingLength > 0))
            {
                didParse       = false;
                curRespHeader  = nextRespHeader;
                nextRespHeader = null;

                if ((didParse == false) && (dsh == null))
                {
                    var telCmd = inputArray.NextTelnetCommand();
                    if (telCmd != null)
                    {
                        if (telList == null)
                        {
                            telList = new TelnetCommandList();
                        }
                        telList.Add(telCmd);
                        var s1 = telCmd.ToString();
                        didParse = true;
                    }
                }

                // parse the data stream header.
                if ((didParse == false) && (dsh == null))
                {
                    var code = inputArray.PeekDataStreamCode();
                    if (code != null)
                    {
                        var rv = DataStreamHeader.Factory(inputArray);
                        dsh      = rv.Item1;
                        didParse = true;

                        // update the type of device depending on data stream header stream
                        // code.
                        if ((TypeDevice == null) && (dsh != null) && (dsh.Errmsg == null))
                        {
                            TypeDevice = dsh.StreamCode.ToTypeTelnetDevice();
                        }
                    }
                }

                // parse as a sequence of workstation commands.
                if (didParse == false)
                {
                    if ((TypeDevice == null) || (TypeDevice.Value != TypeTelnetDevice.Printer))
                    {
                        var rv = Process5250.ParseWorkstationCommandList(
                            inputArray, sessionSettings);

                        var anotherDsh    = rv.Item1;
                        var wrkstnCmdList = rv.Item2;

                        if ((anotherDsh != null) && (anotherDsh.Errmsg == null))
                        {
                            didParse = true;
                            dsh      = anotherDsh;
                        }

                        // draw the fields and literals on the canvas.
                        if (wrkstnCmdList?.Count > 0)
                        {
                            accumCmdList.Append(wrkstnCmdList);
                            didParse = true;
                        }
                    }
                }

                // parse as sequence of SCS control functions. ( printer data stream ).
                if (didParse == false)
                {
                    if ((TypeDevice == null) || (TypeDevice.Value == TypeTelnetDevice.Printer))
                    {
                        var rv = ControlFunctionList.ParseDataStream(inputArray);
                        if (rv.Item1?.Count > 0)
                        {
                            didParse = true;
                            funcList = rv.Item1;
                        }
                    }
                }

                // parse as response stream header.
                if ((didParse == false) &&
                    (ResponseHeader.IsResponseHeader(inputArray).Item1 == true))
                {
                    curRespHeader = new ResponseHeader(inputArray);
                    didParse      = true;

                    responseItemList.Add(curRespHeader);
                    var rv = Response5250.ParseResponseStream(inputArray, curRespHeader);
                    responseItemList.Append(rv.Item1);
                }
            }

            return(new Tuple <WorkstationCommandList, ResponseItemList,
                              DataStreamHeader, TelnetCommandList, ControlFunctionList>(
                       accumCmdList, responseItemList, dsh, telList, funcList));
        }
コード例 #3
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            string itemText = null;

            if (sender is MenuItem)
            {
                itemText = (sender as MenuItem).Header as string;
            }

            if (itemText == "Test")
            {
                var logList     = new TelnetLogList();
                var negSettings = NegotiateSettings.Build5250Settings("SRICHTER", "Steve25");

                var lines = System.IO.File.ReadAllLines("c:\\downloads\\hextext.txt");
                var ba    = lines.HexTextLinesToBytes();

                // print the bytes of the response stream as lines of hex text.
                {
                    var rep = ba.ToHexReport(16);
                    logList.AddItem(Direction.Read, "Length:" + ba.Length + " Byte stream bytes:");
                    logList.AddItems(Direction.Read, rep);
                }

                var inputArray      = new InputByteArray(ba, ba.Length);
                var sessionSettings = new SessionSettings();

                var rv = Process5250.ParseWorkstationCommandList(
                    inputArray, sessionSettings);

                var dsh           = rv.Item1;
                var wrkstnCmdList = rv.Item2;

                // draw the fields and literals on the canvas.
                if (wrkstnCmdList != null)
                {
                    foreach (var workstationCmd in wrkstnCmdList)
                    {
                    }
                }
                return;
            }

            else if (itemText == "Parse server stream")
            {
                var ba = this.Model.ParseTextLines.HexTextLinesToBytes( );

                // print the bytes of the response stream as lines of hex text.
                {
                    TelnetLogList logList = new TelnetLogList();
                    var           rep     = ba.ToHexReport(16);
                    logList.AddItem(Direction.Read, "Length:" + ba.Length + " Byte stream bytes:");
                    logList.AddItems(Direction.Read, rep);
                }
            }

            else if (itemText == "Parse response stream")
            {
                var logList     = new TelnetLogList();
                var negSettings = NegotiateSettings.Build5250Settings("SRICHTER", "Steve25");

                var lines = System.IO.File.ReadAllLines("c:\\downloads\\hextext.txt");
                var ba    = lines.HexTextLinesToBytes();

                // print the bytes of the response stream as lines of hex text.
                {
                    var rep = ba.ToHexReport(16);
                    logList.AddItem(Direction.Read, "Length:" + ba.Length + " Byte stream bytes:");
                    logList.AddItems(Direction.Read, rep);
                }

                {
                    var inputArray = new InputByteArray(ba);
                    var rv         = Response5250.ParseResponseStream(inputArray);
                    foreach (var respItem in rv.Item1)
                    {
                        this.Model.RunLog.Add(respItem.ToString());
                    }
                }

                foreach (var item in logList)
                {
                    if (item.NewGroup == true)
                    {
                        this.Model.RunLog.Add("");
                    }
                    this.Model.RunLog.Add(item.Text);
                }

                return;
            }

            else if (itemText == "Exit")
            {
                this.Close();
            }

            else if (itemText == "Settings")
            {
            }

            else if (itemText == "Print")
            {
                LinePrinter.PrintLines(this.Model.RunLog);
            }
            else if (itemText == "Clear log")
            {
                Model.RunLog.Clear();
            }
        }