public void LoadString_TaskHasValidId_ReturnsId()
        {
            var newTask = new SparkTask
            {
                Id = "Correct Task Id"
            };

            newTask.LoadString().ShouldBe("Correct Task Id");
        }
示例#2
0
        public override int Run(String[] RemainingArguments)
        {
            IRavenEntity taskToFetch  = new SparkTask();
            var          actualTaskId = "SparkTasks/" + TaskId;

            taskToFetch.Id = actualTaskId;
            if (TaskId == null)
            {
                Console.WriteLine("Please specify an Id for the task to activate");
                return(0);
            }
            SparkTask         taskToSet        = SparkLogic.fetch(taskToFetch) as SparkTask;
            TaskStateControl  taskStateControl = new TaskStateControl();
            ActiveTaskProcess taskProcessor    = new ActiveTaskProcess();

            if (taskToSet == null)
            {
                Console.WriteLine("The task specified doesn't exist");
                return(0);
            }

            var result = taskStateControl.SetActiveTask(taskToSet);

            if (result == true)
            {
                Console.WriteLine("The task was activated");
            }
            if (taskToSet != null && result == false)
            {
                taskStateControl.PauseTask();
                taskStateControl.SetActiveTask(taskToSet);
                Console.WriteLine("The Task was activated. The previous task was put on pause");
            }

            ReminderControl.StartTime = DateTime.Now;
            taskProcessor.SetStartTime();
            return(0);
        }
        public override int Run(string[] remainingArguments)
        {
            if (EntityType.ToLower() == "task")
            {
                SparkTask taskToDelete = new SparkTask();
                var       actualId     = "SparkTasks/" + IdToDelete;
                taskToDelete.Id = actualId;

                DeleteItemCmd deleteItemCmd = new DeleteItemCmd();
                deleteItemCmd.ItemToWork = taskToDelete;

                var result = deleteItemCmd.DeleteItem();

                Console.WriteLine(result);
                return(0);
            }

            if (EntityType.ToLower() == "reminder")
            {
                SparkTask reminderToDelete = new SparkTask();
                var       actualId         = "Reminders/" + IdToDelete;
                reminderToDelete.Id = actualId;

                DeleteItemCmd deleteItemCmd = new DeleteItemCmd();
                deleteItemCmd.ItemToWork = reminderToDelete;

                var result = deleteItemCmd.DeleteItem();

                Console.WriteLine(result);
                return(0);
            }
            else
            {
                Console.WriteLine("The type of entity should be a task or reminder");
            }
            return(0);
        }
 public void TaskLoadString_TaskDoesntHaveId_ReturnsNoSuchId()
 {
     var noIdTask = new SparkTask();
     noIdTask.LoadString().ShouldBe("There's no ID");
 }
示例#5
0
        public static bool AddDefaultReminders()
        {
            #region debug
#if DEBUG
            SparkTask thisTask = new SparkTask
            {
                Description = "auto Task default premium plus",
                Duration    = 10,
                Client      = "Client",
                StartDate   = DateTime.Now,
                State       = TaskState.Paused
            };

            SparkTask theOtherTask = new SparkTask
            {
                Description = "task number 2",
                Duration    = 5,
                Client      = "Client number 2",
                StartDate   = DateTime.Now,
                State       = TaskState.Paused,
                TimeElapsed = new TimeSpan(36, 0, 0)
            };


            Reminder thisReminder = new Reminder
            {
                Description = "test reminder",
                Interval    = 1,
                Type        = ReminderType.NoActiveTask,
                Source      = ReminderSource.System
            };


            Reminder thisReminder2 = new Reminder
            {
                Description = "reminder 2",
                Interval    = 1,
                Type        = ReminderType.DefaultHourly,
                Source      = ReminderSource.System
            };


            //ThreadPool.QueueUserWorkItem(delegate { ReminderControl.ActivateReminder(thisReminder, thisTask); });
#endif
            #endregion

            DateTime EntranceTime = DateTime.Now;
            TimeSpan ts           = new TimeSpan(9, 0, 0);
            EntranceTime = EntranceTime.Date + ts;

            DateTime ExitTime = DateTime.Now;
            TimeSpan ts2      = new TimeSpan(15, 0, 0);
            ExitTime = ExitTime.Date + ts2;

            Repository repo = new Repository();
            Reminder   DefaultReminderNoOtherActive = new Reminder
            {
                Description = "There is no active task.",
                Interval    = 120,
                Type        = ReminderType.NoActiveTask,
                Source      = ReminderSource.System
            };
            Reminder DefaultHourlyReminder = new Reminder
            {
                Description = "An hour has passed in the task.",
                Interval    = 60,
                Type        = ReminderType.DefaultHourly,
                Source      = ReminderSource.System
            };

            Reminder StartOfWeek = new Reminder
            {
                Description      = "Start of the week.",
                Interval         = 7,
                TimeOfActivation = EntranceTime,
                Type             = ReminderType.StartOfWeek,
                Source           = ReminderSource.System
            };
            Reminder EndOfWeek = new Reminder
            {
                Description      = "The end of week.",
                Interval         = 7,
                TimeOfActivation = ExitTime,
                Type             = ReminderType.EndOfWeek,
                Source           = ReminderSource.System
            };
            Reminder StartOfDay = new Reminder
            {
                Description = "Start of The day",
                Interval    = 8,
                Type        = ReminderType.StartOfDay,
                Source      = ReminderSource.System
            };
            Reminder EndOfDay = new Reminder
            {
                Description = "End of the Day",
                Interval    = 8,
                Type        = ReminderType.EndOfDay,
                Source      = ReminderSource.System
            };

            #region debug
#if DEBUG
            repo.Add(thisTask);
            repo.Add(thisReminder);
            repo.Add(thisReminder2);
            repo.Add(theOtherTask);
#endif
            #endregion

            repo.Add(DefaultReminderNoOtherActive);
            repo.Add(DefaultHourlyReminder);
            repo.Add(StartOfWeek);
            repo.Add(StartOfDay);
            repo.Add(EndOfDay);
            repo.Add(EndOfWeek);

            return(true);
        }
        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);
        }
示例#7
0
        public override int Run(string[] remainingArguments)
        {
            if (EntityType.ToLower() == "task")
            {
                int       duration;
                SparkTask taskToFetch = new SparkTask();
                var       actualId    = "SparkTasks/" + IdToUpdate;
                taskToFetch.Id = actualId;
                var taskToUpdate = SparkLogic.fetch(taskToFetch) as SparkTask;

                taskToUpdate.Description = Description;
                if (int.TryParse(Duration, out duration))
                {
                    if (duration <= 0)
                    {
                        Console.WriteLine("The duration must be greater than 0");
                        return(0);
                    }
                    taskToUpdate.Duration = duration;
                }

                UpdateItemCmd updateItemCmd = new UpdateItemCmd();
                updateItemCmd.ItemToWork = taskToUpdate;

                var result = updateItemCmd.UpdateItem();
                Console.WriteLine(result);
                return(0);
            }
            if (EntityType.ToLower() == "reminder")
            {
                int      interval;
                Reminder reminderToFetch = new Reminder();
                var      actualId        = "Reminders/" + IdToUpdate;
                reminderToFetch.Id = actualId;
                var reminderToUpdate = SparkLogic.fetch(reminderToFetch) as Reminder;
                reminderToUpdate.Description = Description;
                //if (!int.TryParse(Duration, out interval))
                //{
                //    Console.WriteLine("The duration of the interval must be an integer");
                //    return 0;
                //}
                if (int.TryParse(Duration, out interval))
                {
                    if (interval <= 0)
                    {
                        Console.WriteLine("The interval must be greater than 0");
                        return(0);
                    }
                    reminderToUpdate.Interval = interval;
                }

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

                if (!match.Success)
                {
                    Console.WriteLine("The hour format should be hh:mm unsing 24 hours format.");
                    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;

                reminderToUpdate.TimeOfActivation = ActivationTime;

                UpdateItemCmd updateItemCmd = new UpdateItemCmd();
                updateItemCmd.ItemToWork = reminderToUpdate;

                var result = updateItemCmd.UpdateItem();
                Console.WriteLine(result);
                return(0);
            }
            else
            {
                Console.WriteLine("the entity should be a task or reminder.");
            }
            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);
        }