Example #1
0
        /// <summary>
        /// Calculates the correct bitfield enum value for the event recurrence based on the config values
        /// </summary>
        /// <returns></returns>
        ScheduledEventCommon.eWeekDays CalculateDaysOfWeekRecurrence()
        {
            ScheduledEventCommon.eWeekDays value = new ScheduledEventCommon.eWeekDays();

            if (PropertiesConfig.EnableSunday)
            {
                value = value | ScheduledEventCommon.eWeekDays.Sunday;
            }
            if (PropertiesConfig.EnableMonday)
            {
                value = value | ScheduledEventCommon.eWeekDays.Monday;
            }
            if (PropertiesConfig.EnableTuesday)
            {
                value = value | ScheduledEventCommon.eWeekDays.Tuesday;
            }
            if (PropertiesConfig.EnableWednesday)
            {
                value = value | ScheduledEventCommon.eWeekDays.Wednesday;
            }
            if (PropertiesConfig.EnableThursday)
            {
                value = value | ScheduledEventCommon.eWeekDays.Thursday;
            }
            if (PropertiesConfig.EnableFriday)
            {
                value = value | ScheduledEventCommon.eWeekDays.Friday;
            }
            if (PropertiesConfig.EnableSaturday)
            {
                value = value | ScheduledEventCommon.eWeekDays.Saturday;
            }

            return(value);
        }
Example #2
0
        /// <summary>
        /// Checks existing event to see if it matches the recurrence days
        /// </summary>
        /// <param name="existingEvent"></param>
        /// <param name="eWeekdays"></param>
        /// <returns></returns>
        bool CheckExistingEventRecurrenceForMatch(ScheduledEvent existingEvent, ScheduledEventCommon.eWeekDays eWeekdays)
        {
            bool isMatch = true;

            // Check to see if recurrence matches
            if (eWeekdays != existingEvent.Recurrence.RecurrenceDays)
            {
                return(false);
            }

            return(isMatch);
        }
Example #3
0
        /// <summary>
        /// Checks the day of week in eventTime to see if it matches the weekdays defined in the recurrence enum.
        /// </summary>
        /// <param name="eventTime"></param>
        /// <param name="recurrence"></param>
        /// <returns></returns>
        public static bool CheckIfDayOfWeekMatchesRecurrenceDays(DateTime eventTime, ScheduledEventCommon.eWeekDays recurrence)
        {
            bool isMatch = false;

            var dayOfWeek = eventTime.DayOfWeek;

            Debug.Console(1, "[Scheduler]: eventTime day of week is: {0}", dayOfWeek);

            switch (dayOfWeek)
            {
            case DayOfWeek.Sunday:
            {
                if ((recurrence & ScheduledEventCommon.eWeekDays.Sunday) == ScheduledEventCommon.eWeekDays.Sunday)
                {
                    isMatch = true;
                }
                break;
            }

            case DayOfWeek.Monday:
            {
                if ((recurrence & ScheduledEventCommon.eWeekDays.Monday) == ScheduledEventCommon.eWeekDays.Monday)
                {
                    isMatch = true;
                }
                break;
            }

            case DayOfWeek.Tuesday:
            {
                if ((recurrence & ScheduledEventCommon.eWeekDays.Tuesday) == ScheduledEventCommon.eWeekDays.Tuesday)
                {
                    isMatch = true;
                }
                break;
            }

            case DayOfWeek.Wednesday:
            {
                if ((recurrence & ScheduledEventCommon.eWeekDays.Wednesday) == ScheduledEventCommon.eWeekDays.Wednesday)
                {
                    isMatch = true;
                }
                break;
            }

            case DayOfWeek.Thursday:
            {
                if ((recurrence & ScheduledEventCommon.eWeekDays.Thursday) == ScheduledEventCommon.eWeekDays.Thursday)
                {
                    isMatch = true;
                }
                break;
            }

            case DayOfWeek.Friday:
            {
                if ((recurrence & ScheduledEventCommon.eWeekDays.Friday) == ScheduledEventCommon.eWeekDays.Friday)
                {
                    isMatch = true;
                }
                break;
            }

            case DayOfWeek.Saturday:
            {
                if ((recurrence & ScheduledEventCommon.eWeekDays.Saturday) == ScheduledEventCommon.eWeekDays.Saturday)
                {
                    isMatch = true;
                }
                break;
            }
            }

            Debug.Console(1, "[Scheduler]: eventTime day of week matches recurrence days: {0}", isMatch);

            return(isMatch);
        }
        void myKeypad_ButtonStateChange(GenericBase device, ButtonEventArgs args)
        {
            try
            {
                if (args.Button.State == eButtonState.Pressed)
                {
                    CrestronConsole.PrintLine("Button {0} was pressed.", args.Button.Number);
                    switch (args.Button.Number)
                    {
                    case 1:
                        var selWeekDays = new ScheduledEventCommon.eWeekDays();
                        selWeekDays |= ScheduledEventCommon.eWeekDays.Monday;
                        selWeekDays |= ScheduledEventCommon.eWeekDays.Tuesday;
                        selWeekDays |= ScheduledEventCommon.eWeekDays.Friday;

                        CrestronConsole.PrintLine("Initializing program response for button {0}", args.Button.Number);
                        myEventGroup.ClearAllEvents();
                        if (myEventGroup.ScheduledEvents.ContainsKey("MyEvent") == false)
                        {
                            myEvent             = new ScheduledEvent("MyEvent", myEventGroup);
                            myEvent.Description = "My first event";
                            myEvent.DateAndTime.SetAbsoluteEventTime(2019, 03, 11, 10, 30);
                            myEvent.Acknowledgeable = false;
                            myEvent.Persistent      = true;
                            myEvent.UserCallBack   += new ScheduledEvent.UserEventCallBack(myEvent_UserCallBack);
                            myEvent.Recurrence.Weekly(selWeekDays);

                            /*
                             * myEvent.Recurrence.Weekly(
                             *  ScheduledEventCommon.eWeekDays.Monday &
                             *  ScheduledEventCommon.eWeekDays.Tuesday &
                             *  ScheduledEventCommon.eWeekDays.Friday, 10);
                             */
                            myEvent.Enable();

                            CrestronConsole.PrintLine("Event {0} created for {1}:{2}",
                                                      myEvent.Name,
                                                      myEvent.DateAndTime.Hour,
                                                      myEvent.DateAndTime.Minute);
                        }
                        break;

                    case 2:
                        CrestronConsole.PrintLine("Initializing program response for button {0}", args.Button.Number);
                        myEventGroup.ClearAllEvents();
                        break;

                    case 3:
                        CrestronConsole.PrintLine("Initializing program response for button {0}", args.Button.Number);
                        CrestronConsole.PrintLine("Event {0} is scheduled for {1}/{2}/{3} {4}:{5}",
                                                  myEvent.Name,
                                                  myEvent.DateAndTime.Month,
                                                  myEvent.DateAndTime.Day,
                                                  myEvent.DateAndTime.Year,
                                                  myEvent.DateAndTime.Hour,
                                                  myEvent.DateAndTime.Minute);
                        break;

                    case 4:
                        ComPorts[1].Send(String.Format("{0}{1}{2}{3}{4}",
                                                       Convert.ToChar(0x31),
                                                       Convert.ToChar(0x32),
                                                       Convert.ToChar(0x33),
                                                       Convert.ToChar(0x34),
                                                       Convert.ToChar(0x0D)));
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Exception occurred --> {0}", e.Message);
                ErrorLog.Notice(String.Format("Exception occurred --> {0}", e.Message));
            }
            finally { }
        }