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); } }
private static void WriteToHost( TelnetLogList LogList, byte[] Buffer, NetworkStream NetStream) { if (NetStream.CanWrite == true) { LogList.Write(Direction.Write, Buffer); { string hexText = Buffer.ToHex(' '); LogList.AddItem(Direction.Write, "Hex: " + Buffer.Length.ToString() + " " + hexText); } NetStream.Write(Buffer, 0, Buffer.Length); } else { LogList.AddItem(Direction.Write, "Error. Could not write to network stream."); } }
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 OneRowCol PaintScreen( WriteToDisplayCommand WTD_command, bool Erase = true, TelnetLogList LogList = null) { if (Erase == true) { this.EraseScreen(); if (LogList != null) { LogList.AddItem(Direction.Read, "PaintScreen. EraseScreen."); } } this.ShowItemList = null; var caret = PaintScreen_Actual(WTD_command, LogList); return(caret); }
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); }
/// <summary> /// create list of ShowLiteralItem and ShowFieldItem from the list of orders of /// a WriteToDisplay command. /// </summary> /// <param name="WtdCommand"></param> /// <param name="LogList"></param> /// <returns></returns> public static Tuple <ShowItemList, OneRowCol> BuildShowItemList( this WriteToDisplayCommand WtdCommand, ScreenDim ScreenDim, TelnetLogList LogList) { var itemList = new ShowItemList(); IRowCol curRowCol = new ZeroRowCol(0, 0); OneRowCol caret = null; foreach (var order in WtdCommand.OrderList) { bool newGroup = false; if ((order.OrderCode == WtdOrder.SetBufferAddress) || (order.OrderCode == WtdOrder.StartHeader)) { newGroup = true; } LogList.AddItem(Direction.Read, order.ToString(), newGroup); LogList.AddItem(Direction.Read, order.ToHexString()); if (order is TextDataOrder) { var tdo = order as TextDataOrder; var s1 = tdo.ShowText; if ((tdo.AttrByte != null) || (s1.Length > 0) || (tdo.TailAttrByte != null)) { var litItem = new ShowLiteralItem( (ZeroRowCol)curRowCol, tdo.AttrByte, s1, tdo.TailAttrByte); litItem.tdo_Length = s1.Length; itemList.Add(litItem); curRowCol = curRowCol.Advance(litItem.ItemLength()); } } else if (order.OrderCode == WtdOrder.StartField) { var sfo = order as StartFieldOrder; var lx = sfo.LL_Length; var attrByte = sfo.AttrByte; var fldItem = new ShowFieldItem((ZeroRowCol)curRowCol, sfo.AttrByte, ShowUsage.Both, ShowDtyp.Char, lx); fldItem.IsMonocase = sfo.IsMonocase; fldItem.sfo_FCW = sfo.FCW_Bytes; fldItem.sfo_FFW = sfo.FFW_Bytes; fldItem.sfo_Length = sfo.LL_Length; fldItem.IsNonDisplay = sfo.IsNonDisplay; // field is non display. // if ((attrByte & 0x07) == 0x07) // { // fldItem.IsNonDisplay = true; // } itemList.Add(fldItem); curRowCol = curRowCol.Advance(1); // advance because of attrbyte. } else if (order.OrderCode == WtdOrder.SetBufferAddress) { var sba = order as SetBufferAddressOrder; curRowCol = sba.GetRowCol(ScreenDim).ToZeroRowCol(); } else if (order.OrderCode == WtdOrder.InsertCursor) { var ico = order as InsertCursorOrder; caret = ico.RowCol; } else if (order.OrderCode == WtdOrder.RepeatToAddress) { var rao = order as RepeatToAddressOrder; var s1 = rao.RepeatShowText((ZeroRowCol)curRowCol); var litItem = new ShowLiteralItem((ZeroRowCol)curRowCol, s1); litItem.rao_RepeatTextByte = rao.RepeatTextByte; litItem.rao_ToRowCol = rao.RowCol; itemList.Add(litItem); curRowCol = curRowCol.Advance(s1.Length); } else if (order.OrderCode == WtdOrder.EraseToAddress) { var eao = order as EraseToAddressOrder; var lx = eao.EraseLength((ZeroRowCol)curRowCol); var s1 = (" ").Repeat(lx); var litItem = new ShowLiteralItem((ZeroRowCol)curRowCol, s1); litItem.rao_RepeatTextByte = 0x00; litItem.rao_ToRowCol = eao.RowCol; itemList.Add(litItem); curRowCol = curRowCol.Advance(s1.Length); } } return(new Tuple <ShowItemList, OneRowCol>(itemList, caret)); }
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(); } }
public static Tuple <int, int, List <ShowItemBase>, TelnetLogList> GetAndProcessStream( TcpClient Client, NetworkStream NetStream, NetworkStreamBackedInputByteArray InputArray, NegotiateSettings NegotiateSettings, bool ForceRead = false) { int sendStmtCx = 0; int getStmtCx = 0; var logList = new TelnetLogList(); var showItemList = new ShowItemList(); bool exitLoop = false; while (exitLoop == false) { // read available bytes from input stream. if (InputArray.IsEof()) { var log = InputArray.ReadFromNetworkStream(5, 5, ForceRead); logList.AddItems(log); } // no input data to process. if (InputArray.IsEof()) { break; } DataStreamHeader currentDataStreamHeader = null; while (true) { if (InputArray.IsEof() == true) { break; } // process the input as 5250 data stream commands. if (currentDataStreamHeader != null) { var rv = ParseAndProcessWorkstationCommand(InputArray, currentDataStreamHeader); var workstationCommand = rv.Item1; showItemList = rv.Item2; currentDataStreamHeader = rv.Item3; logList.AddItems(rv.Item4); continue; } // peek and process input bytes as a telnet stmt. ( starts with IAC ) var telCmd = InputArray.NextTelnetCommand(); if (telCmd != null) { getStmtCx += 1; var rv = TelnetConnection.ProcessTelnetCommand(telCmd, NegotiateSettings); var cx = rv.Item1; var writeBytes = rv.Item2; logList.AddItems(rv.Item3); sendStmtCx += cx; WriteToHost(logList, writeBytes, NetStream); continue; } var dsh = new DataStreamHeader(InputArray); if ((dsh != null) && (dsh.Errmsg == null)) { logList.AddItem(Direction.Read, dsh.ToString()); currentDataStreamHeader = dsh; continue; } exitLoop = true; break; } } return(new Tuple <int, int, List <ShowItemBase>, TelnetLogList>( getStmtCx, sendStmtCx, showItemList, logList)); }
/// <summary> /// create visual items from the show items and place those visual items on the /// canvase. /// </summary> /// <param name="ShowItemList"></param> private OneRowCol PaintScreen_Actual( WriteToDisplayCommand WTD_command, TelnetLogList LogList = null) { IRowCol curRowCol = new ZeroRowCol(0, 0); OneRowCol caret = null; foreach (var order in WTD_command.OrderList) { if (LogList != null) { LogList.AddItem(Direction.Read, "PaintScreen. " + order.ToString()); } if (order is TextDataOrder) { var tdo = order as TextDataOrder; if (tdo.IsEmpty() == false) { PaintScreen_ApplyTextDataOrder(tdo, curRowCol); } curRowCol = tdo.Advance(curRowCol); } else if (order is SetBufferAddressOrder) { var sba = order as SetBufferAddressOrder; curRowCol = sba.GetRowCol(this.ScreenDim).ToZeroRowCol(); } else if (order.OrderCode == WtdOrder.InsertCursor) { var ico = order as InsertCursorOrder; caret = ico.RowCol; } else if (order is StartFieldOrder) { var sfo = order as StartFieldOrder; { var showText = new String(' ', sfo.LL_Length); var vtb = new VisualTextBlock( showText, (ZeroRowCol)curRowCol, sfo.AttrByte, this.CanvasDefn.CharBoxDim, this.CanvasDefn.KernDim, this.CanvasDefn.FontDefn); var iMore = vtb as IVisualItemMore; var node = iMore.InsertIntoVisualItemsList(this.VisualItems); iMore.AddToCanvas(this); vtb.SetupFieldItem( sfo, this.CanvasDefn.CharBoxDim, this.CanvasDefn.KernDim); } curRowCol = curRowCol.Advance(1); } else if (order is RepeatToAddressOrder) { var rao = order as RepeatToAddressOrder; this.VisualItems.ApplyRepeatToAddressOrder(curRowCol, rao, this); var lx = rao.RepeatLength((ZeroRowCol)curRowCol); curRowCol = curRowCol.Advance(lx); } else if (order is EraseToAddressOrder) { var eao = order as EraseToAddressOrder; this.VisualItems.ApplyEraseToAddressOrder(curRowCol, eao, this); var lx = eao.EraseLength((ZeroRowCol)curRowCol); curRowCol = curRowCol.Advance(lx); } } return(caret); }