Ejemplo n.º 1
0
        /// <summary>
        /// Sets up device based on config values
        /// </summary>
        void SetUpDevice()
        {
            Room = DeviceManager.GetDeviceForKey(PropertiesConfig.RoomKey) as EssentialsRoomBase;

            if (Room != null)
            {
                try
                {
                    FeatureEnabledTime = DateTime.Parse(PropertiesConfig.OccupancyStartTime);

                    if (FeatureEnabledTime != null)
                    {
                        Debug.Console(1, this, "Enabled Time: {0}", FeatureEnabledTime.ToString());
                    }
                    else
                    {
                        Debug.Console(1, this, "Unable to parse {0} to DateTime", PropertiesConfig.OccupancyStartTime);
                    }
                }
                catch (Exception e)
                {
                    Debug.Console(1, this, "Unable to parse OccupancyStartTime property: {0} \n Error: {1}", PropertiesConfig.OccupancyStartTime, e);
                }

                try
                {
                    FeatureDisabledTime = DateTime.Parse(PropertiesConfig.OccupancyEndTime);

                    if (FeatureDisabledTime != null)
                    {
                        Debug.Console(1, this, "Disabled Time: {0}", FeatureDisabledTime.ToString());
                    }
                    else
                    {
                        Debug.Console(1, this, "Unable to parse {0} to DateTime", PropertiesConfig.OccupancyEndTime);
                    }
                }
                catch (Exception e)
                {
                    Debug.Console(1, this, "Unable to parse a DateTime config value \n Error: {1}", e);
                }

                if (!PropertiesConfig.EnableRoomOnWhenOccupied)
                {
                    FeatureEventGroup.ClearAllEvents();
                }
                else
                {
                    AddEnableEventToGroup();

                    AddDisableEventToGroup();

                    FeatureEventGroup.UserGroupCallBack += new ScheduledEventGroup.UserEventGroupCallBack(FeatureEventGroup_UserGroupCallBack);

                    FeatureEventGroup.EnableAllEvents();
                }

                FeatureEnabled = CheckIfFeatureShouldBeEnabled();
            }
            else
            {
                Debug.Console(1, this, "Unable to get room from Device Manager with key: {0}", PropertiesConfig.RoomKey);
            }
        }
Ejemplo n.º 2
0
        void CreateEvent(ScheduledEvent schEvent, string name)
        {
            Debug.Console(1, this, "Adding Event: '{0}'", name);
            // Create the event
            if (schEvent == null)
            {
                schEvent = new ScheduledEvent(name, FeatureEventGroup);
            }

            // Set up its initial properties

            if (!schEvent.Acknowledgeable)
            {
                schEvent.Acknowledgeable = true;
            }

            if (!schEvent.Persistent)
            {
                schEvent.Persistent = true;
            }

            schEvent.DateAndTime.SetFirstDayOfWeek(ScheduledEventCommon.eFirstDayOfWeek.Sunday);

            // Set config driven properties

            if (schEvent.Name == FeatureEnableEventName)
            {
                schEvent.Description = "Enables the RoomOnToDefaultSourceWhenOccupiedFeature";

                var eventRecurrennce = CalculateDaysOfWeekRecurrence();

                var eventTime = new DateTime();

                // Check to make sure the date for this event is in the future
                if (DateTime.Now.CompareTo(FeatureEnabledTime) > 0)
                {
                    eventTime = FeatureEnabledTime.AddDays(1);
                }
                else
                {
                    eventTime = FeatureEnabledTime;
                }

                Debug.Console(1, this, "eventTime (before recurrence check): {0}", eventTime);

                // Check day of week against recurrence days and move date ahead as necessary to avoid throwing an exception by trying to set the event
                // start date on a day of the week that doesn't match teh recurrence values
                while (!SchedulerUtilities.CheckIfDayOfWeekMatchesRecurrenceDays(eventTime, eventRecurrennce))
                {
                    eventTime = eventTime.AddDays(1);
                    Debug.Console(1, this, "eventTime does not fall on a recurrence weekday.  eventTime: {0}", eventTime);
                }

                schEvent.DateAndTime.SetAbsoluteEventTime(eventTime);

                Debug.Console(1, this, "Event '{0}' Absolute time set to {1}", schEvent.Name, schEvent.DateAndTime.ToString());

                CalculateAndSetAcknowledgeExpirationTimeout(schEvent, FeatureEnabledTime, FeatureDisabledTime);

                schEvent.Recurrence.Weekly(eventRecurrennce);
            }
            else if (schEvent.Name == FeatureDisableEventName)
            {
                schEvent.Description = "Disables the RoomOnToDefaultSourceWhenOccupiedFeature";

                // Check to make sure the date for this event is in the future
                if (DateTime.Now.CompareTo(FeatureDisabledTime) > 0)
                {
                    schEvent.DateAndTime.SetAbsoluteEventTime(FeatureDisabledTime.AddDays(1));
                }
                else
                {
                    schEvent.DateAndTime.SetAbsoluteEventTime(FeatureDisabledTime);
                }

                Debug.Console(1, this, "Event '{0}' Absolute time set to {1}", schEvent.Name, schEvent.DateAndTime.ToString());

                CalculateAndSetAcknowledgeExpirationTimeout(schEvent, FeatureDisabledTime, FeatureEnabledTime);

                schEvent.Recurrence.Daily();
            }
        }