private void TelnetDisplayStartup(
            ServerConnectPack ConnectPack, NegotiateSettings NegotiateSettings,
            ConcurrentMessageQueue TelnetQueue,
            FromThread FromThread, ToThread ToThread,
            Window ClientWindow, Action <bool, TypeTelnetDevice?> TelnetStartupComplete)
        {
            // initial telnet back and forth negotiation with server.
            var rv = TelnetConnection.TelnetConnectAndNegotiate(
                ConnectPack.HostName, NegotiateSettings,
                TelnetQueue, ToThread);
            var sessionSettings = rv.Item1;

            ConnectPack.Settings = sessionSettings;

            // read the dataStreamHeader from the Telnet thread.
            // this message contains the startup up code ( I902 ), system name and
            // printer name.  The next message from the server will be sent when there
            // is a spooled file ready to print.
            var attrMsg = TelnetQueue.WaitAndDequeue() as TelnetDeviceAttrMessage;

            if (attrMsg != null)
            {
                // signal startup is complete to the telnet window on the UI thread.
                var bi = ClientWindow.Dispatcher.BeginInvoke(
                    DispatcherPriority.Input, new ThreadStart(
                        () =>
                {
                    TelnetStartupComplete(true, attrMsg.TypeDevice);
                }));
            }
        }
Esempio n. 2
0
 public TelnetStartupMessage(
     ConcurrentMessageQueue TelnetQueue,
     ServerConnectPack ServerConnectPack, NegotiateSettings NegotiateSettings,
     Window ClientWindow, Action <bool, TypeTelnetDevice?> TelnetStartupComplete,
     TypeTelnetDevice TypeTelnetDevice)
 {
     this.TelnetQueue           = TelnetQueue;
     this.ServerConnectPack     = ServerConnectPack;
     this.NegotiateSettings     = NegotiateSettings;
     this.ClientWindow          = ClientWindow;
     this.TypeTelnetDevice      = TypeTelnetDevice;
     this.TelnetStartupComplete = TelnetStartupComplete;
 }
        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));
        }