IrcDotNet.IrcClient.GetSourceFromPrefix C# (CSharp) Method

GetSourceFromPrefix() protected method

Gets the source of a message from the specified prefix. A message source may be a IrcUser or IrcServer.
/// does not represent a valid message source. ///
protected GetSourceFromPrefix ( string prefix ) : IIrcMessageSource
prefix string The raw prefix of the message.
return IIrcMessageSource
        protected IIrcMessageSource GetSourceFromPrefix(string prefix)
        {
            if (prefix == null)
                return null;
            if (prefix.Length == 0)
                throw new ArgumentException(Resources.MessageValueCannotBeEmptyString, "prefix");

            // Check whether prefix represents server or user.
            var prefixMatch = Regex.Match(prefix, regexMessagePrefix);
            var serverName = prefixMatch.Groups["server"].GetValue();
            var nickName = prefixMatch.Groups["nick"].GetValue();
            var userName = prefixMatch.Groups["user"].GetValue();
            var hostName = prefixMatch.Groups["host"].GetValue();
            if (serverName != null)
            {
                return GetServerFromHostName(serverName);
            }
            if (nickName != null)
            {
                // Find user by nick name. If no user exists in list, create it and set its properties.
                var user = GetUserFromNickName(nickName, true);
                if (user.UserName == null)
                    user.UserName = userName;
                if (user.HostName == null)
                    user.HostName = hostName;

                return user;
            }
            throw new ArgumentException(string.Format(
                Resources.MessageInvalidSource, prefix), "prefix");
        }

Usage Example

コード例 #1
0
ファイル: IrcClient.cs プロジェクト: txdv/ircdotnet
            /// <summary>
            /// Initializes a new instance of the <see cref="IrcMessage"/> structure.
            /// </summary>
            /// <param name="client">A client object that has sent/will receive the message.</param>
            /// <param name="prefix">The message prefix that represents the source of the message.</param>
            /// <param name="command">The command name; either an alphabetic word or 3-digit number.</param>
            /// <param name="parameters">A list of the parameters to the message. Can contain a maximum of 15 items.
            /// </param>
            public IrcMessage(IrcClient client, string prefix, string command, IList<string> parameters)
            {
                this.Prefix = prefix;
                this.Command = command;
                this.Parameters = parameters;

                this.Source = client.GetSourceFromPrefix(prefix);
            }
IrcClient