public void PositionCaret(OneRowCol CaretRowCol) { // position the caret cursor. VisualItemCursor ic = null; if (CaretRowCol != null) { var rowCol = CaretRowCol.ToZeroRowCol(); this.CaretCursor = VisualItems.FindVisualItemCanvas(rowCol); } else { // find the first field on the screen. ic = VisualItems.InputItemList().FirstOrDefault(); this.CaretCursor = new CanvasPositionCursor(ic); } // by default. place the caret at first input field on screen. if (this.CaretCursor.RowCol == null) { var rowCol = new ZeroRowCol(0, 0); this.CaretCursor = VisualItems.FindVisualItemCanvas(rowCol); } // position the caret cursor at the visual item. this.CanvasCaret.StartBlink(this.CaretCursor, true); }
public PrintItem(OneRowCol RowCol) { this.RowCol = RowCol; this.ItemType = null; this.ItemLgth = 0; this.AttrByte = null; this.ItemText = null; this.ffw = null; }
/// <summary> /// build a byte array containing a SBA order. /// </summary> /// <param name="RowNum"></param> /// <param name="ColNum"></param> /// <returns></returns> public static byte[] Build(OneRowCol RowCol) { var ba = new ByteArrayBuilder(); ba.Append((byte)WtdOrder.SetBufferAddress); ba.Append(RowCol.RowNum); ba.Append(RowCol.ColNum); return(ba.ToByteArray()); }
public static byte[] Build(byte RepeatTextByte, OneRowCol ToRowCol) { var ba = new byte[4]; ba[0] = (byte)WtdOrder.RepeatToAddress; ba[1] = RepeatTextByte; ba[2] = (byte)ToRowCol.RowNum; ba[3] = (byte)ToRowCol.ColNum; return(ba); }
public static byte[] Build(OneRowCol RowCol, AidKey AidKey) { var ba = new ByteArrayBuilder(); ba.Append((byte)RowCol.RowNum); ba.Append((byte)RowCol.ColNum); ba.Append((byte)AidKey); return(ba.ToByteArray()); }
/// <summary> /// build a byte array containing an InsertCursor order. /// </summary> /// <param name="RowNum"></param> /// <param name="ColNum"></param> /// <returns></returns> public static byte[] Build(OneRowCol RowCol) { var ba = new ByteArrayBuilder(); ba.Append((byte)WtdOrder.InsertCursor); ba.Append(RowCol.RowNum); ba.Append(RowCol.ColNum); return(ba.ToByteArray()); }
public void PaintScreen( List <ShowItemBase> ShowItemList, OneRowCol CaretRowCol, bool Erase = true) { if (Erase == true) { this.EraseScreen(); } this.ShowItemList = ShowItemList; PaintScreen_Actual(ShowItemList); }
public static Tuple <bool, OneRowCol> PaintCanvas( this WriteToDisplayCommand WTD_command, ItemCanvas ItemCanvas, bool EraseScreen = true, TelnetLogList LogList = null ) { OneRowCol caret = null; bool drawDone = false; caret = ItemCanvas.PaintScreen(WTD_command, EraseScreen, LogList); drawDone = true; return(new Tuple <bool, OneRowCol>(drawDone, caret)); }
/// <summary> /// build a byte array containing an EraseToAddress order. /// </summary> /// <param name="RowNum"></param> /// <param name="ColNum"></param> /// <returns></returns> public static byte[] Build(OneRowCol RowCol, byte[] AttrTypesArray) { var ba = new ByteArrayBuilder(); ba.Append((byte)WtdOrder.EraseToAddress); ba.Append(RowCol.RowNum); ba.Append(RowCol.ColNum); if ((AttrTypesArray.Length == 1) && (AttrTypesArray[0] == 0xff)) { ba.Append(new byte[] { 0xff, 0xff }); } else { ba.Append((byte)AttrTypesArray.Length); ba.Append(AttrTypesArray); } return(ba.ToByteArray()); }
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); }
/// <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)); }
/// <summary> /// build a byte stream containing the WTD workstation command orders from all /// of the visual items on the canvas. The visual item list is the equivalent of /// the 5250 format table. /// </summary> /// <returns></returns> public byte[] BuildOrderStream() { var ba = new ByteArrayBuilder(); // start header order. { byte[] cmdKeySwitches = new byte[] { 0x00, 0x00, 0x00 }; var buf = StartHeaderOrder.Build(0x00, 0x00, 24, cmdKeySwitches); ba.Append(buf); } // insert cursor order. { var rowCol = this.CaretRowCol; if (rowCol == null) { rowCol = new OneRowCol(1, 1, this); } var buf = InsertCursorOrder.Build(rowCol); ba.Append(buf); } // build sets of SBA, StartField and TextData orders for each visual item. The // visual item represents something on the screen. Whether output literal or // and input field. // VisualItem visualItem = null; foreach (var dictItem in this.FieldDict) { var contentItem = dictItem.Value; { var buf = SetBufferAddressOrder.Build( contentItem.RowCol.ToOneRowCol() as OneRowCol); ba.Append(buf); } if (contentItem is ContentField) { var contentField = contentItem as ContentField; var ffw = contentField.FFW_Bytes; byte attrByte = contentField.GetAttrByte(this).Value; int lgth = contentField.LL_Length; var buf = StartFieldOrder.Build(ffw[0], ffw[1], attrByte, lgth); ba.Append(buf); } // create a text data order from either the text of the literal item. Or the // text value of the entry field. { byte[] buf = null; var s1 = contentItem.GetShowText(this); if (contentItem is ContentField) { buf = TextDataOrder.Build(s1, null, null); } else { buf = TextDataOrder.Build(s1, contentItem.GetAttrByte(this), null); } ba.Append(buf); } } return(ba.ToByteArray());; }
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); }
private byte[] BuildResponseByteStream( ScreenContent ScreenContent, AidKey AidKey, OneRowCol CaretRowCol, HowReadScreen?HowRead = null) { var ba = new ByteArrayBuilder(); // what to read from the screen. HowReadScreen howRead = HowReadScreen.ReadAllInput; if (HowRead != null) { howRead = HowRead.Value; } { var buf = DataStreamHeader.Build(99, TerminalOpcode.PutGet); ba.Append(buf); } // location of caret on the canvas. { var rowCol = CaretRowCol.ToParentRelative(ScreenContent); var buf = ResponseHeader.Build(rowCol as OneRowCol, AidKey); ba.Append(buf); } foreach (var dictItem in ScreenContent.FieldDict) { ContentField responseField = null; var contentItem = dictItem.Value; // process only ContentField. if (contentItem is ContentField) { var contentField = contentItem as ContentField; responseField = contentField; } // only process the first of a continued entry field. if ((responseField != null) && (responseField is ContinuedContentField)) { var contContentField = responseField as ContinuedContentField; if (contContentField.ContinuedFieldSegmentCode != ContinuedFieldSegmentCode.First) { responseField = null; } } if ((howRead == HowReadScreen.ReadMdt) && (responseField != null) && (responseField.GetModifiedFlag(ScreenContent) == false)) { responseField = null; } if (responseField != null) { IRowCol rowCol = responseField.RowCol.ToOneRowCol().AdvanceRight(); { rowCol = rowCol.ToParentRelative(ScreenContent); var buf = SetBufferAddressOrder.Build(rowCol as OneRowCol); ba.Append(buf); } { var buf = TextDataOrder.Build(responseField.GetFieldShowText(ScreenContent)); ba.Append(buf); } } } // update length of response data stream. var ra = ba.ToByteArray(); { var wk = new ByteArrayBuilder(); wk.AppendBigEndianShort((short)ra.Length); Array.Copy(wk.ToByteArray(), ra, 2); } return(ra); }
/// <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); }
private void MenuItem_Click(object sender, RoutedEventArgs e) { string itemText = null; string tagText = null; var senderItem = sender as MenuItem; if (sender is MenuItem) { itemText = (sender as MenuItem).Header as string; } tagText = senderItem.Tag as string; if (itemText == "Telnet") { var devName = "STEVE26"; var termType = "IBM-3477-FC"; // IBM-3477-FC, IBM-3179-2 TelnetInitialConnect( this.Model.SystemName, this.Model.AutoConnect, this.Model.DeviceName, this.Model.TerminalType); } else if (itemText == "Printer") { TelnetPrinterConnect(this.Model.SystemName); } else if (itemText == "Exit") { this.canAutoClose = true; this.Close(); } else if (itemText == "Test") { var s2 = this.Model.ScreenDefnPath; Debug.Print("ScreenDefnPath:" + s2); } else if (itemText == "Read xml") { string xmlPath = "c:\\skydrive\\c#\\TextCanvasLib\\xmlfile1.xml"; var items = ScreenDocReader.ReadDoc(xmlPath); OneRowCol caret = null; this.Model.TelnetCanvas.PaintScreen(items, caret); } else if (itemText == "Print log") { LinePrinter.PrintLines(this.Model.RunLog); } else if (itemText == "Clear log") { MainWindow.LogFile.ClearFile(); this.Model.RunLog.Clear(); this.PaintThread.PostInputMessage(ThreadMessageCode.ClearLog); this.MasterThread.PostInputMessage(ThreadMessageCode.ClearLog); this.ToThread.PostInputMessage(ThreadMessageCode.ClearLog); this.FromThread.PostInputMessage(ThreadMessageCode.ClearLog); } else if (itemText == "view special") { var specialPath = "c:\\downloads\\specialLog.txt"; string exePath = Environment.ExpandEnvironmentVariables(@"%windir%\system32\notepad.exe"); Process.Start(exePath, specialPath); } else if (itemText == "Report canvas items") { MasterThread.PostInputMessage(ThreadMessageCode.ReportVisualItems); var visualItems = this.Model.TelnetCanvas.VisualItems; var report = wtdReportExt.PrintVisualItems(visualItems); this.Model.RunLog.AddRange(report); } else if (itemText == "Send data") { var dataBytes = new byte[] { 0x00, 0x0a, 0x12, 0xa0, 0x01, 0x02, 0x04, 0x00, 0x00, 0x01, 0xff, 0xef }; dataBytes = new byte[] { 0x00, 0x0A, 0x12, 0xA0, 0x01, 0x02, 0x04, 0x00, 0x00, 0x01, 0xFF, 0xEF }; var dataMessage = new SendDataMessage(dataBytes); this.ToThread.PostInputMessage(dataMessage); } // capture the currently matched screen. else if (tagText == "Capture") { if (this.Model.MatchScreenDefn == null) { MessageBox.Show("no matched screen to capture"); } else { // send message to master thread to get the current screen content. var msg = new ExchangeMessage(ThreadMessageCode.GetScreenContent); this.MasterThread.PostInputMessage(msg); msg.WaitReplyEvent(); var content = msg.ReplyMessage as ScreenContent; // send message to capture thread telling it to capture the current // screen. var captureMessage = new CaptureContentMessage( this.Model.CaptureFolderPath, this.Model.CaptureAuto, this.Model.MatchScreenDefn, content); this.CaptureThread.PostInputMessage(captureMessage); } } else if (tagText == "CaptureViewer") { var window = new CaptureViewerWindow(); window.CaptureFolderPath = this.Model.CaptureFolderPath; window.Show(); } }
public SetBufferAddressOrder(OneRowCol RowCol) : base(WtdOrder.SetBufferAddress) { this.RowAddress = (byte)RowCol.RowNum; this.ColumnAddress = (byte)RowCol.ColNum; }