Ejemplo n.º 1
0
        public static CanvasPositionCursor PrevInputItem(
            this CanvasPositionCursor Cursor, ScreenVisualItems VisualItems,
            VisualFeature?Feature = null, bool Reuse = true)
        {
            VisualItemCursor vc = null;
            var cursor          = Cursor;

            if (cursor.IsOutsideVisualItem() == true)
            {
                vc = VisualItems.FindPrevInputItem(cursor.RowCol, Feature);
            }
            else
            {
                vc = Cursor.ItemCursor.PrevInputItem(Feature);
            }

            if (vc == null)
            {
                cursor = null;
            }
            else if (Reuse == true)
            {
                cursor.ItemCursor = vc;
                cursor.Position   = 1;
            }
            else
            {
                cursor = new CanvasPositionCursor(vc, 1);
            }

            return(cursor);
        }
Ejemplo n.º 2
0
        public LinkedListNode <IVisualItem> InsertIntoVisualItemsList(
            ScreenVisualItems VisualItems)
        {
            // insert this spanner object.
            var node = VisualItems.InsertIntoVisualItemsList(this);

            return(node);
        }
Ejemplo n.º 3
0
        public static CanvasPositionCursor PrevInputItemCircular(
            this CanvasPositionCursor Cursor, ScreenVisualItems VisualItems,
            VisualFeature?Feature = null, bool Reuse = true)
        {
            var posCursor = Cursor.PrevInputItem(VisualItems, Feature, Reuse);

            if (posCursor == null)
            {
                var ic = VisualItems.InputItemList().Last();
                if (ic != null)
                {
                    posCursor = new CanvasPositionCursor(ic);
                }
            }

            return(posCursor);
        }
        /// <summary>
        /// no longer used. called WorkstationCommandListExt.ProcessAndPaint, which
        /// itself is not used.
        /// </summary>
        /// <param name="VisualItems"></param>
        /// <param name="Caret"></param>
        /// <returns></returns>
        public static byte[] BuildSaveScreenResponse(
            ScreenVisualItems VisualItems, CanvasPositionCursor Caret)
        {
            var ra = new ByteArrayBuilder();

            // data stream header.
            {
                var buf = DataStreamHeader.Build(50, TerminalOpcode.SaveScreen, 0, 0);
                ra.Append(buf);
            }

            // restore screen workstation command.
            {
                var cmd = new RestoreScreenCommand();
                ra.Append(cmd.ToBytes());
            }

            // clear unit command.
            {
                var cmd = new ClearUnitCommand();
                ra.Append(cmd.ToBytes());
            }

            // WTD command.
            {
                var ordersByteStream = VisualItems.BuildOrderStream(Caret);
                var buf = WriteToDisplayCommand.Build(0x00, 0x18, ordersByteStream);
                ra.Append(buf);
            }

            // update length of response data stream.
            {
                var wk = new ByteArrayBuilder();
                wk.AppendBigEndianShort((short)ra.Length);
                ra.CopyToBuffer(wk.ToByteArray(), 0);
            }

            // IAC EOR
            {
                ra.Append(EOR_Command.Build());
            }

            return(ra.ToByteArray());
        }
Ejemplo n.º 5
0
        public CanvasPositionCursor(ScreenVisualItems VisualItems, ZeroRowCol RowCol)
        {
            var itemCursor = VisualItems.FindVisualItem(RowCol);

            if (itemCursor == null)
            {
                this.ItemCursor    = null;
                this.Position      = 0;
                this.OutsideRowCol = RowCol;
            }
            else
            {
                var item  = itemCursor.GetVisualItem();
                var iItem = item as IVisualItem;
                int pos   = RowCol.ColNum - iItem.ShowRowCol().ColNum + 1;
                this.ItemCursor = itemCursor;
                this.Position   = pos;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// advance the cursor one column to the right. The advanced to location depends
        /// if the cursor is located in an input field, if the cursor is at the last
        /// column of the input field and if it is, whether the code should advance to the
        /// next input field or to the screen location to the right which is outside the
        /// input field.
        /// </summary>
        /// <param name="HowAdvance"></param>
        /// <param name="Reuse"></param>
        /// <returns></returns>
        public CanvasPositionCursor AdvanceRight(ScreenVisualItems VisualItems,
                                                 HowAdvance HowAdvance = HowAdvance.NextEntryField,
                                                 bool Reuse            = true)
        {
            var cursor = this;

            if (cursor.IsOutsideVisualItem() == true)
            {
                var rowCol = cursor.RowCol.AdvanceRight();
                cursor = new CanvasPositionCursor(VisualItems, rowCol as ZeroRowCol);
            }

            else
            {
                var vi  = cursor.GetVisualItem();
                var pos = cursor.Position;

                // cursor located in entry field. and cursor is at the end of the input field.
                if (((vi as VisualItem)?.IsInputItem == true) &&
                    ((vi as VisualItem).IsLastColumn(this.Position)))
                {
                    if (HowAdvance == HowAdvance.NextEntryField)
                    {
                        cursor = this.NextInputItemCircular(VisualItems, null, Reuse);
                    }
                }

                else
                {
                    if (Reuse == true)
                    {
                        cursor.Position += 1;
                    }
                    else
                    {
                        cursor = new CanvasPositionCursor(this.ItemCursor, this.Position + 1);
                    }
                }
            }

            return(cursor);
        }
Ejemplo n.º 7
0
        public CanvasPositionCursor AdvanceLeft(ScreenVisualItems VisualItems,
                                                HowAdvance HowAdvance = HowAdvance.NextEntryField,
                                                bool Reuse            = true)
        {
            var cursor = this;

            if (cursor.IsOutsideVisualItem() == true)
            {
                var rowCol = cursor.RowCol.AdvanceLeft();
                cursor = new CanvasPositionCursor(VisualItems, rowCol as ZeroRowCol);
            }

            else
            {
                var vi  = cursor.GetVisualItem();
                var pos = cursor.Position;

                // cursor located in entry field. and cursor is at the end of the input field.
                if (((vi as VisualItem)?.IsInputItem == true) && (this.Position == 1) &&
                    (HowAdvance == HowAdvance.NextEntryField))
                {
                    cursor = this.PrevInputItem(VisualItems, null, Reuse);
                    // need to set cursor position to the last position in the visual item.
                }

                else
                {
                    if (Reuse == true)
                    {
                        cursor.Position -= 1;
                    }
                    else
                    {
                        cursor = new CanvasPositionCursor(this.ItemCursor, this.Position - 1);
                    }
                }
            }
            return(cursor);
        }
Ejemplo n.º 8
0
        public static IEnumerable <string> PrintVisualItems(ScreenVisualItems VisualItems)
        {
            var lines = new List <string>();

            {
                var titleText = "----------- Canvas Visual Item Listing -----------";
                lines.Add(titleText.PadCenter(80));
                var chd = wtdReport.PrintColumnHeading();
                lines.AddRange(chd);
            }

            foreach (var cursor in VisualItems.CanvasItemList( ))
            {
                var iVisual    = cursor.GetVisualItem();
                var visualItem = iVisual as VisualItem;

                var printItem = new PrintItem(iVisual.ItemRowCol.ToOneRowCol() as OneRowCol);
                if (visualItem.IsInputItem == false)
                {
                    printItem.ItemType = ReportItemType.Literal;
                    printItem.ItemText = iVisual.ShowText;
                    printItem.ItemLgth = iVisual.ShowText.Length;
                }
                else
                {
                    printItem.ItemType = ReportItemType.Field;
                    printItem.ItemText = iVisual.ShowText;
                    printItem.ItemLgth = iVisual.ShowText.Length;
                }

                if (printItem.ItemLgth > 0)
                {
                    printItem = wtdReport.PrintAndAdvance(lines, printItem);
                }
            }

            return(lines);
        }
Ejemplo n.º 9
0
        public static CanvasPositionCursor NextInputItemNextLine(
            this CanvasPositionCursor PosCursor, ScreenVisualItems VisualItems)
        {
            var posCursor = PosCursor;

            // save the row/col of the current
            var startRowCol = PosCursor.RowCol;

            while (true)
            {
                posCursor = posCursor.NextInputItemCircular(VisualItems);
                if (startRowCol.RowNum != posCursor.RowCol.RowNum)
                {
                    break;
                }
                if (posCursor.RowCol.CompareTo(startRowCol) != 1)
                {
                    break;
                }
            }

            return(posCursor);
        }
Ejemplo n.º 10
0
        public CanvasPositionCursor AdvanceUp(ScreenVisualItems VisualItems)
        {
            var rowCol = this.RowCol.AdvanceUp();

            return(new CanvasPositionCursor(VisualItems, rowCol as ZeroRowCol));
        }
        ProcessWorkstationDataStream(
            this ServerConnectPack ConnectPack, 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 (ConnectPack.ReadBlocks.IsEmpty == true)
                {
                    if (howRead != null)
                    {
                        break;
                    }
                }

                var item = ConnectPack.ReadBlocks.WaitAndDequeue();

                if (item is DataStreamHeader)
                {
                    dsh = item as DataStreamHeader;
                    continue;
                }

                gotEOR = true;
                if (item is WorkstationCommandList)
                {
                    workstationCmdList = item as WorkstationCommandList;

                    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, ConnectPack.TcpClient.GetStream());
                                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, ConnectPack.TcpClient.GetStream());
                                    gotEOR = false;
                                }
                            }
                        }
                    }
                }
            }

            return(new Tuple <HowReadScreen?, List <WriteToDisplayCommand>,
                              TelnetLogList, WorkstationCommandList, DataStreamHeader, bool>(
                       howRead, wtdCmdList, logList, returnCmdList, dsh, gotEOR));
        }
        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));
        }