示例#1
0
        /// <summary>
        /// Processes a connection request and creates marshals and tabs were needed.
        /// </summary>
        /// <param name="input">The raw connection command.</param>
        /// <param name="server">The associated server, null if not applicable.</param>
        private void ProcessConnectionRequest(string input, Server server)
        {
            Connection connection = new Connection();
            ParseResult result = connection.Parse(input);
            Action<IRCTabPage> connectAction = (t) =>
            {
                IRCTabPage serverTab;
                if (t == null)
                {
                    serverTab = new IRCTabPage(this, connection.ToString(), server == null ? connection.Server : server.Alias, IRCTabType.Server);
                    serverTab.Connection = connection;
                    serverTab.Connection.UserName = server == null ? GlobalSettings.Instance.UserName : server.UserName;
                    serverTab.Connection.RealName = server == null ? GlobalSettings.Instance.RealName : server.RealName;
                    serverTab.Connection.Nickname = server == null ? GlobalSettings.Instance.NickName : server.NickName;
                    serverTab.Connection.Mode = server == null ? GlobalSettings.Instance.Mode : server.Mode;

                    List<string> commands = null;

                    if (server != null)
                    {
                        commands = server.Commands;
                    }

                    IRCMarshal marshal = new IRCMarshal(connection, this.channelsTabControl, commands, this);
                    marshal.ChannelCreated += new IRCMarshal.ChannelCreatedHandler(this.ChannelCreated);
                    marshal.NetworkRegistered += (s, e) => this.InvokeAction(() => this.UpdateStatusBarText());

                    serverTab.Marshal = marshal;
                    marshal.ServerTab = serverTab;

                    channelsTabControl.TabPages.Add(serverTab);
                    this.ConfigureNewIRCMarshal(this, marshal);
                }
                else
                {
                    serverTab = t;
                }

                channelsTabControl.SelectedTab = serverTab;
                serverTab.Connection.Connect();
            };

            if (result.Success)
            {
                if (this.channelsTabControl.TabPages.ContainsKey(connection.ToString()))
                {
                    IRCTabPage tabPage = this.channelsTabControl.TabPages[connection.ToString()] as IRCTabPage;
                    if (tabPage.Marshal.IsConnected)
                    {
                        this.channelsTabControl.SelectedTab = tabPage;
                    }
                    else
                    {
                        connectAction.Invoke(tabPage);
                    }
                }
                else
                {
                    connectAction.Invoke(null);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Processes a connection request and creates marshals and tabs were needed.
        /// </summary>
        /// <param name="server">The server to connect to.</param>
        private void ProcessConnectionRequest(Server server)
        {
            string command = null;
            if (string.IsNullOrEmpty(server.Password))
            {
                command = string.Format("/server {0} {1}", server.Address, server.Port);
            }
            else
            {
                command = string.Format("/server {0} {1} {2}", server.Address, server.Port, server.Password);
            }

            this.ProcessConnectionRequest(command, server);
        }
        /// <summary>
        /// Verifies all the data entered into the input controls is valid.
        /// </summary>
        /// <param name="server">The server the data is being entered for.</param>
        /// <returns>true if valid.</returns>
        private bool ValidateData(Server server)
        {
            if (!this.ValidateAlias(this.aliasTextBox.Text, server))
            {
                this.lastValidationError = Strings_Validation.DuplicateAlias;
                this.controlToFocus = this.aliasTextBox;
                return false;
            }

            if (!this.ValidateAddress(this.addressTextBox.Text, server))
            {
                this.controlToFocus = this.addressTextBox;
                return false;
            }

            if (!this.portTextBox.Text.IsNumeric())
            {
                this.lastValidationError = Strings_Validation.NonNumericPort;
                this.controlToFocus = this.portTextBox;
                return false;
            }

            if (!this.ValidateNickName(this.nickNameTextBox.Text))
            {
                this.lastValidationError = Strings_Validation.NickName;
                this.controlToFocus = this.nickNameTextBox;
                return false;
            }

            return true;
        }
 /// <summary>
 /// Verifies that the alias entered is valid.
 /// </summary>
 /// <param name="alias">The alias to validate.</param>
 /// <param name="server">The server the alias represents.</param>
 /// <returns>true if valid.</returns>
 private bool ValidateAlias(string alias, Server server)
 {
     return string.IsNullOrEmpty(alias.Trim()) || FavouriteServers.Instance.Servers.Find(i => i.Alias.Equals(alias, StringComparison.OrdinalIgnoreCase) && i != server) == null;
 }
        /// <summary>
        /// Verifies that the address entered is valid.
        /// </summary>
        /// <param name="address">The address to validate.</param>
        /// <param name="server">The server the address is associated with.</param>
        /// <returns>true if valid.</returns>
        private bool ValidateAddress(string address, Server server)
        {
            bool retval = true;

            if (FavouriteServers.Instance.Servers.Find(i => i.Address.Equals(address, StringComparison.OrdinalIgnoreCase) && i != server) != null)
            {
                retval = false;
                this.lastValidationError = Strings_Validation.AddressInUse;
            }

            return retval;
        }
 /// <summary>
 /// Handles the Click event of System.Windows.Forms.Button.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The event arguments.</param>
 private void ConnectButton_Click(object sender, EventArgs e)
 {
     this.serverToOpen = this.serverTreeView.SelectedNode.Tag as Server;
     this.DialogResult = DialogResult.OK;
 }
        /// <summary>
        /// Adds a server to the tree view.
        /// </summary>
        /// <param name="server">The server to create a node from.</param>
        /// <param name="select">A value indicating whether or not to select the node after creation.</param>
        private void AddServer(Server server, bool select)
        {
            TreeNode node = new TreeNode();
            node.Text = server.Alias;

            if (this.openConnections.Find(i => i.Server.Equals(server.Address, StringComparison.OrdinalIgnoreCase) && i.Port.Equals(server.Port)) != null)
            {
                node.ImageKey = "bullet_green";
                node.SelectedImageKey = "bullet_green";
            }
            else
            {
                node.ImageKey = "bullet_white";
                node.SelectedImageKey = "bullet_white";
            }

            node.Tag = server;

            this.serverTreeView.Nodes[0].Nodes.Add(node);

            if (select)
            {
                this.serverTreeView.SelectedNode = node;
            }
        }