Exemple #1
0
        /// <summary>
        /// Create a new clock event
        /// </summary>
        /// <param name="activationTime">Time it should activate</param>
        /// <param name="repetitionType">When will the event try to activate</param>
        /// <param name="onlyOnce">Will it only activate only once</param>
        /// <param name="actions">Callbacks</param>
        public ClockEvent(SavedTime activationTime,
                          EventRepetitionType repetitionType, bool onlyOnce, params Action <SavedTime>[] actions)
        {
            TimeOfCreation = MainClock.NowTime;
            ActivationTime = activationTime;
            RepetitionType = repetitionType;
            OnlyOnce       = onlyOnce;
            IsInjected     = false;

            AddNewListeners(actions);
        }
Exemple #2
0
        private void AddTimeEvent(EventRepetitionType repetitionType, ClockEvent clockEvent, params Action <SavedTime>[] actions)
        {
            switch (repetitionType)
            {
            case EventRepetitionType.Every_Second:
                AddTo(ref OnSecondChange);
                break;

            case EventRepetitionType.Every_Minute:
                AddTo(ref OnMinuteChange);
                break;

            case EventRepetitionType.Every_Hour:
                AddTo(ref OnHourChange);
                break;

            case EventRepetitionType.Every_Day:
                AddTo(ref OnDayChange);
                break;

            case EventRepetitionType.Every_DayPhase:
                AddTo(ref OnDayPhaseChange);
                break;

            case EventRepetitionType.Every_Month:
                AddTo(ref OnMonthChange);
                break;

            case EventRepetitionType.Every_Year:
                AddTo(ref OnYearChange);
                break;
            }

            void AddTo(ref Action <SavedTime> targetEvent)
            {
                clockEvent?.Setup(ref targetEvent);

                for (int i = 0; i < actions.Length; i++)
                {
                    targetEvent += actions[i];
                }
            }
        }