コード例 #1
0
ファイル: TN3270API.cs プロジェクト: cbuosi/Extrinha
        public bool Connect(IAudit audit, string host, int port, string lu, ConnectionConfig config)
        {
            tn        = new Telnet(this, audit, config);
            tn.UseSSL = mUseSSL;
            tn.trace.optionTraceAnsi        = mDebug;
            tn.trace.optionTraceDS          = mDebug;
            tn.trace.optionTraceDSN         = mDebug;
            tn.trace.optionTraceEvent       = mDebug;
            tn.trace.optionTraceNetworkData = mDebug;
            tn.telnetDataEvent += new TelnetDataDelegate(tn_telnetDataEvent);
            if (lu == null || lu.Length == 0)
            {
                tn.lus = null;
            }
            else
            {
                tn.lus = new System.Collections.ArrayList();
                tn.lus.Add(lu);
            }

            tn.Connect(this, host, port);
            if (!tn.WaitForConnect())
            {
                tn.Disconnect();
                string text = tn.DisconnectReason;
                tn = null;
                throw new TNHostException("connect to " + host + " on port " + port + " failed", text, null);
                //return false;
            }
            tn.trace.WriteLine("--connected");
            return(true);
        }
コード例 #2
0
 // Called by a UI action of some sort...
 private void Connect(string ipAddress, string portNumber)
 {
     if (this.telnet != null)
     {
         this.telnet = telnetFactory.Create(ipAddress, portNumber);
     }
 }
コード例 #3
0
        /// <summary>
        /// Sends a command string to the mud and does not do typical line processing like splitting commands, identifying
        /// if an alias was run, identifying if a hash command was run or tracking the spam guard.
        /// </summary>
        /// <param name="cmd">The raw unprocessed command to send.</param>
        /// <param name="silent">Whether the commands should be outputted to the game window.</param>
        public async Task SendRaw(string cmd, bool silent)
        {
            if (Telnet == null)
            {
                Conveyor.EchoLog("You are not connected to the game.", LogType.Error);
                return;
            }

            // Show the command in the window that was sent.
            if (!silent)
            {
                EchoText(cmd, AnsiColors.Yellow);
            }

            try
            {
                await Telnet.SendAsync(cmd);
            }
            catch (Exception ex)
            {
                App.Conveyor.EchoError(ex.Message);

                if (this.Telnet == null || !this.Telnet.IsConnected())
                {
                    App.Conveyor.SetText("Disconnected from server.");
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Connects to the mud server.  Requires that the event handlers for required events be passed in here where they will
        /// be wired up.
        /// </summary>
        public async void Connect(EventHandler <string> lineReceived, EventHandler <string> dataReceived, EventHandler connectionClosed)
        {
            try
            {
                if (Telnet != null)
                {
                    Telnet.Dispose();
                    Telnet = null;
                }

                Conveyor.EchoLog($"Connecting: {App.Settings.ProfileSettings.IpAddress}:{App.Settings.ProfileSettings.Port}", LogType.Information);

                var ctc = new CancellationTokenSource();
                Telnet = new TelnetClient(App.Settings.ProfileSettings.IpAddress, App.Settings.ProfileSettings.Port, TimeSpan.FromSeconds(0), ctc.Token);
                Telnet.ConnectionClosed += connectionClosed;
                Telnet.LineReceived     += lineReceived;
                Telnet.DataReceived     += dataReceived;
                await Telnet.Connect();
            }
            catch (Exception ex)
            {
                Telnet.Dispose();
                Conveyor.EchoLog($"Connection Failed: {ex.Message}", LogType.Error);
            }
        }
コード例 #5
0
ファイル: Actions.cs プロジェクト: stevenengland/open3270
        internal Actions(Telnet tn)
        {
            telnet  = tn;
            actions = new[]
            {
                new XtActionRec("printtext", false, telnet.Print.PrintTextAction),
                new XtActionRec("flip", false, telnet.Keyboard.FlipAction),
                new XtActionRec("ascii", false, telnet.Controller.AsciiAction),
                new XtActionRec("dumpxml", false, telnet.Controller.DumpXMLAction),
                new XtActionRec("asciifield", false, telnet.Controller.AsciiFieldAction),
                new XtActionRec("attn", true, telnet.Keyboard.AttnAction),
                new XtActionRec("backspace", false, telnet.Keyboard.BackSpaceAction),
                new XtActionRec("backtab", false, telnet.Keyboard.BackTab_action),
                new XtActionRec("circumnot", false, telnet.Keyboard.CircumNotAction),
                new XtActionRec("clear", true, telnet.Keyboard.ClearAction),
                new XtActionRec("cursorselect", false, telnet.Keyboard.CursorSelectAction),
                new XtActionRec("delete", false, telnet.Keyboard.DeleteAction),
                new XtActionRec("deletefield", false, telnet.Keyboard.DeleteFieldAction),
                new XtActionRec("deleteword", false, telnet.Keyboard.DeleteWordAction),
                new XtActionRec("down", false, telnet.Keyboard.MoveCursorDown),
                new XtActionRec("dup", false, telnet.Keyboard.DupAction),
                new XtActionRec("emulateinput", true, telnet.Keyboard.EmulateInputAction),
                new XtActionRec("enter", true, telnet.Keyboard.EnterAction),
                new XtActionRec("erase", false, telnet.Keyboard.EraseAction),
                new XtActionRec("eraseeof", false, telnet.Keyboard.EraseEndOfFieldAction),
                new XtActionRec("eraseinput", false, telnet.Keyboard.EraseInputAction),
                new XtActionRec("fieldend", false, telnet.Keyboard.FieldEndAction),
                new XtActionRec("fields", false, telnet.Keyboard.FieldsAction),
                new XtActionRec("fieldget", false, telnet.Keyboard.FieldGetAction),
                new XtActionRec("fieldset", false, telnet.Keyboard.FieldSetAction),
                new XtActionRec("fieldmark", false, telnet.Keyboard.FieldMarkAction),
                new XtActionRec("fieldexit", false, telnet.Keyboard.FieldExitAction),
                new XtActionRec("hexString", false, telnet.Keyboard.HexStringAction),
                new XtActionRec("home", false, telnet.Keyboard.HomeAction),
                new XtActionRec("insert", false, telnet.Keyboard.InsertAction),
                new XtActionRec("interrupt", true, telnet.Keyboard.InterruptAction),
                new XtActionRec("key", false, telnet.Keyboard.SendKeyAction),
                new XtActionRec("left", false, telnet.Keyboard.LeftAction),
                new XtActionRec("left2", false, telnet.Keyboard.MoveCursorLeft2Positions),
                new XtActionRec("monocase", false, telnet.Keyboard.MonoCaseAction),
                new XtActionRec("movecursor", false, telnet.Keyboard.MoveCursorAction),
                new XtActionRec("Newline", false, telnet.Keyboard.MoveCursorToNewLine),
                new XtActionRec("NextWord", false, telnet.Keyboard.MoveCursorToNextUnprotectedWord),
                new XtActionRec("PA", true, telnet.Keyboard.PAAction),
                new XtActionRec("PF", true, telnet.Keyboard.PFAction),
                new XtActionRec("PreviousWord", false, telnet.Keyboard.PreviousWordAction),
                new XtActionRec("Reset", true, telnet.Keyboard.ResetAction),
                new XtActionRec("Right", false, telnet.Keyboard.MoveRight),
                new XtActionRec("Right2", false, telnet.Keyboard.MoveCursorRight2Positions),
                new XtActionRec("String", true, telnet.Keyboard.SendStringAction),
                new XtActionRec("SysReq", true, telnet.Keyboard.SystemRequestAction),
                new XtActionRec("Tab", false, telnet.Keyboard.TabForwardAction),
                new XtActionRec("ToggleInsert", false, telnet.Keyboard.ToggleInsertAction),
                new XtActionRec("ToggleReverse", false, telnet.Keyboard.ToggleReverseAction),
                new XtActionRec("Up", false, telnet.Keyboard.MoveCursorUp)
            };

            actionCount = actions.Length;
        }
コード例 #6
0
ファイル: TN3270API.cs プロジェクト: edusis/open3270
 /// <summary>
 /// Disconnects the connected telnet object from the host
 /// </summary>
 public void Disconnect()
 {
     if (tn != null)
     {
         tn.Disconnect();
         tn = null;
     }
 }
コード例 #7
0
ファイル: actions.cs プロジェクト: cbuosi/Extrinha
        internal Actions(Telnet tn)
        {
            telnet   = tn;
            _actions = new XtActionRec[] {
                new XtActionRec("printtext", false, new ActionDelegate(telnet.print.PrintText_action)),
                new XtActionRec("flip", false, new ActionDelegate(telnet.keyboard.Flip_action)),
                new XtActionRec("ascii", false, new ActionDelegate(telnet.tnctlr.Ascii_action)),
                new XtActionRec("dumpxml", false, new ActionDelegate(telnet.tnctlr.DumpXML_action)),
                new XtActionRec("asciifield", false, new ActionDelegate(telnet.tnctlr.AsciiField_action)),
                new XtActionRec("attn", true, new ActionDelegate(telnet.keyboard.Attn_action)),
                new XtActionRec("backspace", false, new ActionDelegate(telnet.keyboard.BackSpace_action)),
                new XtActionRec("backtab", false, new ActionDelegate(telnet.keyboard.BackTab_action)),
                new XtActionRec("circumnot", false, new ActionDelegate(telnet.keyboard.CircumNot_action)),
                new XtActionRec("clear", true, new ActionDelegate(telnet.keyboard.Clear_action)),
                new XtActionRec("cursorselect", false, new ActionDelegate(telnet.keyboard.CursorSelect_action)),
                new XtActionRec("delete", false, new ActionDelegate(telnet.keyboard.Delete_action)),
                new XtActionRec("deletefield", false, new ActionDelegate(telnet.keyboard.DeleteField_action)),
                new XtActionRec("deleteword", false, new ActionDelegate(telnet.keyboard.DeleteWord_action)),
                new XtActionRec("down", false, new ActionDelegate(telnet.keyboard.Down_action)),
                new XtActionRec("dup", false, new ActionDelegate(telnet.keyboard.Dup_action)),
                new XtActionRec("emulateinput", true, new ActionDelegate(telnet.keyboard.EmulateInput_action)),
                new XtActionRec("enter", true, new ActionDelegate(telnet.keyboard.Enter_action)),
                new XtActionRec("erase", false, new ActionDelegate(telnet.keyboard.Erase_action)),
                new XtActionRec("eraseeof", false, new ActionDelegate(telnet.keyboard.EraseEOF_action)),
                new XtActionRec("eraseinput", false, new ActionDelegate(telnet.keyboard.EraseInput_action)),
                new XtActionRec("fieldend", false, new ActionDelegate(telnet.keyboard.FieldEnd_action)),
                new XtActionRec("fields", false, new ActionDelegate(telnet.keyboard.Fields_action)),
                new XtActionRec("fieldget", false, new ActionDelegate(telnet.keyboard.FieldGet_action)),
                new XtActionRec("fieldset", false, new ActionDelegate(telnet.keyboard.FieldSet_action)),
                new XtActionRec("fieldmark", false, new ActionDelegate(telnet.keyboard.FieldMark_action)),
                new XtActionRec("fieldexit", false, new ActionDelegate(telnet.keyboard.FieldExit_action)),
                new XtActionRec("hexString", false, new ActionDelegate(telnet.keyboard.HexString_action)),
                new XtActionRec("home", false, new ActionDelegate(telnet.keyboard.Home_action)),
                new XtActionRec("insert", false, new ActionDelegate(telnet.keyboard.Insert_action)),
                new XtActionRec("interrupt", true, new ActionDelegate(telnet.keyboard.Interrupt_action)),
                new XtActionRec("key", false, new ActionDelegate(telnet.keyboard.Key_action)),
                new XtActionRec("left", false, new ActionDelegate(telnet.keyboard.Left_action)),
                new XtActionRec("left2", false, new ActionDelegate(telnet.keyboard.Left2_action)),
                new XtActionRec("monocase", false, new ActionDelegate(telnet.keyboard.MonoCase_action)),
                new XtActionRec("movecursor", false, new ActionDelegate(telnet.keyboard.MoveCursor_action)),
                new XtActionRec("Newline", false, new ActionDelegate(telnet.keyboard.Newline_action)),
                new XtActionRec("NextWord", false, new ActionDelegate(telnet.keyboard.NextWord_action)),
                new XtActionRec("PA", true, new ActionDelegate(telnet.keyboard.PA_action)),
                new XtActionRec("PF", true, new ActionDelegate(telnet.keyboard.PF_action)),
                new XtActionRec("PreviousWord", false, new ActionDelegate(telnet.keyboard.PreviousWord_action)),
                new XtActionRec("Reset", true, new ActionDelegate(telnet.keyboard.Reset_action)),
                new XtActionRec("Right", false, new ActionDelegate(telnet.keyboard.Right_action)),
                new XtActionRec("Right2", false, new ActionDelegate(telnet.keyboard.Right2_action)),
                new XtActionRec("String", true, new ActionDelegate(telnet.keyboard.String_action)),
                new XtActionRec("SysReq", true, new ActionDelegate(telnet.keyboard.SysReq_action)),
                new XtActionRec("Tab", false, new ActionDelegate(telnet.keyboard.Tab_action)),
                new XtActionRec("ToggleInsert", false, new ActionDelegate(telnet.keyboard.ToggleInsert_action)),
                new XtActionRec("ToggleReverse", false, new ActionDelegate(telnet.keyboard.ToggleReverse_action)),
                new XtActionRec("Up", false, new ActionDelegate(telnet.keyboard.Up_action)),
            };

            actioncount = _actions.Length;
        }
コード例 #8
0
 /// <summary>
 /// Disconnects from the mud server if there is a connection.
 /// </summary>
 public void Disconnect()
 {
     if (Telnet != null)
     {
         Telnet.Dispose();
         Telnet = null;
         return;
     }
 }
コード例 #9
0
 /// <summary>
 ///     Disconnects the connected telnet object from the host
 /// </summary>
 public void Disconnect()
 {
     if (tn != null)
     {
         tn.Disconnect();
         tn.CursorLocationChanged -= tn_CursorLocationChanged;
         tn = null;
     }
 }
コード例 #10
0
        public async Task <string> SendQueryAsync(ChannelSubcommand subCommand)
        {
            var command  = $":CHAN{ChannelNumber}:{subCommand}?";
            var response = await Telnet.SendCommandAsync(command, true);

            // remove line terminator
            var result = response?.TrimEnd();

            return(result);
        }
コード例 #11
0
        private string RemoteChangeDirectory(string path)
        {
            if (path.EndsWith("/"))
            {
                path = path.Substring(0, path.Length - 1);
            }
            var dir = path.Substring(0, path.LastIndexOf('/') + 1);

            Telnet.ChangeFtpDirectory(dir);
            return(path.Replace(dir, string.Empty));
        }
コード例 #12
0
ファイル: Sockets.cs プロジェクト: envis10n/XeonProject
 public async Task SendGMCP(string path, Dictionary <string, object> payload)
 {
     try
     {
         byte[] t = Telnet.CreateGMCPData(path, payload);
         await Stream.WriteAsync(t, 0, t.Length);
     }
     catch (Exception)
     {
         //
     }
 }
コード例 #13
0
ファイル: Sockets.cs プロジェクト: envis10n/XeonProject
 public async Task SendTelnet(byte command, byte option)
 {
     try
     {
         byte[] t = Telnet.CreateTelnetData(command, option);
         await Stream.WriteAsync(t, 0, t.Length);
     }
     catch (Exception)
     {
         //
     }
 }
コード例 #14
0
 private void butClose_Click(object sender, EventArgs e)
 {
     try
     {
         telnet.Close();
         telnet = null;
     }
     catch (NullReferenceException)
     {
         richtxtLogInfo.AppendText("与telnet服务器连接已经关闭,不需要再次关闭!\r\n");
     }
 }
コード例 #15
0
        /// <summary>
        ///     Connects a Telnet object to the host using the parameters provided
        /// </summary>
        /// <param name="audit">IAudit interface to post debug/tracing to</param>
        /// <param name="host">host ip/name</param>
        /// <param name="port">port to use</param>
        /// <param name="lu">lu to use or empty string for host negotiated</param>
        /// <param name="config">configuration parameters</param>
        /// <returns></returns>
        public bool Connect(IAudit audit, string host, int port, string lu, ConnectionConfig config)
        {
            if (tn != null)
            {
                tn.CursorLocationChanged -= tn_CursorLocationChanged;
            }

            tn = new Telnet(this, audit, config);

            tn.Trace.optionTraceAnsi        = debug;
            tn.Trace.optionTraceDS          = debug;
            tn.Trace.optionTraceDSN         = debug;
            tn.Trace.optionTraceEvent       = debug;
            tn.Trace.optionTraceNetworkData = debug;

            tn.telnetDataEventOccurred += tn_DataEventReceived;
            tn.CursorLocationChanged   += tn_CursorLocationChanged;

            if (lu == null || lu.Length == 0)
            {
                tn.Lus = null;
            }
            else
            {
                tn.Lus = new List <string>();
                tn.Lus.Add(lu);
            }

            if (!string.IsNullOrEmpty(sourceIP))
            {
                tn.Connect(this, host, port, sourceIP);
            }
            else
            {
                tn.Connect(this, host, port);
            }

            if (!tn.WaitForConnect())
            {
                tn.Disconnect();
                var text = tn.DisconnectReason;
                tn = null;
                throw new TNHostException("connect to " + host + " on port " + port + " failed", text, null);
            }
            tn.Trace.WriteLine("--connected");

            return(true);
        }
コード例 #16
0
ファイル: TN3270HostParser.cs プロジェクト: zendever/Open3270
        /// <summary>
        ///
        /// </summary>
        public TN3270HostParser()
        {
            Open3270.ConnectionConfig config = new ConnectionConfig();
            config.HostName = "DUMMY_PARSER";
            TN3270API api = new TN3270API();

            telnet = new Telnet(api, this, config);
            telnet.Trace.optionTraceAnsi        = true;
            telnet.Trace.optionTraceDS          = true;
            telnet.Trace.optionTraceDSN         = true;
            telnet.Trace.optionTraceEvent       = true;
            telnet.Trace.optionTraceNetworkData = true;
            telnet.telnetDataEventOccurred     += new TelnetDataDelegate(telnet_telnetDataEvent);

            telnet.Connect(null, null, 0);
        }
コード例 #17
0
 /// <summary>
 /// Creates a clone of this instance
 /// </summary>
 /// <returns>Clone of this instance</returns>
 public object Clone()
 {
     return(new Channels
     {
         HTTP = (Channel)HTTP.Clone(),
         Telnet = (Channel)Telnet.Clone(),
         File = (Channel)File.Clone(),
         USB = (Channel)USB.Clone(),
         AUX = (Channel)AUX.Clone(),
         Daemon = (Channel)Daemon.Clone(),
         CodeQueue = (Channel)CodeQueue.Clone(),
         LCD = (Channel)LCD.Clone(),
         SPI = (Channel)SPI.Clone(),
         AutoPause = (Channel)AutoPause.Clone()
     });
 }
コード例 #18
0
ファイル: ADFSimulator.cs プロジェクト: ProjectAgri20/newrepo
 private static string RunCommand(string hostName, string command)
 {
     try
     {
         using (Telnet telnet = new Telnet(hostName, 1952))
         {
             string prompt = telnet.ReceiveUntilMatch(">", string.Empty);
             telnet.SendLine(command);
             return(telnet.ReceiveUntilMatch(">", prompt));
         }
     }
     catch (SocketException ex)
     {
         throw new DeviceCommunicationException($"ADF simulator at {hostName} did not respond.", ex);
     }
 }
コード例 #19
0
ファイル: TN3270API.cs プロジェクト: edusis/open3270
        public bool Connect(IAudit audit, string host, int port, string lu, ConnectionConfig config)
        {
            tn        = new Telnet(this, audit, config);
            tn.UseSSL = mUseSSL;
            tn.trace.optionTraceAnsi        = mDebug;
            tn.trace.optionTraceDS          = mDebug;
            tn.trace.optionTraceDSN         = mDebug;
            tn.trace.optionTraceEvent       = mDebug;
            tn.trace.optionTraceNetworkData = mDebug;

            tnDataDelegate      = new TelnetDataDelegate(tn_telnetDataEvent); // CFC,Jr 8/2/2008
            tn.telnetDataEvent += tnDataDelegate;

            if (lu == null || lu.Length == 0)
            {
                tn.lus = null;
            }
            else
            {
                tn.lus = new System.Collections.ArrayList();
                tn.lus.Add(lu);
            }

            // Modified CFCJR Feb/29/2008 to allow for local IP endpoint
            if (!string.IsNullOrEmpty(_sourceIP))
            {
                tn.Connect(this, host, port, _sourceIP);
            }
            else
            {
                tn.Connect(this, host, port);
            }

            if (!tn.WaitForConnect())
            {
                tn.Disconnect();
                string text = tn.DisconnectReason;
                tn = null;
                throw new TNHostException("connect to " + host + " on port " + port + " failed", text, null);
                //return false;
            }
            tn.trace.WriteLine("--connected");
            return(true);
        }
コード例 #20
0
        /// <summary>
        /// Connects to the mud server.  Requires that the event handlers for required events be passed in here where they will
        /// be wired up.
        /// </summary>
        public async Task Connect(EventHandler <string> lineReceived, EventHandler <string> dataReceived, EventHandler connectionClosed)
        {
            try
            {
                if (Telnet != null)
                {
                    Telnet.Dispose();
                    Telnet = null;
                }

                // If there was a last host and it was not the current IP to connect to it likely means
                // a new profile was loaded, in that case we're going to reset the ScriptingHost to it's default
                // so things aren't hanging around.
                if (!string.IsNullOrWhiteSpace(_lastHost) && !string.Equals(_lastHost, App.Settings.ProfileSettings.IpAddress))
                {
                    this.ScriptHost?.Reset();
                    Conveyor.EchoLog("Host change detected: Scripting environment reset.", LogType.Information);

                    // Refresh the scripts so they will load when needed.
                    this.ScriptHost?.RefreshScripts();
                }

                // We can set this now, when we come back in if the IP changes they we'll reset above.
                _lastHost = App.Settings.ProfileSettings.IpAddress;

                Conveyor.EchoLog($"Connecting: {App.Settings.ProfileSettings.IpAddress}:{App.Settings.ProfileSettings.Port}", LogType.Information);

                var ctc = new CancellationTokenSource();
                this.Telnet = new TelnetClient(App.Settings.ProfileSettings.IpAddress, App.Settings.ProfileSettings.Port, TimeSpan.FromSeconds(0), ctc.Token);
                this.Telnet.ConnectionClosed += connectionClosed;
                this.Telnet.LineReceived     += lineReceived;
                this.Telnet.DataReceived     += dataReceived;
                await this.Telnet.ConnectAsync();
            }
            catch (Exception ex)
            {
                Telnet?.Dispose();
                Conveyor.EchoLog($"Connection Failed: {ex.Message}", LogType.Error);
            }
        }
コード例 #21
0
        /// <summary>
        /// Assigns every property from another instance
        /// </summary>
        /// <param name="from">Object to assign from</param>
        /// <exception cref="ArgumentNullException">other is null</exception>
        /// <exception cref="ArgumentException">Types do not match</exception>
        public void Assign(object from)
        {
            if (from == null)
            {
                throw new ArgumentNullException();
            }
            if (!(from is Channels other))
            {
                throw new ArgumentException("Invalid type");
            }

            HTTP.Assign(other.HTTP);
            Telnet.Assign(other.Telnet);
            File.Assign(other.File);
            USB.Assign(other.USB);
            AUX.Assign(other.AUX);
            Daemon.Assign(other.Daemon);
            CodeQueue.Assign(other.CodeQueue);
            LCD.Assign(other.LCD);
            SPI.Assign(other.SPI);
            AutoPause.Assign(other.AutoPause);
        }
コード例 #22
0
        private void butConnect_Click(object sender, EventArgs e)
        {
            try
            {
                if (telnet == null)
                {
                    telnet = new Telnet();
                }

                string strIpAddress = txtIPAddress.Text;
                int    intPort      = Convert.ToInt16(txtPort.Text);

                telnet.Connect(strIpAddress, intPort);

                if (telnet.Connected == true)
                {
                    richtxtLogInfo.AppendText("服务器 " + strIpAddress + ":" + intPort + " 连接成功。\r\n");
                    richtxtLogInfo.AppendText(telnet.WaitFor("login:"******"cq");
                    richtxtLogInfo.AppendText(telnet.WaitFor("password:"******"windows001");
                    richtxtLogInfo.AppendText(telnet.WaitFor(">"));
                    telnet.Send("dir");
                    richtxtLogInfo.AppendText(telnet.WaitFor(">"));
                    telnet.Send("cd Favorites");
                    richtxtLogInfo.AppendText(telnet.WaitFor(">"));
                    telnet.Send("dir");
                    richtxtLogInfo.AppendText(telnet.WaitFor(">"));
                }

                telnet.Close();
                telnet = null;
            }
            catch (Exception exc)
            {
                richtxtLogInfo.AppendText(exc.Message);
            }
        }
コード例 #23
0
        /// <summary>
        /// Sets the job media mode for the device.
        /// </summary>
        /// <param name="mode">The <see cref="JobMediaMode" /> to set.</param>
        /// <returns><c>true</c> if the job media mode was set successfully, <c>false</c> otherwise.</returns>
        /// <exception cref="ArgumentException"><paramref name="mode" /> is set to <see cref="JobMediaMode.Unknown" />.</exception>
        public bool SetJobMediaMode(JobMediaMode mode)
        {
            if (mode == JobMediaMode.Unknown)
            {
                throw new ArgumentException($"Cannot set Job Media Mode to {mode}.", nameof(mode));
            }

            // We need to have debug telnet enabled on this device, to do that, we will send a payload to the printer opening it up
            if (EnableTelnetDebug())
            {
                // Now that debug telnet is open, we open telnet session and send the command
                const string crcCommandDirectory = "cd print/debug";
                string       crcCommand          = (mode == JobMediaMode.Paperless)
                    ? "VideoCRCMode true"
                    : "VideoCRCMode false";

                using (Telnet telnet = new Telnet(_device.Address, 23000))
                {
                    try
                    {
                        telnet.ReceiveUntilMatch(">");
                        telnet.SendLine(crcCommandDirectory);
                        telnet.ReceiveUntilMatch(">");
                        telnet.SendLine(crcCommand);
                        telnet.ReceiveUntilMatch(">");
                        return(true);
                    }
                    catch (SocketException ex)
                    {
                        LogWarn($"Printer does not have telnet enabled, skipping paperless mode. {ex.Message}");
                        return(false);
                    }
                }
            }
            return(false);
        }
コード例 #24
0
ファイル: DatabaseMethods.cs プロジェクト: jcryer/SolarCore
        // This method uses the Telnet class to pull down a specific celestial body from NASA's Horizons server based on NASA's unique object ID system.
        // It then adds the SolarObject object to the database, as a new record in both the InitialValues and the Object tables.
        public static bool AddObject(int nasaID)
        {
            var t   = new Telnet().Run(nasaID);
            var cmd = new SQLiteCommand($"SELECT count(*) FROM Object;", DBConnection);

            int countObjectView = Convert.ToInt32(cmd.ExecuteScalar());

            string addString = $"insert into Object (ObjectID, Name, Mass, Radius, Obliquity, OrbitalSpeed) " +
                               $"values('{countObjectView}', '{t.Name}', '{t.Mass}', '{t.Radius}', 0, 0);";

            var add = new SQLiteCommand(addString, DBConnection);

            add.ExecuteNonQuery();
            var    position            = t.GetPosition();
            var    velocity            = t.GetVelocity();
            string addinitvaluesString = $"insert into InitialValues (ObjectID, PlanetarySystemID, PositionX, PositionY, PositionZ, " +
                                         $"VelocityX, VelocityY, VelocityZ) values('{countObjectView}', '0', '{position.X}', '{position.Y}', '{position.Z}', '{velocity.X}', '{velocity.Y}', '{velocity.Z}');";

            var addinitValues = new SQLiteCommand(addinitvaluesString, DBConnection);

            addinitValues.ExecuteNonQuery();

            return(true);
        }
コード例 #25
0
 private void ClearScreen(Telnet.Terminal telnetSwitch)
 {
     try
     {
         telnetSwitch.VirtualScreen.CleanScreen();
     }
     catch (Exception e)
     {
         LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString());
         lock (nowUsingItem)
         { nowUsingItem.FlushResult = "试图清屏幕失败,可能是连接被断开" + e.ToString(); }
         throw new Exception();
     }
 }
コード例 #26
0
ファイル: ClientCore.cs プロジェクト: lonely21/chiroptera
        public void Initialize(string[] args)
        {
            if (args.Length == 1 && args[0] == "/reset")
            {
                Properties.Settings.Default.Reset();
            }

            m_baseServicesDispatcher = new BaseServicesDispatcher();

            // Init mainwindow and display
            m_mainWindow         = new MainWindow(this);
            m_paragraphContainer = new ParagraphContainer();
            m_mainWindow.TextView.ParagraphContainer = m_paragraphContainer;
            ChiConsole.SetChiConsole(this);

            // Initialize ironpython
            IronPython.Compiler.Options.GenerateModulesAsSnippets = true;

            /*			IronPython.Compiler.Options.GenerateDynamicMethods = false;
             *                      IronPython.Compiler.Options.DebugMode = true;
             *                      IronPython.Compiler.Options.EngineDebug = true;
             *                      IronPython.Compiler.Options.ILDebug = true;
             *                      IronPython.Compiler.Options.Frames = true;
             */
            m_pythonEngine = new PythonEngine();
            //m_pythonEngine.CreateModule("globals", true);

            ChiPythonStream s = new ChiPythonStream();

            m_pythonEngine.SetStandardOutput(s);
            m_pythonEngine.SetStandardError(s);
            m_pythonEngine.SetStandardInput(s);
            m_pythonEngine.AddToPath(Application.StartupPath + "/lib");
#if DEBUG
            m_pythonEngine.AddToPath(@"../../../scripts/lib");
#endif
            m_pythonEngine.LoadAssembly(typeof(TriggerManager).Assembly);             // load ChiropteraBase
            m_pythonEngine.LoadAssembly(typeof(System.Drawing.Bitmap).Assembly);      // load System.Drawing
            m_pythonEngine.LoadAssembly(typeof(System.Windows.Forms.Keys).Assembly);  // load System.Windows.Forms

            // Network
            m_telnet = new Telnet();
            m_telnet.connectEvent    += new Telnet.ConnectDelegate(_ConnectEvent);
            m_telnet.disconnectEvent += new Telnet.DisconnectDelegate(_DisconnectEvent);
            m_telnet.receiveEvent    += new Telnet.ReceiveDelegate(_ReceiveEvent);
            m_telnet.promptEvent     += new Telnet.PromptDelegate(_PromptEvent);
            m_telnet.telnetEvent     += new Telnet.TelnetDelegate(_TelnetEvent);



            m_commandManager = new CommandManager(m_baseServicesDispatcher);
            AddBuiltinCommands();

            m_triggerManager = new TriggerManager(m_baseServicesDispatcher);
            m_triggerManager.SetTriggers(Properties.Settings.Default.Triggers);

            m_hiliteManager = new HiliteManager(m_triggerManager);

            m_keyManager = new KeyManager(m_baseServicesDispatcher);
            m_keyManager.SetKeyBindings(Properties.Settings.Default.KeyBindings);

            PythonInterface.Initialize(m_baseServicesDispatcher, m_triggerManager, m_commandManager, this,
                                       this, m_pythonEngine, m_keyManager, m_hiliteManager);

            try
            {
#if DEBUG
                PythonInterface.RunScript(Path.GetFullPath("../../../scripts/std/init_std.bc"));
#else
                PythonInterface.RunScript(Path.Combine(Environment.CurrentDirectory, "std/init_std.bc"));
#endif
            }
            catch (Exception e)
            {
                ChiConsole.WriteError("Error running init_std.bc", e);
            }

            try
            {
                string userScript = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Chiroptera/init.bc");
                if (File.Exists(userScript))
                {
                    PythonInterface.RunScript(userScript);
                }
            }
            catch (Exception e)
            {
                ChiConsole.WriteError("Error running init.bc", e);
            }

            Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            Version baseVersion    = System.Reflection.Assembly.GetAssembly(typeof(Telnet)).GetName().Version;
            ChiConsole.WriteLine("Chiroptera version {0} (base {1})", currentVersion.ToString(2), baseVersion.ToString(2));
            ChiConsole.WriteLine("Using {0}", PythonEngine.VersionString);

            CheckClientVersion();
        }
コード例 #27
0
        public ActionResult Video(string path, string file)
        {
            KillVLCProc();
            RunVLC();
            Guid vodId = Guid.NewGuid();
            using (var telnet = new Telnet()) {
                telnet.Connect("127.0.0.1", 4212);
                telnet.Send("admin"); // password
                telnet.Receive();
                telnet.Send(string.Format("new {0} broadcast enabled", vodId));
                telnet.Receive();
                telnet.Send(string.Format("setup {0} input \"{1}\"", vodId, Path.Combine(path, file)));
                telnet.Receive();
                //telnet.Send(string.Format("setup {0} mux mov", vodId)); // mp4 mp2t mp2p ts ps mp2v mp4v avi asf
                telnet.Send("setup {0} output #transcode{$t}:gather:rtp{mp4a-latm,sdp=rtsp://0.0.0.0/{0}.sdp}"
                                .Replace("{0}", vodId.ToString())
                                .Replace("$t", TranscoderSettings));
                telnet.Receive();
                telnet.Send(string.Format("control {0} play", vodId));
                telnet.Receive();
            }

            return Redirect(string.Format("rtsp://{0}/{1}.sdp", Request.Url.Host, vodId));
        }
コード例 #28
0
        private void SendLoginPassword_HighPriv(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
        {
            //enable密码
            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable密码");
            lock (nowUsingItem)
            {
                nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable密码\n";
            }
            try
            {
                telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForEnablePassword);
            }
            catch (Exception e)
            {
                LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString());
                lock (nowUsingItem)
                { nowUsingItem.FlushResult = "没有提示输入enable密码/enable用户名错误?"; }
                throw new Exception();
            }
            lock (nowUsingItem)
            { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送enable密码\n"; }
            if (!telnetSwitch.SendResponse(nowUsingItem.EnablePassword, true))
            {
                lock (nowUsingItem)
                { nowUsingItem.FlushResult = "错误:发送enable密码失败"; }
                throw new Exception();
            }

            if (!telnetSwitch.WaitForChangedScreen())
            {
                lock (nowUsingItem)
                { nowUsingItem.FlushResult = "错误:WaitForChangedScreen返回false"; }
                throw new Exception();
            }
        }
コード例 #29
0
        private void DealWithErrorStuff(Telnet.Terminal telnetSwitch)
        {
            string infomationToWriteInfo = nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + nowUsingItem.FlushResult;
            if (telnetSwitch.VirtualScreen != null)
            {
                infomationToWriteInfo += telnetSwitch.VirtualScreen.Hardcopy().Trim();
            }
            else
            {
                infomationToWriteInfo += "=====NULL=====";
            }
            LogInToEvent.WriteInfo(infomationToWriteInfo);
            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "失败,日志:\n" + telnetSwitch.GetHistory);

            RemoveFromDisableListForErrorOcour();

            AddsToErrorList();

            lock (nowUsingItem)
            {
                nowUsingItem.LastFlushLog = telnetSwitch.GetHistory;
            }
            nowUsingItem.LastFlushTime = DateTime.Now;

            if (telnetSwitch.IsOpenConnection())
            {
                if (telnetSwitch.SendLogout() == false)
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "请求注销失败"; }
                }
                telnetSwitch.Close();
            }
        }
コード例 #30
0
 private void SendErrdisableRecoveryCommand(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
 {
     nowUsingItem.LastFlushLog += "\n SendErrdisableRecoveryCommand ";
     nowUsingItem.LastFlushLog += "\n 发送:" + whatTypeOfSwitch.SwitchCommandForRecoving + "\r\n";
     if (!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForRecoving, true))
     {
         lock (nowUsingItem)
         {
             nowUsingItem.LastFlushLog += "\n" + "发送恢复命令失败\n";
         }
         throw new Exception();
     }
     for (int i = 0; i < 20; ++i)
     {
         telnetSwitch.SendResponse(" ", true);
     }
 }
コード例 #31
0
 private void GetIntoTerminalConfigMode(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
 {
     nowUsingItem.LastFlushLog += "\n GetIntoTerminalConfigMode ";
     nowUsingItem.LastFlushLog += "\n 发送:" + whatTypeOfSwitch.SwitchCommandForConfigMode + "\r\n";
     if (!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForConfigMode, true))
     {
         lock (nowUsingItem)
         {
             nowUsingItem.LastFlushLog += "\n" + "进入终端配置模式失败\n";
         }
         throw new Exception();
     }
     for (int i = 0; i < 20; ++i)
     {
         telnetSwitch.SendResponse(" ", true);
     }
 }
コード例 #32
0
 private string GetAllDataTransmited(Telnet.Terminal telnetSwitch)
 {
     string dataContains;
     try
     {
         dataContains = telnetSwitch.VirtualScreen.Hardcopy().Trim(); ;
     }
     catch (NullReferenceException)
     {
         lock (nowUsingItem)
         { nowUsingItem.FlushResult = "发送等待命令行参数的请求过程中断开连接"; }
         throw new Exception();
     }
     catch (Exception e)
     {
         lock (nowUsingItem)
         { nowUsingItem.FlushResult = "发送等待命令行参数的请求过程中发生了异常," + e.ToString(); }
         throw new Exception();
     }
     return dataContains;
 }
コード例 #33
0
        private void DealWithSuccessStuff(string nowProgressing, Telnet.Terminal telnetSwitch)
        {
            nowUsingItem.LastFlushTime = DateTime.Now;

            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "成功,日志:\n" + telnetSwitch.GetHistory);
            lock (nowUsingItem)
            { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "成功\n"; }
            //成功

            RemoveFromErrorList();

            if (nowProgressing == nowUsingItem.FlushResult)
            {
                lock (nowUsingItem)
                {
                    nowUsingItem.FlushResult = "";
                }

            }

            lock (nowUsingItem)
            {
                nowUsingItem.LastFlushLog += "\n\n SESSIONLOG:\n\n" + telnetSwitch.GetHistory;
            }

            if (telnetSwitch.IsOpenConnection())
            {
                if (telnetSwitch.SendLogout() == false)
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "请求注销失败"; }
                    throw new Exception();
                }
                telnetSwitch.Close();
            }
        }
コード例 #34
0
        private void MakeSureLowPrivIsGood(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
        {
            //确认登录密码正确性
            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "确认登录密码正确性");
            nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "确认登录密码正确性\n";
            try
            {
                telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForCommandBeforeEnable);

            }
            catch (Exception e)
            {
                LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString());
                lock (nowUsingItem)
                {
                    nowUsingItem.FlushResult = "登录密码错误";
                }
                throw new Exception();
            }
        }
コード例 #35
0
        private void MakeSureEnableSuccess(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
        {
            try
            {
                telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForCommandAfterEnable);

            }
            catch (Exception e)
            {
                LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString());
                lock (nowUsingItem)
                { nowUsingItem.FlushResult = "没有提示enable提示符,enable 密码错误?"; }
                throw new Exception();
            }
        }
コード例 #36
0
        private void WaitForAllSwitchStatusTransmited(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
        {
            //大量交换机显示==more==信息,因此需要等待命令行
            //added @ 2012 05 20 by sc
            for (int counter = 0; counter < 20; ++counter)
            {
                if (!telnetSwitch.SendResponse(" ", false))
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "发送等待命令行参数的请求失败"; }
                    throw new Exception();
                }
            }

            ///最大尝试次数
            const int MAXIMUM_TRY_COUNT = 20;

            for (int currectTry = 0; currectTry <= MAXIMUM_TRY_COUNT; ++currectTry)
            {
                telnetSwitch.WaitForChangedScreen();

                //若是屏幕上没有出现命令提示符
                try
                {
                    if (telnetSwitch.VirtualScreen.FindOnScreen(whatTypeOfSwitch.PromptForCommandAfterEnable, false) != null)
                    {
                        break;
                    }
                }
                catch (NullReferenceException)
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "发送请求命令行参数的请求中,连接断开"; }
                    throw new Exception();
                }
                catch (Exception)
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "发送请求命令行参数的请求失败"; }
                    throw new Exception();
                }

                if (currectTry == MAXIMUM_TRY_COUNT)
                {
                    //到达最大重试门限
                    lock (nowUsingItem)
                    {
                        nowUsingItem.LastFlushLog += "\n到达取得数据最大门限\n";
                    }
                }
                else
                {

                    //发送空格以及两个回车
                    if (!telnetSwitch.SendResponse(" ", true))
                    {
                        lock (nowUsingItem)
                        { nowUsingItem.FlushResult = "发送等待命令行参数的请求失败-1"; }
                        throw new Exception();
                    }
                }

            }
        }
コード例 #37
0
        private void SendLoginUserNameIfNeeded(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
        {
            if (whatTypeOfSwitch.IsThisSwitchNeedsOfUserName)
            {
                LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录用户名");
                lock (nowUsingItem)
                {
                    nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录用户名\n";
                }
                try
                {
                    telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForUserName);

                }
                catch (Exception e)
                {
                    lock (nowUsingItem)
                    {
                        nowUsingItem.FlushResult = "要求用户名时遇到异常-" + e.ToString();
                    }
                    LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString());
                    throw new Exception();
                }

                if (!telnetSwitch.SendResponse(nowUsingItem.UserName, true))
                {
                    lock (nowUsingItem)
                    {
                        nowUsingItem.FlushResult = "未发送用户名";
                    }

                    throw new Exception();
                }

                if (!telnetSwitch.WaitForChangedScreen())
                {
                    lock (nowUsingItem)
                    {
                        nowUsingItem.FlushResult = "等待用户名结果失败";
                    }
                    throw new Exception();
                }

            }
        }
コード例 #38
0
        private void SendLoginPassword_LowPriv(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
        {
            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录密码");
            lock (nowUsingItem)
            {
                nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录密码\n";
            }
            try
            {
                telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForPassword);

            }
            catch (Exception e)
            {
                LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString());
                lock (nowUsingItem)
                {
                    nowUsingItem.FlushResult = "没有要求密码或密码请求字符串不正确";
                }
                throw new Exception();
            }
            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送登录密码");
            lock (nowUsingItem)
            {
                nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送登录密码\n";
            }
            if (!telnetSwitch.SendResponse(nowUsingItem.Password, true))
            {
                lock (nowUsingItem)
                {
                    nowUsingItem.FlushResult = "发送密码失败";
                }
                throw new Exception();
            }
            if (!telnetSwitch.WaitForChangedScreen())
            {
                lock (nowUsingItem)
                {
                    nowUsingItem.FlushResult = "发送密码后没有响应";
                }
                throw new Exception();
            }
        }
コード例 #39
0
 public async Task SendCommandAsync(ChannelSubcommand subCommand, string param)
 {
     await Telnet.SendCommandAsync($"CHAN{ChannelNumber}:{subCommand} {param}", false);
 }
コード例 #40
0
 internal Idle(Telnet tn)
 {
     telnet = tn;
 }
コード例 #41
0
 public async Task SendCommandAsync(ChannelSubcommand subCommand, bool param)
 {
     var value = param ? "1" : "0";
     await Telnet.SendCommandAsync($"CHAN{ChannelNumber}:{subCommand} {value}", false);
 }
コード例 #42
0
ファイル: sf.cs プロジェクト: zendever/Open3270
 public sf(Telnet telnet)
 {
     this.telnet = telnet;
     NSR         = supported_replies.Length;
 }
コード例 #43
0
 private void SendEndToSuperModeCommand(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
 {
     lock (nowUsingItem)
     {
         nowUsingItem.LastFlushLog += "\n SendEndToSuperModeCommand \r\n";
         nowUsingItem.LastFlushLog += "\n 发送:"+ whatTypeOfSwitch.SwitchCommandForEndConfig+"\r\n";
     }
     if(!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForEndConfig, true))
     {
         lock (nowUsingItem)
         {
             nowUsingItem.LastFlushLog += "\n" + "回到普通命令提示模式失败\n";
         }
         throw new Exception();
     }
     for (int i = 0; i < 20; ++i)
     {
         telnetSwitch.SendResponse(" ", true);
     }
 }
コード例 #44
0
ファイル: App.Runtime.cs プロジェクト: hmaster20/mRemoteNC
            private static void OpenConnectionFinal(Connection.Info newConnectionInfo, Connection.Info.Force Force,
                                                    Form ConForm)
            {
                try
                {
                    if (newConnectionInfo.Hostname == "" &&
                        newConnectionInfo.Protocol != Protocols.IntApp)
                    {
                        MessageCollector.AddMessage(MessageClass.WarningMsg,
                                                    Language.strConnectionOpenFailedNoHostname);
                        return;
                    }

                    if (newConnectionInfo.PreExtApp != "")
                    {
                        ExternalTool extA = GetExtAppByName(newConnectionInfo.PreExtApp);
                        if (extA != null)
                        {
                            extA.Start(newConnectionInfo);
                        }
                    }

                    //TODO
                    if (!(((Force & Info.Force.DoNotJump) == Info.Force.DoNotJump) || !SwitchToOpenConnection(newConnectionInfo)))
                    {
                        return;
                    }
                    Base newProtocol;
                        // Create connection based on protocol type
                        switch (newConnectionInfo.Protocol)
                        {
                            case Protocols.RDP:
                                newProtocol = new RDP();
                                break;
                            case Protocols.VNC:
                                newProtocol = new VNC();
                                break;
                            case Protocols.SSH1:
                                newProtocol = new SSH1();
                                break;
                            case Protocols.SSH2:
                                newProtocol = new SSH2();
                                break;
                            case Protocols.Telnet:
                                newProtocol = new Telnet();
                                break;
                            case Protocols.Rlogin:
                                newProtocol = new Rlogin();
                                break;
                            case Protocols.Serial:
                                newProtocol = new Serial();
                                break;
                            case Protocols.RAW:
                                newProtocol = new RAW();
                                break;
                            case Protocols.HTTP:
                                newProtocol = new HTTP(newConnectionInfo.RenderingEngine);
                                break;
                            case Protocols.HTTPS:
                                newProtocol = new HTTPS(newConnectionInfo.RenderingEngine);
                                break;
                            case Protocols.TeamViewer:
                                newProtocol = new TeamViewer();
                                break;
                            case Protocols.RAdmin:
                                newProtocol = new RAdmin();
                                break;
                            case Protocols.ICA:
                                newProtocol = new ICA();
                                break;
                            case Protocols.IntApp:
                                newProtocol = new IntApp();
                                if (newConnectionInfo.ExtApp == "")
                                {
                                    throw (new Exception(Language.strNoExtAppDefined));
                                }
                                break;
                            default:
                                return;
                        }

                    string cPnl;
                    if (((newConnectionInfo.Panel == "") | ((Force & Connection.Info.Force.OverridePanel) == Connection.Info.Force.OverridePanel)) | Settings.Default.AlwaysShowPanelSelectionDlg)
                    {
                        var frmPnl = new frmChoosePanel();
                        if (frmPnl.ShowDialog() == DialogResult.OK)
                        {
                            cPnl = frmPnl.Panel;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        cPnl = newConnectionInfo.Panel;
                    }

                    Form cForm = ConForm ?? WindowList.FromString(cPnl);
                    
                    if (cForm == null)
                    {
                        cForm = AddPanel(cPnl);
                        cForm.Focus();
                    }
                    else
                    {
                        (cForm as UI.Window.Connection).Show(frmMain.Default.pnlDock);
                        (cForm as UI.Window.Connection).Focus();
                    }

                    Control cContainer = (cForm as UI.Window.Connection).AddConnectionTab(newConnectionInfo);

                    if (newConnectionInfo.Protocol == Protocols.IntApp)
                    {
                        if (GetExtAppByName(newConnectionInfo.ExtApp).Icon != null)
                        {
                            (cContainer as TabPage).Icon =
                                GetExtAppByName(newConnectionInfo.ExtApp).Icon;
                        }
                    }

                    newProtocol.Closed +=  (cForm as UI.Window.Connection).Prot_Event_Closed;
                    newProtocol.Connected += (cForm as UI.Window.Connection).Prot_Event_Connected;
                    newProtocol.Disconnected += Prot_Event_Disconnected;
                    newProtocol.Connected += Prot_Event_Connected;
                    newProtocol.Closed += Prot_Event_Closed;
                    newProtocol.ErrorOccured += Prot_Event_ErrorOccured;
                    (cForm as UI.Window.Connection).ResizeBegin += newProtocol.ResizeBegin;
                    (cForm as UI.Window.Connection).ResizeEnd += newProtocol.ResizeEnd;
                    (cForm as UI.Window.Connection).Resize += newProtocol.Resize;

                    newProtocol.InterfaceControl = new InterfaceControl(cContainer, newProtocol, newConnectionInfo);

                    newProtocol.Force = Force;

                    if (newProtocol.SetProps() == false)
                    {
                        newProtocol.Close();
                        return;
                    }

                    if (newProtocol.Connect() == false)
                    {
                        newProtocol.Close();
                        if (newProtocol is PuttyBase&&!ProblemFixer.IsPuTTYOk())
                        {
                            ProblemFixer.FixPuTTYProblem();
                        }
                        if (newProtocol is TeamViewer && !ProblemFixer.IsTeamViewerOk())
                        {
                            ProblemFixer.FixTVProblem();
                        }
                        if (newProtocol is RAdmin && !ProblemFixer.IsRAdminOk())
                        {
                            ProblemFixer.FixRAdminProblem();
                        }
                        return;
                    }

                    newConnectionInfo.OpenConnections.Add(newProtocol);

                    if (newConnectionInfo.IsQuicky == false)
                    {
                        if (newConnectionInfo.Protocol != Protocols.IntApp)
                        {
                            Node.SetNodeImage(newConnectionInfo.TreeNode, Enums.TreeImage.ConnectionOpen);
                        }
                        else
                        {
                            ExternalTool extApp = GetExtAppByName((string)newConnectionInfo.ExtApp);
                            if (extApp != null)
                            {
                                if (extApp.TryIntegrate)
                                {
                                    if (newConnectionInfo.TreeNode != null)
                                    {
                                        Node.SetNodeImage(newConnectionInfo.TreeNode,
                                                          Enums.TreeImage.ConnectionOpen);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageCollector.AddMessage(MessageClass.ErrorMsg,
                                                Language.strConnectionOpenFailed + Constants.vbNewLine +
                                                ex.Message);
                }
            }
コード例 #45
0
 private void SendEnableCommand(Telnet.Terminal telnetSwitch)
 {
     if (!telnetSwitch.SendResponse("enable", true))
     {
         lock (nowUsingItem)
         {
             nowUsingItem.FlushResult = "发送enable指令失败";
         }
         throw new Exception();
     }
     if (!telnetSwitch.WaitForChangedScreen())
     {
         lock (nowUsingItem)
         {
             nowUsingItem.FlushResult = "发送enable指令后没有响应";
         }
         throw new Exception();
     }
 }
コード例 #46
0
        private void DealWithErrorStuff(Telnet.Terminal telnetSwitch)
        {
            string infomationToWriteInfo = nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + nowUsingItem.FlushResult;
            if (telnetSwitch.VirtualScreen != null)
            {
                infomationToWriteInfo += telnetSwitch.VirtualScreen.Hardcopy().Trim();
            }
            else
            {
                infomationToWriteInfo += "=====NULL=====";
            }
            LogInToEvent.WriteInfo(infomationToWriteInfo);
            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "失败,日志:\n" + telnetSwitch.GetHistory);

            lock (nowUsingItem)
            {
                nowUsingItem.LastFlushLog += "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n===========================\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
                nowUsingItem.LastFlushLog += infomationToWriteInfo;
                nowUsingItem.LastFlushLog += telnetSwitch.GetHistory;
                nowUsingItem.LastFlushLog += "\r\n错误返回";
                nowUsingItem.FlushResult = "在恢复过程中出现错误";
            }
            nowUsingItem.LastFlushTime = DateTime.Now;

            if (telnetSwitch.IsOpenConnection())
            {
                if (telnetSwitch.SendLogout() == false)
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "请求注销失败"; }
                }
                telnetSwitch.Close();
            }
            lock (nowUsingItem)
            {
                nowUsingItem.FlushResult = "在试图恢复时发生错误";
            }
        }
コード例 #47
0
ファイル: SF.cs プロジェクト: xandr001/Open3270
 public StructuredField(Telnet telnet)
 {
     this.telnet = telnet;
     NSR         = SupportedReplies.Length;
 }
コード例 #48
0
        private void SendEnableUserNameIfNeeded(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
        {
            //enable登录过程
            if (whatTypeOfSwitch.IsThisSwitchNeedsOfEnableUserName)
            {
                LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable用户名登录");
                nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable用户名登录\n";
                try
                {
                    telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForEnableUserName);

                }
                catch (Exception e)
                {
                    LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString());
                    lock (nowUsingItem)
                    {
                        nowUsingItem.FlushResult = "没有提示输入enable用户名";
                    }
                    throw new Exception();
                }
                lock (nowUsingItem)
                {
                    nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送enable用户名\n";
                }
                if (!telnetSwitch.SendResponse(nowUsingItem.EnableUsername, true))
                {
                    lock (nowUsingItem)
                    {
                        nowUsingItem.FlushResult = "发送enable用户名失败";
                    }
                    throw new Exception();
                }
                if (!telnetSwitch.WaitForChangedScreen())
                {
                    lock (nowUsingItem)
                    {
                        nowUsingItem.FlushResult = "发送enable用户名后没有响应";
                    }
                    throw new Exception();
                }
            }
        }