private static IEnumerable <string> ReportParseResults(
            DataStreamHeader dsHeader, WorkstationCommandList wrkstnCmdList,
            ResponseItemList responseList, TelnetCommandList telList)
        {
            var report = new List <string>();

            if (dsHeader != null)
            {
                report.AddRange(dsHeader.ToColumnReport());
            }

            if (wrkstnCmdList != null)
            {
                report.AddRange(wrkstnCmdList.ToColumnReport());
            }

            if (responseList != null)
            {
                report.AddRange(responseList.ReportResponseItems());
            }

            if (telList != null)
            {
                report.AddRange(telList.ToColumnReport());
            }

            return(report);
        }
Example #2
0
        private void ProcessAndPostBytesReceived(byte[] recvBytes)
        {
            // load bytes received from the server into InputArray.
            var inputArray = new InputByteArray(recvBytes);

            WorkstationCommandList wipCmdList = null;
            bool badDataLogged = false;

            while (inputArray.IsEof() == false)
            {
                var rv = ParseAndPostInputArray(inputArray, wipCmdList);
                wipCmdList = rv.Item1;
                var gotSomething = rv.Item2;

                // nothing parsed. And there is data remaining. This is an error.
                if ((gotSomething == false) && (inputArray.IsEof() == false))
                {
                    if (badDataLogged == false)
                    {
                        LogBadData(inputArray);
                        badDataLogged = true;
                    }
                    inputArray.GetByte(); // advance by 1 byte in byte stream.
                }
            }
        }
        public static Tuple <WorkstationCommandList, TelnetLogList> GetAndParseWorkstationCommandList(
            NetworkStreamBackedInputByteArray InputArray,
            SessionSettings SessionSettings)
        {
            TelnetLogList logList       = new TelnetLogList();
            var           wrkstnCmdList = new WorkstationCommandList();

            var dsh = new DataStreamHeader(InputArray);

            if (dsh != null)
            {
                logList.AddItems(Direction.Read, dsh.ToReportLines( ), true);
            }

            if ((dsh != null) && (dsh.Errmsg == null))
            {
                bool lastCmdWasTelnet_EOR = false;
                while (dsh != null)
                {
                    // read available bytes from input stream.
                    if (InputArray.IsEof() && (lastCmdWasTelnet_EOR == false))
                    {
                        var log = InputArray.ReadFromNetworkStream(5, 5);
                        logList.AddItems(log);
                    }

                    // no input data to process.
                    if (InputArray.IsEof())
                    {
                        break;
                    }
                    lastCmdWasTelnet_EOR = false;

                    // check for IAC EOR
                    var telCode = InputArray.PeekTelnetCommandCode(CommandCode.EOR);
                    if (telCode != null)
                    {
                        var telCmd = InputArray.NextTelnetCommand();
                        logList.AddItems(Direction.Read, telCmd.ToReportLines(), true);
                        lastCmdWasTelnet_EOR = true;
                    }

                    // process the input as workstation data stream commands.
                    else
                    {
                        var rv = ParseAndProcessWorkstationCommand(InputArray, dsh);
                        var workstationCommand = rv.Item1;
                        dsh = rv.Item3;
                        logList.AddItems(rv.Item4);

                        if (workstationCommand != null)
                        {
                            wrkstnCmdList.Add(workstationCommand);
                        }
                    }
                }
            }
            return(new Tuple <WorkstationCommandList, TelnetLogList>(wrkstnCmdList, logList));
        }
        public static Tuple <bool, TelnetLogList> PaintCanvas(
            this WorkstationCommandList CmdList, ItemCanvas ItemCanvas, TelnetLogList LogList = null)
        {
            TelnetLogList logList  = new TelnetLogList();
            bool          drawDone = false;
            OneRowCol     caret    = null;

            foreach (var cmdBase in CmdList)
            {
                if ((cmdBase is ClearUnitCommand) || (cmdBase is ClearUnitAlternateCommand))
                {
                    ItemCanvas.EraseScreen();
                }

                else if (cmdBase is WriteToDisplayCommand)
                {
                    // store the painted from wtdCommand in the ItemCanvas itself. Used when
                    // ScreenDefn imports a screen layout into the defn of a screen.
                    ItemCanvas.WriteToDisplayCommand = cmdBase as WriteToDisplayCommand;

                    bool eraseScreen = false;
                    var  rv          = ItemCanvas.WriteToDisplayCommand.PaintCanvas(
                        ItemCanvas, eraseScreen, LogList);
                    var localDrawDone = rv.Item1;
                    if (rv.Item2 != null)
                    {
                        caret = rv.Item2;
                    }

                    if (localDrawDone == true)
                    {
                        drawDone = true;
                    }
                }
            }

            ItemCanvas.PositionCaret(caret);

            return(new Tuple <bool, TelnetLogList>(drawDone, logList));
        }
        /// <summary>
        /// run the BuildShowItemList method against the first WriteToDisplay command in
        /// the list of workstation commands.
        /// </summary>
        /// <param name="LogList"></param>
        /// <returns></returns>
        public static ShowItemList BuildShowItemList(
            this WorkstationCommandList CommandList, ScreenDim ScreenDim, TelnetLogList LogList)
        {
            ShowItemList showItemList = null;
            OneRowCol    caret        = null;

            foreach (var workstationCommand in CommandList)
            {
                if (workstationCommand is WriteToDisplayCommand)
                {
                    var           wtdCmd  = workstationCommand as WriteToDisplayCommand;
                    TelnetLogList logList = new TelnetLogList();
                    var           rv      = wtdCmd.BuildShowItemList(ScreenDim, logList);
                    showItemList = rv.Item1;
                    if (rv.Item2 != null)
                    {
                        caret = rv.Item2;
                    }
                    break;
                }
            }
            return(showItemList);
        }
Example #6
0
        /// <summary>
        /// apply the commands of the workstation command list to the screen content
        /// block.
        /// </summary>
        /// <param name="applyMaster"></param>
        /// <param name="CmdList"></param>
        /// <param name="ToThread"></param>
        /// <param name="LogList"></param>
        /// <returns></returns>
        public static Tuple <bool, ScreenContent> Apply(
            this ScreenContent InBaseMaster,
            WorkstationCommandList CmdList,
            ToThread ToThread, PaintThread PaintThread, TelnetLogList LogList)
        {
            bool wtdApplied = false;
            var  baseMaster = InBaseMaster;
            var  master     = baseMaster.GetWorkingContentBlock();

            foreach (var cmdBase in CmdList)
            {
                if (cmdBase is ClearUnitCommand)
                {
                    var rv = ProcessClearUnit(baseMaster, baseMaster.ScreenDim, PaintThread);
                    baseMaster = rv.Item1;
                    master     = rv.Item2;
                }

                // same as ClearUnit. Only signals that a wide screen to be used.
                else if (cmdBase is ClearUnitAlternateCommand)
                {
                    var cua = cmdBase as ClearUnitAlternateCommand;

                    // screen size.
                    ScreenDim screenDim;
                    if (cua.RequestByte == 0x00)
                    {
                        screenDim = new ScreenDim(27, 132);
                    }
                    else
                    {
                        screenDim = new ScreenDim(24, 80);
                    }

                    var rv = ProcessClearUnit(baseMaster, screenDim, PaintThread);
                    baseMaster = rv.Item1;
                    master     = rv.Item2;
                }

                // apply the orders of the WriteToDisplay command.
                else if (cmdBase is WriteToDisplayCommand)
                {
                    var curMaster = master.Apply(cmdBase as WriteToDisplayCommand);
                    master     = curMaster;
                    wtdApplied = true;
                }

                else if (cmdBase is ReadMdtFieldsCommand)
                {
                    master.HowRead = HowReadScreen.ReadMdt;
                }

                // save screen command. Build response, send back to server.
                else if (cmdBase is SaveScreenCommand)
                {
                    var msg = new SaveScreenMessage(master.Copy());
                    ToThread.PostInputMessage(msg);
                }

                // read screen command. Build response, send back to server.
                else if (cmdBase is ReadScreenCommand)
                {
                    var msg = new ReadScreenMessage(master.Copy());
                    ToThread.PostInputMessage(msg);
                }

                else if (cmdBase is WriteStructuredFieldCommand)
                {
                    var wsfCmd = cmdBase as WriteStructuredFieldCommand;
                    if (wsfCmd.RequestCode == WSF_RequestCode.Query5250)
                    {
                        var msg = new Query5250ResponseMessage();
                        ToThread.PostInputMessage(msg);
                    }
                }
                else if (cmdBase is WriteSingleStructuredFieldCommand)
                {
                }
            }
            return(new Tuple <bool, ScreenContent>(wtdApplied, baseMaster));
        }
        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));
        }
        public static void ProcessAndPaint(
            this WorkstationCommandList CmdList, TcpClient TcpClient,
            ItemCanvas ItemCanvas, Window Window,
            TelnetLogList LogList = null)
        {
            OneRowCol caret = null;

            foreach (var cmdBase in CmdList)
            {
                if ((cmdBase is ClearUnitCommand) || (cmdBase is ClearUnitAlternateCommand))
                {
                    ItemCanvas.EraseScreen();
                    caret = null;
                }

                else if (cmdBase is WriteToDisplayCommand)
                {
                    bool doEraseScreen = false;
                    var  WTD_Command   = cmdBase as WriteToDisplayCommand;
                    ItemCanvas.WriteToDisplayCommand = WTD_Command;
                    var localCaret = ItemCanvas.PaintScreen(WTD_Command, doEraseScreen, LogList);
                    if (localCaret != null)
                    {
                        caret = localCaret;
                    }
                }

                else if (cmdBase is ReadMdtFieldsCommand)
                {
                    ItemCanvas.HowRead = HowReadScreen.ReadMdt;
                }

                // save screen command. Build response, send back to server.
                else if (cmdBase is SaveScreenCommand)
                {
                    var ra = SaveScreenCommandExt.BuildSaveScreenResponse(
                        ItemCanvas.VisualItems, ItemCanvas.CaretCursor);

                    // send response stream back to server.
                    if (TcpClient != null)
                    {
                        TelnetConnection.WriteToHost(
                            null, ra, TcpClient.GetStream());
                    }
                }

                else if (cmdBase is WriteStructuredFieldCommand)
                {
                    var wsfCmd = cmdBase as WriteStructuredFieldCommand;
                    if (wsfCmd.RequestCode == WSF_RequestCode.Query5250)
                    {
                        var ra = Query5250Response.BuildQuery5250Response();

                        // send response stream back to server.
                        if (TcpClient != null)
                        {
                            TelnetConnection.WriteToHost(LogList, ra, TcpClient.GetStream());
                        }
                    }
                }
                else if (cmdBase is WriteSingleStructuredFieldCommand)
                {
                }
            }

            ItemCanvas.PositionCaret(caret);
        }
        ProcessWorkstationDataStream(
            this ServerConnectPack ConnectPack, ScreenVisualItems VisualItems,
            CanvasPositionCursor Caret)
        {
            WorkstationCommandList       workstationCmdList = null;
            List <WriteToDisplayCommand> wtdCmdList         = null;
            DataStreamHeader             dsh = null;
            var           returnCmdList      = new WorkstationCommandList();
            HowReadScreen?howRead            = null;
            var           logList            = new TelnetLogList();
            bool          gotEOR             = false;

            while (gotEOR == false)
            {
                // input array is eof. Exit loop if have read a READ workstn command.
                // Otherwise, read from server.
                if (ConnectPack.ReadBlocks.IsEmpty == true)
                {
                    if (howRead != null)
                    {
                        break;
                    }
                }

                var item = ConnectPack.ReadBlocks.WaitAndDequeue();

                if (item is DataStreamHeader)
                {
                    dsh = item as DataStreamHeader;
                    continue;
                }

                gotEOR = true;
                if (item is WorkstationCommandList)
                {
                    workstationCmdList = item as WorkstationCommandList;

                    foreach (var workstationCmd in workstationCmdList)
                    {
                        if (workstationCmd is ClearUnitCommand)
                        {
                            returnCmdList.Add(workstationCmd);
                        }

                        // WTD command. Add to list of WTD commands. This list is returned to
                        // the caller of this method.
                        else if (workstationCmd is WriteToDisplayCommand)
                        {
                            returnCmdList.Add(workstationCmd);
                            var wtdCommand = workstationCmd as WriteToDisplayCommand;
                            if (wtdCmdList == null)
                            {
                                wtdCmdList = new List <WriteToDisplayCommand>();
                            }
                            wtdCmdList.Add(wtdCommand);
                        }

                        else if (workstationCmd is ReadMdtFieldsCommand)
                        {
                            howRead = HowReadScreen.ReadMdt;
                        }

                        // save screen command. Build response, send back to server.
                        else if (workstationCmd is SaveScreenCommand)
                        {
                            var ra =
                                SaveScreenCommandExt.BuildSaveScreenResponse(VisualItems, Caret);

                            // send response stream back to server.
                            {
                                TelnetConnection.WriteToHost(
                                    logList, ra, ConnectPack.TcpClient.GetStream());
                                gotEOR = false;
                            }
                        }

                        else if (workstationCmd is WriteStructuredFieldCommand)
                        {
                            var wsfCmd = workstationCmd as WriteStructuredFieldCommand;
                            if (wsfCmd.RequestCode == WSF_RequestCode.Query5250)
                            {
                                var ra = Query5250Response.BuildQuery5250Response();

                                // send response stream back to server.
                                {
                                    TelnetConnection.WriteToHost(
                                        logList, ra, ConnectPack.TcpClient.GetStream());
                                    gotEOR = false;
                                }
                            }
                        }
                    }
                }
            }

            return(new Tuple <HowReadScreen?, List <WriteToDisplayCommand>,
                              TelnetLogList, WorkstationCommandList, DataStreamHeader, bool>(
                       howRead, wtdCmdList, logList, returnCmdList, dsh, gotEOR));
        }
        ProcessWorkstationDataStream(
            this ConnectedSocketPack SocketPack, ScreenVisualItems VisualItems,
            CanvasPositionCursor Caret)
        {
            WorkstationCommandList       workstationCmdList = null;
            List <WriteToDisplayCommand> wtdCmdList         = null;
            DataStreamHeader             dsh = null;
            var           returnCmdList      = new WorkstationCommandList();
            HowReadScreen?howRead            = null;
            var           logList            = new TelnetLogList();
            bool          gotEOR             = false;

            while (gotEOR == false)
            {
                // input array is eof. Exit loop if have read a READ workstn command.
                // Otherwise, read from server.
                if (SocketPack.InputArray.IsEof() == true)
                {
                    if (howRead != null)
                    {
                        break;
                    }
                    {
                        var log = SocketPack.InputArray.ReadFromNetworkStream(10, 60);
                        logList.AddItems(log);
                        if (SocketPack.InputArray.IsEof() == true)
                        {
                            break;
                        }
                    }
                }

                // peek at the input stream from server. Classify the data that is next
                // to receive.
                var typeData = ServerDataStream.PeekServerCommand(SocketPack.InputArray);

                // input data not recogizied. Not a 5250 data strem header.
                if (typeData == null)
                {
                    logList.AddItem(Direction.Read, "Unknown data stream data");
                    logList.AddItems(
                        Direction.Read, SocketPack.InputArray.PeekBytes().ToHexReport(16));
                    break;
                }

                if (typeData.Value == TypeServerData.workstationHeader)
                {
                    {
                        var rv = Process5250.GetAndParseWorkstationCommandList(
                            SocketPack.InputArray, SocketPack.Settings);
                        dsh = rv.Item1;
                        workstationCmdList = rv.Item2;
                        logList.AddItems(rv.Item3);
                        gotEOR = rv.Item4;
                    }

                    foreach (var workstationCmd in workstationCmdList)
                    {
                        if (workstationCmd is ClearUnitCommand)
                        {
                            returnCmdList.Add(workstationCmd);
                        }

                        // WTD command. Add to list of WTD commands. This list is returned to the
                        // caller of this method.
                        else if (workstationCmd is WriteToDisplayCommand)
                        {
                            returnCmdList.Add(workstationCmd);
                            var wtdCommand = workstationCmd as WriteToDisplayCommand;
                            if (wtdCmdList == null)
                            {
                                wtdCmdList = new List <WriteToDisplayCommand>();
                            }
                            wtdCmdList.Add(wtdCommand);
                        }

                        else if (workstationCmd is ReadMdtFieldsCommand)
                        {
                            howRead = HowReadScreen.ReadMdt;
                        }

                        // save screen command. Build response, send back to server.
                        else if (workstationCmd is SaveScreenCommand)
                        {
                            var ra = SaveScreenCommandExt.BuildSaveScreenResponse(VisualItems, Caret);

                            // send response stream back to server.
                            {
                                TelnetConnection.WriteToHost(logList, ra, SocketPack.TcpStream);
                                gotEOR = false;
                            }
                        }

                        else if (workstationCmd is WriteStructuredFieldCommand)
                        {
                            var wsfCmd = workstationCmd as WriteStructuredFieldCommand;
                            if (wsfCmd.RequestCode == WSF_RequestCode.Query5250)
                            {
                                var ra = Query5250Response.BuildQuery5250Response();

                                // send response stream back to server.
                                {
                                    TelnetConnection.WriteToHost(logList, ra, SocketPack.TcpStream);
                                    gotEOR = false;
                                }
                            }
                        }
                        else if (workstationCmd is WriteSingleStructuredFieldCommand)
                        {
                        }
                    }
                }
            }
            return(new Tuple <HowReadScreen?, List <WriteToDisplayCommand>,
                              TelnetLogList, WorkstationCommandList, DataStreamHeader, bool>(
                       howRead, wtdCmdList, logList, returnCmdList, dsh, gotEOR));
        }
Example #11
0
 public WorkstationCommandListMessage(
     WorkstationCommandList WorkstationCommandList)
 {
     this.WorkstationCommandList = WorkstationCommandList;
 }
        ProcessWorkstationDataStream(this ConnectedSocketPack SocketPack)
        {
            WorkstationCommandList       workstationCmdList = null;
            List <WriteToDisplayCommand> wtdCmdList         = null;
            HowReadScreen?howRead = null;
            var           logList = new TelnetLogList();

            while (true)
            {
                // input array is eof. Exit loop if have read a READ workstn command.
                // Otherwise, read from server.
                if (SocketPack.InputArray.IsEof( ) == true)
                {
                    if (howRead != null)
                    {
                        break;
                    }
                    {
                        var log = SocketPack.InputArray.ReadFromNetworkStream(20, 30);
                        logList.AddItems(log);
                        if (SocketPack.InputArray.IsEof() == true)
                        {
                            break;
                        }
                    }
                }

                // peek at the input stream from server. Classify the data that is next
                // to receive.
                var typeData = ServerDataStream.PeekServerCommand(SocketPack.InputArray);

                // input data not recogizied. Not a 5250 data strem header.
                if (typeData == null)
                {
                    logList.AddItem(Direction.Read, "Unknown data stream data");
                    logList.AddItems(
                        Direction.Read, SocketPack.InputArray.PeekBytes().ToHexReport(16));
                    break;
                }

                if (typeData.Value == TypeServerData.workstationHeader)
                {
                    {
                        var rv = Process5250.GetAndParseWorkstationCommandList(
                            SocketPack.InputArray, SocketPack.Settings);

                        workstationCmdList = rv.Item1;
                        logList.AddItems(rv.Item2);
                    }

                    foreach (var workstationCmd in workstationCmdList)
                    {
                        if (workstationCmd is ClearUnitCommand)
                        {
                        }

                        else if (workstationCmd is WriteToDisplayCommand)
                        {
                            var wtdCommand = workstationCmd as WriteToDisplayCommand;
                            if (wtdCmdList == null)
                            {
                                wtdCmdList = new List <WriteToDisplayCommand>();
                            }
                            wtdCmdList.Add(wtdCommand);
                        }

                        else if (workstationCmd is ReadMdtFieldsCommand)
                        {
                            howRead = HowReadScreen.ReadMdt;
                        }

                        // save screen command. Build response, send back to server.
                        else if (workstationCmd is SaveScreenCommand)
                        {
                            var ra = SaveScreenCommand.BuildSaveScreenResponse();

                            Debug.WriteLine("Response: " + ra.ToHex(' '));

                            // send response stream back to server.
                            {
                                TelnetConnection.WriteToHost(logList, ra, SocketPack.TcpStream);
                            }
                            // BgnTemp
                            logList.AddSpecialItem(LogItemSpecial.NewGeneration);
                            // EndTemp
                        }

                        else if (workstationCmd is WriteStructuredFieldCommand)
                        {
                            var wsfCmd = workstationCmd as WriteStructuredFieldCommand;
                            if (wsfCmd.RequestCode == WSF_RequestCode.Query5250)
                            {
                                var ra = Query5250Response.BuildQuery5250Response();

                                Debug.WriteLine("Response: " + ra.ToHex(' '));

                                // send response stream back to server.
                                {
                                    TelnetConnection.WriteToHost(logList, ra, SocketPack.TcpStream);
                                }
                            }
                        }
                    }
                }
            }
            return(new Tuple <HowReadScreen?, List <WriteToDisplayCommand>, TelnetLogList>(
                       howRead, wtdCmdList, logList));
        }
Example #13
0
        ParseWorkstationCommandList(
            InputByteArray InputArray,
            SessionSettings SessionSettings)
        {
            var wrkstnCmdList              = new WorkstationCommandList();
            DataStreamHeader dsh           = null;
            bool             gotEOR        = false;
            bool             needMoreBytes = false;
            string           errmsg        = null;

            if (InputArray.IsDataStreamHeader())
            {
                var rv = DataStreamHeader.Factory(InputArray);
                dsh    = rv.Item1;
                errmsg = rv.Item2;
            }

            bool lastCmdWasTelnet_EOR  = false;
            bool gotWorkstationCommand = true;

            gotEOR = false;
            while ((InputArray.IsEof( ) == false) && (gotEOR == false) &&
                   (gotWorkstationCommand == true))
            {
                // no input data to process.
                lastCmdWasTelnet_EOR  = false;
                gotWorkstationCommand = false;

                // check for IAC EOR
                var telCode = InputArray.PeekTelnetCommandCode(CommandCode.EOR);
                if (telCode != null)
                {
                    var telCmd = InputArray.NextTelnetCommand();
                    lastCmdWasTelnet_EOR = true;
                    gotEOR = true;
                }

                // process the input as workstation data stream commands.
                else
                {
                    var rv = ParseAndProcessWorkstationCommand(InputArray);
                    var workstationCommand = rv.Item1;
                    var howRead            = rv.Item2;

                    if (workstationCommand != null)
                    {
                        wrkstnCmdList.Add(workstationCommand);
                        gotWorkstationCommand = true;
                    }
                }
            }

            // read available bytes from input stream.
            if (InputArray.IsEof() && (lastCmdWasTelnet_EOR == false))
            {
                needMoreBytes = true;
            }

            return(new Tuple <DataStreamHeader, WorkstationCommandList, bool, bool>(
                       dsh, wrkstnCmdList, gotEOR, needMoreBytes));
        }
Example #14
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));
        }