Exemple #1
0
        static void Main(string[] args)
        {
            var processed = false;

            Console.Write("Initializing ChronoSpark Time Manager...");
            SparkLogic.Initialize();
            Console.WriteLine("DONE!");

            while (!processed)//!exit
            {
                Console.Write("ChronoSpark => ");
                processed = false;
                var cmd = "run-console";

                ReminderControl        defaultController      = new ReminderControl();
                NoActiveTaskListener   noActiveTaskListener   = new NoActiveTaskListener();
                IntervalPassedListener intervalPassedListener = new IntervalPassedListener();
                TimeToReportListener   timeToReportListener   = new TimeToReportListener();

                noActiveTaskListener.Suscribe(defaultController);
                intervalPassedListener.Suscribe(defaultController);
                timeToReportListener.Suscribe(defaultController);

                ThreadPool.QueueUserWorkItem(delegate { defaultController.ActivateReminders(); });

                String[]           cdmArgs       = cmd.Split(' ');
                var                commands      = GetCommands();
                ConsoleModeCommand consoleRunner = new ConsoleModeCommand(GetCommands);
                commands = commands.Concat(new[] { consoleRunner });
                ConsoleCommandDispatcher.DispatchCommand(commands, cdmArgs, Console.Out);
                processed = true;
            }
        }
Exemple #2
0
        public override int Run(string[] remainingArguments)
        {
            TaskListPrinter lister      = new TaskListPrinter();
            var             listOfTasks = SparkLogic.ReturnTaskList();

            lister.ListTaks(listOfTasks);
            return(0);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public override int Run(String[] RemainingArguments)
        {
            TaskStateControl taskStateControl = new TaskStateControl();
            SparkLogic       sparkLogic       = new SparkLogic();
            var activeTask = sparkLogic.ReturnActiveTask();

            if (activeTask == null)
            {
                Console.WriteLine("There are no active tasks");
                return(0);
            }
            taskStateControl.PauseTask();
            Console.WriteLine("The task has been paused.");

            return(0);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }