public Track(Habit habit, Guid usr_id)
 {
     if (habit == null)
     {
         throw new Exception("Habit is null");
     }
     if (usr_id == null)
     {
         throw new Exception("User is null");
     }
     if (!habit.UserId.Equals(usr_id))
     {
         throw new Exception("User don't have this habit");
     }
     this._todo   = habit;
     this._userId = usr_id;
 }
Ejemplo n.º 2
0
        public static AbcApplication Create(List <Habit> listHabit)
        {
            if (listHabit == null)
            {
                throw new Exception("the Habit is not created yet");
            }

            AbcApplication      daily        = new HabitTracker(listHabit);
            Habit               habits       = null;
            DominatingHandler   dominating   = new DominatingHandler(new DominatingGain());
            WorkaholicHandler   workaholic   = new WorkaholicHandler(new WorkaholicGain());
            EpicComebackHandler epiccomeback = new EpicComebackHandler(new EpicComebackGain());

            habits.Attach(dominating);
            habits.Attach(workaholic);
            habits.Attach(epiccomeback);

            return(daily);
        }
 public HabitTrack(Habit habit, Guid usr_id, DateTime date) : base(habit, usr_id)
 {
     this._date = date;
 }
Ejemplo n.º 4
0
 public EpicComeback(Habit habit) : base(habit)
 {
 }
Ejemplo n.º 5
0
 public Workaholic(Habit habit) : base(habit)
 {
 }
Ejemplo n.º 6
0
 public Dominating(Habit habit) : base(habit)
 {
 }
Ejemplo n.º 7
0
 public TrackResult(Habit habit)
 {
     this.Habits = habit;
 }
Ejemplo n.º 8
0
        public static Log AddLog(Habit habit, DateTime currentDate, IBadgeRepository badgeRepo = null, IHabitRepository habitRepo = null)
        {
            string[] days_off   = habit.DaysOff;
            string   currentDay = (currentDate.DayOfWeek.ToString()).Substring(0, 3);
            int      count      = 0;

            DateTime[] allLog       = habit.Log;
            DateTime   lastDateTime = DateTime.Now;

            if (allLog.Length == 0)
            {
                lastDateTime = currentDate.AddDays(-1);
            }
            else if (allLog.Length != 0)
            {
                lastDateTime = allLog[allLog.Length - 1];
            }

            int current_streak = habit.CurrentStreak;
            int longest_streak = habit.LongestStreak;

            int diff = (currentDate - lastDateTime).Days;

            if (diff <= 0)
            {
                throw new Exception("Today, You already Logs it");
            }
            else if (diff == 1)
            {
                current_streak++;
            }
            else if (diff > 1 && diff < 7)
            {
                for (int i = 1; i < diff; i++)
                {
                    if (Array.Exists(days_off, element => element == ((lastDateTime.AddDays(i).DayOfWeek.ToString()).Substring(0, 3))) == false)
                    {
                        break;
                    }
                    else
                    {
                        count++;
                    }
                }
                if (count == (diff - 1))
                {
                    current_streak++;
                }
                else
                {
                    current_streak = 5;
                }
            }
            else
            {
                current_streak = 1;
            }

            if (longest_streak < current_streak)
            {
                longest_streak = current_streak;
            }
            if (current_streak == 0 || longest_streak == 0)
            {
                current_streak = 1;
                longest_streak = 1;
            }

            if (Array.Exists(days_off, element => element == ((currentDate.DayOfWeek.ToString()).Substring(0, 3))) == true)
            {
                count = 1;
            }

            DateTime[] logDate = { currentDate };
            string[]   logDay  = { currentDay };

            Log log = new Log(current_streak, longest_streak, logDate, logDay);

            //Domain Event
            TriggerHandler Dominating   = new DominatingHandler(badgeRepo, new ActivityDominating());
            TriggerHandler Workaholic   = new WorkaholicHandler(badgeRepo, new ActivityWorkaholic());
            TriggerHandler EpicComeback = new EpicComebackHandler(badgeRepo, new ActivityEpicComeback());

            habit.Attach(Dominating);
            habit.Attach(Workaholic);
            habit.Attach(EpicComeback);

            if (isDominating(habit.UserID, badgeRepo, current_streak))
            {
                habit.Broadcast(new Dominating(habit.UserID));
            }
            if (isWorkaholic(habit.UserID, badgeRepo, habitRepo, count))
            {
                habit.Broadcast(new Workaholic(habit.UserID));
            }
            if (isEpicComeback(habit.UserID, badgeRepo, current_streak, habit))
            {
                habit.Broadcast(new EpicComeback(habit.UserID));
            }

            return(log);
        }
Ejemplo n.º 9
0
        private static bool isEpicComeback(Guid user_id, IBadgeRepository badgeRepo, int CurrentStreak, Habit habit)
        {
            DateTime[] Alldate = habit.Log;
            int        diff;

            if (isDuplicate(user_id, "EpicComeback", badgeRepo) != true)
            {
                for (int i = (habit.LogCount - 1); i > 0; i--)
                {
                    diff = (Alldate[i] - Alldate[i - 1]).Days;
                    if (diff >= 10 && CurrentStreak == 10)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }