public void ApplyTextDataOrder(IRowCol CurRowCol, TextDataOrder TextData) { int lx = TextData.ItemLength(); var itemRange = new RowColRange(CurRowCol, lx); var buf = this.GetContentBytes(CurRowCol, lx); // get the fields located within the bounds of the StartField. All of these // fields are removed from the ScreenTable. if (buf.AllMatch(0x00) == false) { foreach (var contentField in this.ContentFields(itemRange)) { var ix = contentField.RowCol.DistanceInclusive(CurRowCol) - 1; var textByte = TextData.RawBytes[ix]; if (textByte.IsAttrByte( ) == false) { this.FieldDict.Remove(contentField.RowCol); SetContentBytes(contentField.RowCol, 0x00); } } } // apply the textbytes ( including leading and trailing attrbyte ) directly // to the content array. { // store the attrByte at ItemRowCol location of the field. SetContentBytes(CurRowCol, TextData.RawBytes); } }
public WriteToDisplayCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WTD) { this.OrderList = new List <WtdOrderBase>(); if (InputArray.RemainingLength < 4) { this.Errmsg = "Byte stream too short. Missing control chars."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.ControlChars = buf.SubArray(2, 2); InputArray.AdvanceIndex(4); this.BytesLength = 4; // gather WTD orders and display characters. while (true) { WtdOrderBase orderBase = null; if (InputArray.RemainingLength == 0) { break; } orderBase = WtdOrderBase.Factory(InputArray); // not an explicit WTD order. Check that is a text data order. if (orderBase == null) { var b1 = InputArray.PeekByte(0); if (Common5250.IsTextDataChar(b1) == true) { orderBase = new TextDataOrder(InputArray); } } // current input stream bytes are not WTD order. End of WTD command. if (orderBase == null) { break; } // got an order but some sort of form error. if (orderBase.Errmsg != null) { throw new Exception("invalid WTD order"); } // Append to list of orders of the WTD command. this.OrderList.Add(orderBase); this.BytesLength += orderBase.GetDataStreamLength(); } } }
public static WriteToDisplayCommand Factory(InputByteArray InputArray) { WriteToDisplayCommand wtdCmd = null; if (InputArray.RemainingLength >= 4) { var buf = InputArray.PeekBytes(4); if ((buf[0] == 0x04) && (buf[1] == 0x11)) { byte[] controlChars = new byte[2]; Array.Copy(buf, 3, controlChars, 0, 2); wtdCmd = new WriteToDisplayCommand(InputArray, controlChars); InputArray.AdvanceIndex(4); // gather WTD orders and display characters. while (true) { if (InputArray.RemainingLength == 0) { break; } var b1 = InputArray.PeekByte(0); var wtdOrder = b1.ToWtdOrder(); if (wtdOrder != null) { } else if (TextDataOrder.IsTextDataChar(b1)) { var tdOrder = TextDataOrder.Factory(InputArray); wtdCmd.OrderList.Add(tdOrder); } else { break; } } } } return(wtdCmd); }
/// <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> /// <param name="VisualItems"></param> /// <returns></returns> public byte[] BuildOrderStream(CanvasPositionCursor Caret) { ByteArrayBuilder 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 zeroRowCol = Caret.RowCol as ZeroRowCol; var rowCol = zeroRowCol.ToOneRowCol() as OneRowCol; 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; IVisualItem iVisual = null; var cursor = this.FirstVisualItem(); while (cursor != null) { var pvVisualItem = iVisual; iVisual = cursor.GetVisualItem(); if (iVisual is VisualSpanner) { } else { { var buf = SetBufferAddressOrder.Build( iVisual.ItemRowCol.ToOneRowCol() as OneRowCol); ba.Append(buf); } var visualItem = iVisual as VisualItem; if (iVisual.IsField == true) { var vtb = iVisual as VisualTextBlock; var ffw = vtb.FFW_Bytes; byte attrByte = iVisual.AttrByte.Value; int lgth = iVisual.ShowText.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 = iVisual.ShowText; if (iVisual.IsField == true) { buf = TextDataOrder.Build(s1, null, iVisual.TailAttrByte); } else if (visualItem.CreateFromItem != null) { var litItem = visualItem.CreateFromItem as ShowLiteralItem; if (litItem.rao_RepeatTextByte != null) { var toRowCol = (iVisual.ItemEndRowCol() as ZeroRowCol).ToOneRowCol(); buf = RepeatToAddressOrder.Build( litItem.rao_RepeatTextByte.Value, toRowCol as OneRowCol); } else { var attrByte = litItem.AttrByte; if (s1.Length < litItem.tdo_Length) { s1 = s1.PadRight(litItem.tdo_Length); } buf = TextDataOrder.Build(s1, attrByte, iVisual.TailAttrByte); } } else { buf = TextDataOrder.Build(s1, iVisual.AttrByte, iVisual.TailAttrByte); } ba.Append(buf); } } cursor = cursor.NextItem(true); } return(ba.ToByteArray());; }
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> /// 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());; }
private void PaintScreen_ApplyTextDataOrder(TextDataOrder tdo, IRowCol curRowCol) { var showText = tdo.ShowText; var showRowCol = tdo.ShowRowCol(curRowCol); var itemEndRowCol = tdo.ItemEndRowCol(showRowCol); var itemRange = new RowColRange(curRowCol, itemEndRowCol); IVisualItem ivi = null; // range if visual items which overlap this tdo. var overlapItems = VisualItems.GetOverlapItems(itemRange); if (overlapItems != null) { foreach (var cursor in overlapItems) { var item = cursor.GetVisualItem(); var itemRowCol = item.ItemRowCol; var tailAttrByte = tdo.TailAttrByte; if ((tdo.TailAttrByte != null) && (item.AttrByte != null) && (tdo.ItemEndRowCol(curRowCol).CompareTo(item.ItemRowCol) == 0)) { int xx = 4; } } } else { } if (itemEndRowCol != null) { ivi = VisualItems.FindFieldItem(curRowCol, showRowCol, itemEndRowCol); } if (ivi != null) { // replace textbock segment with the spanner. if (ivi is VisualTextBlockSegment) { var seg = ivi as VisualTextBlockSegment; ivi = seg.Parent; } var vim = ivi as IVisualItemMore; // pos within the canvas item at which to place literal text. int bx = showRowCol.ColNum - ivi.ShowRowCol().ColNum; // apply the literal text. vim.ApplyText(showText, bx); if (tdo.TailAttrByte != null) { ivi.TailAttrByte = tdo.TailAttrByte; } } else if (itemEndRowCol != null) { var visualItem = VisualItemFactory( tdo.ShowText, (ZeroRowCol)curRowCol, tdo.AttrByte, tdo.TailAttrByte); visualItem.FromOrder = tdo; var iMore = visualItem as IVisualItemMore; var node = iMore.InsertIntoVisualItemsList(this.VisualItems); iMore.AddToCanvas(this); } }