Exemplo n.º 1
0
        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>
        /// <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());;
        }
Exemplo n.º 3
0
        /// <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());;
        }