private void ParameterSaveCommandExecute()
 {
     Inifile.INIWriteValue(iniParameterPath, "System", "RemotePath", RemotePath);
     Inifile.INIWriteValue(iniParameterPath, "System", "MachineID", MachineID);
     Inifile.INIWriteValue(iniParameterPath, "Remote", "IP", RemoteIP);
     Inifile.INIWriteValue(iniParameterPath, "Remote", "PORT", RemotePort.ToString());
     Inifile.INIWriteValue(iniParameterPath, "Local", "IP", LocalIP);
     Inifile.INIWriteValue(iniParameterPath, "Local", "PORT", LocalPort.ToString());
     AddMessage("保存参数");
 }
Ejemplo n.º 2
0
        public ICommunicationMessage SendCommand(ICommunicationMessage command, int timeout)
        {
            // TODO:  添加 Communicator.sendCommand 实现
            command.SeqID = CommandProcessor.AllocateID();
            try
            {
                ICommunicationMessage response = null;
                ManualResetEvent      mutex    = new ManualResetEvent(false);
                lock (this)
                {
                    if (Interlocked.Read(ref m_Started) == 0)
                    {
                        throw new Exception("与服务器的连接未建立.");
                    }

                    lock (this.m_MessagesWaitForResponse)
                    {
                        m_MessagesWaitForResponse[command.SeqID] = new CommonPair <ICommunicationMessage, ManualResetEvent>(null, mutex);
                    }

                    m_Comm.enqueueMessage(command);
                }

                // 等待响应包的回填
                if (!mutex.WaitOne(timeout * 1000, false))
                {
                    throw new Exception(RemoteIP + ":" + RemotePort.ToString() + "服务器通讯超时");
                }

                if (Interlocked.Read(ref m_Started) == 0)
                {
                    throw new Exception(RemoteIP + ":" + RemotePort.ToString() + "服务器通讯中断");
                }

                lock (m_MessagesWaitForResponse)
                {
                    response = m_MessagesWaitForResponse[command.SeqID].First;
                    m_MessagesWaitForResponse.Remove(command.SeqID);
                }

                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                lock (m_MessagesWaitForResponse)
                {
                    m_MessagesWaitForResponse.Remove(command.SeqID);
                }
            }
        }
Ejemplo n.º 3
0
        private void FormRemoteVnc_Load(object sender, EventArgs e)
        {
            this.textBoxDisplayName.Text = DisplayName;
            this.textBoxRemoteIp.Text    = RemoteIp;
            this.textBoxRemotePort.Text  = RemotePort.ToString();

            this.textBoxDisplayName.TextChanged += textBoxDisplayName_TextChanged;
            this.textBoxRemoteIp.TextChanged    += textBoxRemoteIp_TextChanged;
            this.textBoxRemotePort.TextChanged  += textBoxRemotePort_TextChanged;


            buttonOK.DialogResult     = System.Windows.Forms.DialogResult.OK;
            buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;

            this.AcceptButton = buttonOK;
            this.CancelButton = buttonCancel;

            IsDirty = false;
        }
        private Dictionary <string, string> GetValues()
        {
            Dictionary <string, string> valuesDictionary = new Dictionary <string, string>();

            foreach (PropertyName prop in PropertiesLookup.Keys)
            {
                switch (prop)
                {
                case PropertyName.LocalConnectionString:
                    valuesDictionary.Add(PropertiesLookup[prop], LocalConnectionString);
                    break;

                case PropertyName.RemoteHost:
                    valuesDictionary.Add(PropertiesLookup[prop], RemoteHost);
                    break;

                case PropertyName.RemotePassword:
                    valuesDictionary.Add(PropertiesLookup[prop], RemotePassword);
                    break;

                case PropertyName.RemotePort:
                    valuesDictionary.Add(PropertiesLookup[prop], RemotePort.ToString());
                    break;

                case PropertyName.RemoteRetryWrites:
                    valuesDictionary.Add(PropertiesLookup[prop], RemoteRetryWrites.ToString());
                    break;

                case PropertyName.RemoteUserName:
                    valuesDictionary.Add(PropertiesLookup[prop], RemoteUserName);
                    break;

                case PropertyName.RemoteUseSsl:
                    valuesDictionary.Add(PropertiesLookup[prop], RemoteUseSsl.ToString());
                    break;
                }
            }

            return(valuesDictionary);
        }
Ejemplo n.º 5
0
 public override string ToString()
 {
     return((new System.Net.IPAddress(LocalIP)).ToString() + ":" + LocalPort.ToString() + "=>" +
            (new System.Net.IPAddress(RemoteIP)).ToString() + ":" + RemotePort.ToString());
 }
Ejemplo n.º 6
0
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            int LocalPort;
            int RemotePort;

            switch (lstRemotePort.Text)
            {
            case "HTTP": lstRemotePort.Text = "80"; break;

            case "HTTPS": lstRemotePort.Text = "443"; break;

            case "RDP": lstRemotePort.Text = "3389"; break;

            case "POP3": lstRemotePort.Text = "110"; break;

            case "SMTP": lstRemotePort.Text = "25"; break;

            case "IMAP": lstRemotePort.Text = "143"; break;

            case "SSH": lstRemotePort.Text = "22"; break;

            case "TELNET": lstRemotePort.Text = "23"; break;
            }

            if (int.TryParse(txtLocalPort.Text, out LocalPort) == false)
            {
                MessageBox.Show(this, "Invalid Local Port.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (LocalPort < 1 || LocalPort > 65535)
            {
                MessageBox.Show(this, "Invalid Local Port.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (txtRemoteServer.Text.Trim() == "")
            {
                MessageBox.Show(this, "Invalid Remote Server.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (txtRemoteServer.Text.Contains("\"") == true || txtRemoteServer.Text.Contains("^") == true ||
                txtRemoteServer.Text.Contains("\\") == true || txtRemoteServer.Text.Contains("%") == true)
            {
                MessageBox.Show(this, "Invalid Remote Server.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (int.TryParse(lstRemotePort.Text, out RemotePort) == false)
            {
                MessageBox.Show(this, "Invalid Remote Port.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (RemotePort < 1 || RemotePort > 65535)
            {
                MessageBox.Show(this, "Invalid Remote Port.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            string Exec      = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "FoxSDC_RemoteConnect.exe");
            string SessionID = Program.net.CloneSession();

            if (string.IsNullOrWhiteSpace(SessionID) == true)
            {
                MessageBox.Show(this, "Cannot get a new SessionID from the Server", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            try
            {
                Process p = new Process();
                p.StartInfo.FileName        = Exec;
                p.StartInfo.Arguments       = "-direct \"" + Program.net.ConnectedURL + "\" \"" + MID + "\" \"" + SessionID + "\" " + LocalPort.ToString() + " \"" + txtRemoteServer.Text + "\" " + RemotePort.ToString();
                p.StartInfo.UseShellExecute = false;
                p.Start();
            }
            catch (Exception ee)
            {
                MessageBox.Show(this, "Cannot start the process " + Exec + " - " + ee.Message, Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Debug.WriteLine(ee.ToString());
                return;
            }
        }