/// <summary>
        /// Encodes the specified build notification.
        /// </summary>
        /// <param name="notification">The build notification.</param>
        /// <returns>The encoded notification</returns>
        public static string Encode(IBuildServerNotification notification)
        {
            List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();

            // Common encoding
            string notificationTypeString = ((int)notification.Type).ToString(CultureInfo.InvariantCulture);
            list.Add(CreatePair(Field.NotificationTypeId, notificationTypeString));
            list.Add(CreatePair(Field.ProjectId, notification.ProjectId));
            list.Add(CreatePair(Field.BuildConfigId, notification.BuildConfigId));

            // Notification-specific encoding
            if (notification.GetType() == typeof(BuildNotification))
            {
                BuildNotification buildNotification = (BuildNotification)notification;
                string recipientsList = string.Join(Packet.ListSeparator.ToString(CultureInfo.InvariantCulture), buildNotification.Recipients);
                list.Add(CreatePair(Field.BuildRecipients, recipientsList));
            }
            else if (notification.GetType() == typeof(ResponsibilityNotification))
            {
                ResponsibilityNotification responsibilityNotification = (ResponsibilityNotification)notification;
                list.Add(CreatePair(Field.ResponsibleUsername, responsibilityNotification.Recipient));
                list.Add(CreatePair(Field.ResponsibilityState, responsibilityNotification.State));
            }

            return AssembleCommand(list);
        }
 /// <summary>
 /// Creates a build key that can be used by the cache.
 /// </summary>
 /// <param name="notification">The notification.</param>
 /// <returns>A build key</returns>
 public static string CreateBuildKey(IBuildServerNotification notification)
 {
     return notification.ProjectId + notification.BuildConfigId;
 }
 /// <summary>
 /// Updates the cache with the specified notification.
 /// </summary>
 /// <param name="notification">The notification.</param>
 public void Update(IBuildServerNotification notification)
 {
     string buildKey = Utils.CreateBuildKey(notification);
     if (notification.GetType() == typeof(BuildNotification))
     {
         BuildNotification buildNotification = (BuildNotification)notification;
         Parallel.ForEach(buildNotification.Recipients, recipient =>
         {
             User user = this.TryGetUser(recipient);
             UpdateUserActiveBuilds(buildKey, buildNotification, ref user);
             UpdateUserBuildsResponsibleFor(buildKey, buildNotification, ref user);
             this.userCache.AddOrUpdate(user.Username, user, (key, value) => user);
             this.NotifyUpdate(user);
         });
     }
     else if (notification.GetType() == typeof(ResponsibilityNotification))
     {
         ResponsibilityNotification responsibilityNotification = (ResponsibilityNotification)notification;
         User user = this.TryGetUser(responsibilityNotification.Recipient);
         this.UpdateUserBuildsResponsibleFor(buildKey, responsibilityNotification, ref user);
         this.userCache.AddOrUpdate(user.Username, user, (key, value) => user);
         this.NotifyUpdate(user);
     }
 }