Exemplo n.º 1
0
        /// <summary>
        /// The get next.
        /// </summary>
        /// <param name="count">
        /// The count.
        /// </param>
        /// <param name="level">
        /// The level.
        /// </param>
        /// <param name="weekMode">
        /// The week Mode.
        /// </param>
        /// <returns>
        /// The <see cref="DateTime"/>.
        /// </returns>
        public DateTime?GetNext(int count, BadgeLevel level, bool weekMode)
        {
            this.UpdateProgressCache();

            var badgeDates =
                this.badgeProgresses.Values.Where(x => x.CurrentLevel < level)
                .Select(
                    x =>
                    new StatisticProgress(x.CurrentValue, x.MonthValue, x.WeekValue)
            {
                NextTarget =
                    x.Badge.GetNextTarget(
                        level)
            })
                .Select(x => weekMode ? x.NextTargetDateWeek : x.NextTargetDateMonth)
                .Where(x => x.HasValue)
                .OrderBy(x => x.GetValueOrDefault())
                .ToList();

            if (badgeDates.Count < count)
            {
                // not enough to predict
                return(null);
            }

            return(badgeDates.Take(count).Max());
        }
Exemplo n.º 2
0
        public override bool Parse(XElement xml)
        {
            if (xml == null)
            {
                return(false);
            }

            short        id          = 0;
            string       name        = string.Empty;
            string       descr       = string.Empty;
            BadgeSubject refersTo    = BadgeSubject.User;
            int          threshold   = 0;
            BadgeLevel   level       = BadgeLevel.Junior;
            string       iconPath    = string.Empty;
            DateTime     timestamp   = DateTime.Now;
            string       activedescr = string.Empty;

            xml.ParseNode("ID", ref id, false);
            xml.ParseNode("Name", ref name, false);
            xml.ParseNode("Descr", ref descr, false);
            xml.ParseNode <BadgeSubject>("RefersTo", ref refersTo, false);
            xml.ParseNode("Threshold", ref threshold, false);
            xml.ParseNode <BadgeLevel>("Level", ref level, false);
            xml.ParseNode("IconPath", ref iconPath, false);
            xml.ParseNode("Timestamp", ref timestamp, false);
            xml.ParseNode("ActiveDescr", ref activedescr, false);

            Init(id, name, descr, refersTo, threshold, level, iconPath, timestamp, activedescr);

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// The get target.
        /// </summary>
        /// <param name="badge">
        /// The badge.
        /// </param>
        /// <param name="level">
        /// The level.
        /// </param>
        /// <returns>
        /// The <see cref="long?"/>.
        /// </returns>
        public static long?GetNextTarget(this Badge badge, BadgeLevel level)
        {
            if (level == BadgeLevel.Locked)
            {
                return(badge.Bronze);
            }

            if (level == BadgeLevel.Bronze)
            {
                return(badge.Silver);
            }

            if (level == BadgeLevel.Silver)
            {
                return(badge.Gold);
            }

            if (level == BadgeLevel.Gold)
            {
                return(badge.Platinum);
            }

            if (level == BadgeLevel.Platinum)
            {
                return(badge.Black);
            }

            return(null);
        }
Exemplo n.º 4
0
 /// <summary>
 /// This is the complete init method for this class.
 /// It should be used by the children classes in the constructor in order to correctly fill the properties of the object.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="name"></param>
 /// <param name="refersTo"></param>
 /// <param name="threshold"></param>
 /// <param name="level"></param>
 /// <param name="iconPath"></param>
 /// <param name="timestamp"></param>
 protected void Init(short id, string name, string descr, BadgeSubject refersTo, int threshold, BadgeLevel level,
                     string iconPath, DateTime timestamp, string activeDescr)
 {
     ID          = id;
     Name        = name;
     Descr       = descr;
     RefersTo    = refersTo;
     Threshold   = threshold;
     Level       = level;
     IconPath    = iconPath;
     Timestamp   = timestamp;
     ActiveDescr = activeDescr;
 }
Exemplo n.º 5
0
 public static IEnumerable<Badge> ByBadgeLevel(this IEnumerable<Badge> badges, BadgeLevel level)
 {
     return badges.Where(b => b.Level == level);
 }
Exemplo n.º 6
0
 public BadgeNameLevelPair(string name, BadgeLevel level)
 {
     Name  = name;
     Level = level;
 }
Exemplo n.º 7
0
 /// <summary>
 ///   This create a complete Badge
 /// </summary>
 /// <param name="id">Tag ID (from the dictionary)</param>
 /// <param name="name"></param>
 /// <param name="refersTo"></param>
 /// <param name="threshold"></param>
 /// <param name="level"></param>
 /// <param name="iconPath"></param>
 /// <param name="timestamp"></param>
 /// <param name="activeDescr"></param>
 /// --------------------------------------------------------------------------------------------------
 protected Badge(short id, string name, string descr, BadgeSubject refersTo, int threshold, BadgeLevel level,
                 string iconPath, DateTime timestamp, string activeDescr)
 {
     Init(id, name, descr, refersTo, threshold, level, iconPath, timestamp, activeDescr);
 }