Exemplo 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);
            }
        }