Example #1
0
        private void SetActivatedTask(IEvent ce)
        {
            if (!ce.Enabled)
            {
                return;
            }

            // TODO: check that the beginning time of task is updated, otherwise the task won't be triggered
            ce.UpdateBeginningTime();

            if (IsEventInRange(ce))
            {
                if (ce.ActionEndsEventArgs != null)
                {
                    ce.ActionStartsEvent += EventHandlerFactory.CreateStartingEventHandler(ce);
                    if (ce.ActionEndsEventArgs != null)
                    {
                        ce.ActionEndsEvent += EventHandlerFactory.CreateEndingEventHandler(ce);
                    }
                }

                ActivatedEvents.Add(ce);

                if (ce.AutoDelete)
                {
                    ce.SelfDestructEvent += DeleteEvent;
                }

                ce.SetTimer();
            }
        }
Example #2
0
        public void UpdateEvent <T>(T target) where T : IEvent
        {
            if (target == null)
            {
                return;
            }

            target.DisposeTimer();
            ActivatedEvents.Remove(target);
            ecdb.UpdateEvent(target);

            UpdateEventDB();
            RefreshTasks();
        }
Example #3
0
        private void DeleteEvent(IEvent target)
        {
            if (target == null)
            {
                return;
            }

            target.DisposeTimer();

            ActivatedEvents.Remove(target);
            ecdb.DeleteEvent((CustomEvent)target);

            EventIsDeletedEvent(target);
            target = null;
        }
Example #4
0
        // TODO: write an overloaded function of RefreshTasks for single-added task
        //       otherwise, too much works have to be done when there is only one task is added
        public void RefreshTasks()
        {
            if (EventHandlerFactory == null)
            {
                return;
            }
            //throw new Exception("EventHandlerFactory should not be NULL");

            // TODO: before refresh tasks, check those activated timers and dispose them
            DisposeActivatedTimers();

            // Refresh tasks when this app is opened, or the day is changed. (e.g. 2017/04/10 -> 2017/04/11)
            // NOTE: check whether there will be some unfinished tasks being disposed?
            ActivatedEvents.Clear();

            foreach (IEvent ce in EventDB)
            {
                SetActivatedTask(ce);
            }
        }
Example #5
0
        public void DeleteEvent(Guid targetGUID)
        {
            // NOTE: delete event both in database and ActivatedList
            IEvent target = ecdb.GetEvent(targetGUID);

            if (target == null)
            {
                return;
            }

            // Delete target in both database and activated list
            ecdb.DeleteEvent(target.GUID);

            IEvent activatedTarget = ActivatedEvents.Find(x => x.GUID == targetGUID);

            if (activatedTarget != null)
            {
                activatedTarget.DisposeTimer();
                ActivatedEvents.Remove(activatedTarget);
            }

            EventIsDeletedEvent(target);
            target = null;
        }