Пример #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);
        }