private void butParseResponse_Click(object sender, RoutedEventArgs e) { var logList = new TelnetLogList(); var text = TextBox1.Text; var lines = text.Split( new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); var ba = ParseHexLines(lines); Process5250.ParseResponseStream(logList, ba); foreach (var item in logList) { if (item.NewGroup == true) { this.Model.RunLog.Add(""); } this.Model.RunLog.Add(item.Text); } // 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); } }
void NewParse() { var logList = new TelnetLogList(); var text = TextBox1.Text; var lines = text.Split( new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); var ba = ParseHexLines(lines); var inputArray = new NetworkStreamBackedInputByteArray(ba, ba.Length); var sessionSettings = new SessionSettings(); Process5250.ParseResponseStream(logList, ba); foreach (var item in logList) { if (item.NewGroup == true) { this.Model.RunLog.Add(""); } this.Model.RunLog.Add(item.Text); } // peek at the input stream from server. Classify the data that is next // to receive. var typeData = ServerDataStream.PeekServerCommand(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, inputArray.PeekBytes().ToHexReport(16)); } else if (typeData.Value == TypeServerData.workstationHeader) { { var rv = Process5250.GetAndParseWorkstationCommandList( inputArray, sessionSettings); var workstationCmdList = rv.Item1; logList.AddItems(rv.Item2); } } }
public TelnetLogList ParseDataStream( NetworkStreamBackedInputByteArray inputArray, SessionSettings sessionSettings) { var logList = new TelnetLogList(); bool didParse = true; while ((didParse == true) && (inputArray.RemainingLength > 0)) { didParse = false; if (didParse == false) { var telCmd = inputArray.NextTelnetCommand(); if (telCmd != null) { var s1 = telCmd.ToString(); logList.AddItem(Direction.Read, s1); didParse = true; } } if (didParse == false) { var rv = Process5250.GetAndParseWorkstationCommandList( inputArray, sessionSettings); logList.AddItems(rv.Item2); var wrkstnCmdList = rv.Item1; // draw the fields and literals on the canvas. if (wrkstnCmdList?.Count > 0) { didParse = true; foreach (var workstationCmd in wrkstnCmdList) { } } } } return(logList); }
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)); }
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)); }
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 = ParseHexLines(lines); // 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 NetworkStreamBackedInputByteArray(ba, ba.Length); var sessionSettings = new SessionSettings(); var rv = Process5250.GetAndParseWorkstationCommandList( inputArray, sessionSettings); logList.AddItems(rv.Item2); var wrkstnCmdList = rv.Item1; // draw the fields and literals on the canvas. if (wrkstnCmdList != null) { foreach (var workstationCmd in wrkstnCmdList) { } } foreach (var item in logList) { this.Model.RunLog.Add(item.Text); } return; } else if (itemText == "Parse server stream") { var text = TextBox1.Text; var lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); var ba = ParseHexLines(lines); // 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 = ParseHexLines(lines); // 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); } Process5250.ParseResponseStream(logList, ba); 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(); } }
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)); }
/// <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)); }