public void RemindStartOfWeek(Reminder startOfWeekReminder)
        {
            var dateToday = DateTime.Now;
            TimeSpan accumulatedTime = new TimeSpan(0, 0, 0);
            if (dateToday.ToString("ddd") == "Mon" && dateToday.Hour == startOfWeekReminder.TimeOfActivation.Hour && dateToday.Minute == startOfWeekReminder.TimeOfActivation.Minute ) //should get the hour from a reminder!dateToday.ToString("h tt") == "4 PM"
            {
                IRepository repo = new Repository();
                var startOfWeekTime = dateToday.AddDays(-7);
                //var dateTomorrow = dateToday.AddDays(1);

                var list = repo.GetByStartDate(startOfWeekTime, dateToday);

                foreach (SparkTask task in list)
                {
                    if(task.State != TaskState.reported){ accumulatedTime = accumulatedTime.Add(task.TimeElapsed); }
                }

                if (accumulatedTime >= new TimeSpan(36, 0, 0))
                {
                    ReminderEventArgs args = new ReminderEventArgs(startOfWeekReminder, new SparkTask()); //should be the reminder im using send the task can stay like this.
                    reminderControl.OnEventHaveToReport(args);
                    startOfWeekReminder.TimeOfActivation = startOfWeekReminder.TimeOfActivation.AddHours(1);
                    repo.Update(startOfWeekReminder);
                }

            }
        }
        public void RemindEndOfWeek(Reminder endOfWeekReminder)
        {
            var dateToday = DateTime.Now;
            TimeSpan accumulatedTime = new TimeSpan(0,0,0);

            if (dateToday.ToString("ddd") == "Mon" && dateToday.Hour == endOfWeekReminder.TimeOfActivation.Hour && dateToday.Minute == endOfWeekReminder.TimeOfActivation.Minute)
            {
                IRepository repo = new Repository();
                var startOfWeekTime = dateToday.AddDays(-4);

                var list = repo.GetByStartDate(startOfWeekTime, dateToday);

                foreach(SparkTask task in list)
                {
                    if (task.State != TaskState.reported){ accumulatedTime = accumulatedTime.Add(task.TimeElapsed); }
                }

                if (accumulatedTime >= new TimeSpan(36, 0, 0))
                {
                    ReminderEventArgs args = new ReminderEventArgs(endOfWeekReminder, new SparkTask());
                    reminderControl.OnEventHaveToReport(args);
                    endOfWeekReminder.TimeOfActivation = endOfWeekReminder.TimeOfActivation.AddHours(1);
                    repo.Update(endOfWeekReminder);
                    //event!
                }
            }
        }
 public void RemindStartOfDay(Reminder startOfDayReminder)
 {
     var dateToday = DateTime.Now;
     if (dateToday.Hour == startOfDayReminder.TimeOfActivation.Hour && dateToday.Minute == startOfDayReminder.TimeOfActivation.Minute) //should get the hour from a reminder!
     {
         //do something
     }
 }
        public override int Run(String[] RemainingArguments)
        {
            IRavenEntity reminderToFetch = new Reminder();
            var actualReminderId = "Reminders/" + ReminderId;
            reminderToFetch.Id = actualReminderId;

            Reminder reminderToSet= SparkLogic.fetch(reminderToFetch) as Reminder;

            if (reminderToSet != null)
            {
                ReminderControl reminderControl = new ReminderControl();
            }
            return 0;
        }
        public IRavenEntity GetItem(String entityName)
        {
            if (entityName == "task")
            {
                SparkTask itemToAdd = new SparkTask();
                while (itemToAdd.Description == null || itemToAdd.Description == "")
                {
                    Console.WriteLine("Add a description for the task");
                    itemToAdd.Description = Console.ReadLine();
                    if (itemToAdd.Description == null || itemToAdd.Description == "")
                    {
                        Console.WriteLine("You must add a Description");
                    }
                }

                while (itemToAdd.Duration <= 0)
                {

                    int toDuration;
                    Console.WriteLine("Add a duration (in minutes) for the task");
                    String input = Console.ReadLine();
                    if (int.TryParse(input, out toDuration))
                    {
                        itemToAdd.Duration = toDuration;
                    }
                    if (itemToAdd.Duration <= 0)
                    {
                        Console.WriteLine("The duration must be a number greater than 0");
                    }
                }
                Console.WriteLine("Add a Client for the task");
                itemToAdd.Client = Console.ReadLine();

                itemToAdd.StartDate= DateTime.Now;
                itemToAdd.State=  TaskState.Paused;

                return itemToAdd;
            }

            if (entityName == "reminder")
            {
                Reminder itemToAdd = new Reminder();

                while (itemToAdd.Description == null|| itemToAdd.Description == "")
                {
                    Console.WriteLine("Add a description for the reminder");
                    itemToAdd.Description = Console.ReadLine();
                }
                while (itemToAdd.Interval <= 0)
                {
                    Console.WriteLine("Add an interval (in minutes) for the reminder");
                    String input = Console.ReadLine();
                    int ToInterval;
                    if (int.TryParse(input, out ToInterval))
                    {
                        itemToAdd.Interval = ToInterval;
                    }
                    if (itemToAdd.Interval <= 0)
                    {
                        Console.WriteLine("The Interval must be a number greater than 0");
                    }
                }

                return itemToAdd;
            }

            return null;
        }
 public ReminderEventArgs(Reminder receivedReminder, SparkTask receivedTask)
 {
     TheReminder = receivedReminder;
     TheTask = receivedTask;
 }
        public override int Run(string[] remainingArguments)
        {
            if(EntityType.ToLower() == "task")
            {
                SparkTask taskToAdd = new SparkTask();
                taskToAdd.Description = Description;
                int duration;
                if (int.TryParse(Duration, out duration))
                {
                    if (duration <= 0)
                    {
                        Console.WriteLine("The duration must be a number grather than 0");
                        return 0;
                    }
                    taskToAdd.Duration = duration;
                }
                else
                {
                    Console.WriteLine("The duration must be an integer");
                    return 0;
                }
                taskToAdd.Client = Client;
                taskToAdd.StartDate = DateTime.Now;
                taskToAdd.State = TaskState.Paused;

                AddItemCmd addItemCmd = new AddItemCmd();

                addItemCmd.ItemToWork = taskToAdd;

                var result = addItemCmd.AddItem();
                Console.WriteLine(result);
                return 0;
            }

            if (EntityType.ToLower() == "reminder")
            {
                Reminder reminderToAdd = new Reminder();
                reminderToAdd.Description = Description;
                int interval;
                if (int.TryParse(Duration, out interval))
                {
                    if (interval <= 0)
                    {
                        Console.WriteLine("The duration must be a number grather than 0");
                        return 0;
                    }
                    reminderToAdd.Interval = interval;
                }
                else
                {
                    Console.WriteLine("The duration must be an integer");
                    return 0;
                }

                String pattern = @"((?<hour>\d{2})\:(?<minutes>\d{2}))";
                var regex = new Regex(pattern, RegexOptions.IgnoreCase);
                var match = regex.Match(TimeOfActivation);
                int hour, minutes;

                if (!int.TryParse(match.Groups["hour"].Value, out hour) || !int.TryParse(match.Groups["minutes"].Value, out minutes))
                {
                    Console.WriteLine("The hour has to be numbers");
                    return 0;
                }

                if (int.TryParse(match.Groups["hour"].Value, out hour))
                {
                    if (hour < 00 && hour > 23)
                    {
                        Console.WriteLine("The hours must be between 00 and 23");
                        return 0;
                    }
                }
                if (int.TryParse(match.Groups["minutes"].Value, out minutes))
                {
                    if (minutes < 00 && minutes > 59)
                    {
                        Console.WriteLine("minutes must be between 00 and 59");
                        return 0;
                    }
                }

                DateTime ActivationTime = DateTime.Now;
                TimeSpan ts = new TimeSpan(hour, minutes, 0);
                ActivationTime = ActivationTime.Date + ts;

                reminderToAdd.TimeOfActivation = ActivationTime;
                reminderToAdd.Type = ReminderType.Custom;
                reminderToAdd.Source = ReminderSource.User;

                AddItemCmd addItemCmd = new AddItemCmd();

                addItemCmd.ItemToWork = reminderToAdd;

                var result = addItemCmd.AddItem();
                Console.WriteLine(result);
                return 0;
            }
            else { Console.WriteLine("The type of entity should be a task or reminder"); }

            return 0;
        }