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)); }