public ServerInfo(Client client, int seconds)
 {
     Initialize();
     _client = client;
     _refreshTimer = seconds;
 }
Esempio n. 2
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            int port;
            this.txtServer.Text = this.txtServer.Text.Trim();
            this.txtUsername.Text = this.txtUsername.Text.Trim();
            this.txtPassword.Text = this.txtPassword.Text.Trim();
            this.txtPort.Text = this.txtPort.Text.Trim();
            if (this.txtServer.Text.Length == 0) { MessageBox.Show("Server or IP Address is a required field.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtServer.Focus();  return; }
            if (Uri.CheckHostName(this.txtServer.Text) == UriHostNameType.Unknown) { MessageBox.Show("Invalid Server or IP Address.", "Connection Error", MessageBoxButtons.OK); this.txtServer.Focus(); return; }
            if (this.txtUsername.Text.Length == 0) { MessageBox.Show("Username is a required field.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtUsername.Focus();  return; }
            if (!int.TryParse(this.txtPort.Text, out port)) { MessageBox.Show("Invalid port number specified.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPort.Focus(); return; }

            Logger.LogMessage("Connecting: " + txtServer.Text + ":" + port.ToString(), LogType.Info);

            SetControlPropertyThreadSafe(this.btnConnect, "Enabled", false);
            SetControlPropertyThreadSafe(this.btnConnect, "Text", "Connecting");
            SetControlPropertyThreadSafe(this.txtServer, "Enabled", false);
            SetControlPropertyThreadSafe(this.txtUsername, "Enabled", false);
            SetControlPropertyThreadSafe(this.txtPassword, "Enabled", false);
            SetControlPropertyThreadSafe(this.txtPort, "Enabled", false);

            client = new Client(txtServer.Text, port, txtUsername.Text, txtPassword.Text);
            if (client.IsConnected)
            {
                Logger.LogMessage("Connection established", LogType.Debug);
                WriteRegSZ("host", txtServer.Text);
                WriteRegSZ("username", txtUsername.Text);
                WriteRegSZ("port", txtPort.Text);
                if (cbRememberPW.Checked)
                {
                    WriteRegSZ("password", GetEncString(txtPassword.Text, GetKey(_encKey)));
                }
                else
                {
                    WriteRegSZ("password", null);
                }
                this.si = new ServerInfo(client, 10);
                si.UpdateCompleted += this.PopulateServerInfo;

                UpdateLogonControlState();
                RefreshServerInfo();
                timer.Enabled = true;
            }
            else
            {
                Logger.LogMessage("Connection failed", LogType.Warn);
                MessageBox.Show("Cannot connect to server with specified settings.", "Connection Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                UpdateLogonControlState();
            }
        }
 public ServerInfo(Client client)
     : this(client, 5)
 {
 }