Esempio n. 1
0
        /// <summary>
        /// Retrieves just only the latest badges of each type from the complete list of badges
        /// of the given object
        /// </summary>
        /// <param name="badgeable"></param>
        /// <returns></returns>
        public static List <Badge> GetLatestBadges(this IBadgeable badgeable)
        {
            List <Badge> res = new List <Badge>();

            if (badgeable.Badges.IsNullOrEmpty())
            {
                return(res);
            }

            //sort by ID and then by timestamp:
            List <Badge> allbadges = badgeable.Badges;

            allbadges.Sort(s_badgeComparer);

            short lastBadgeType = -1;

            foreach (Badge b in allbadges)
            {
                //if the type is the same, skip it as we want only the very last one:
                if (lastBadgeType != b.TypeAsNumber)
                {
                    res.Add(b);
                }
                lastBadgeType = b.TypeAsNumber;
            }

            return(res);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the actual badge that matches the given id, if available.
        /// The comparison is made on the badge ID
        /// </summary>
        /// <param name="badgeable"></param>
        /// <param name="badgeID"></param>
        /// <returns>null if not available</returns>
        public static Badge RetrieveBadge(this IBadgeable badgeable, short badgeID)
        {
            if (badgeable == null)
            {
                return(null);
            }
            List <Badge> availBadges = badgeable.Badges;

            if (availBadges.IsNullOrEmpty())
            {
                return(null);
            }

            foreach (Badge badge in availBadges)
            {
                if (badge.ID == badgeID)
                {
                    return(badge);
                }
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns true if the given object already has the given badge.
        /// The comparison is made on the badge ID
        /// </summary>
        /// <param name="badgeable"></param>
        /// <param name="badgeID"></param>
        /// <returns></returns>
        public static bool HasBadge(this IBadgeable badgeable, short badgeID)
        {
            if (badgeable == null)
            {
                return(false);
            }
            List <Badge> availBadges = badgeable.Badges;

            if (availBadges.IsNullOrEmpty())
            {
                return(false);
            }

            foreach (Badge badge in availBadges)
            {
                if (badge.ID == badgeID)
                {
                    return(true);
                }
            }

            return(false);
        }