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");
}