Ejemplo n.º 1
0
        public Room(string uid, IEnumerable <string> neighbors, string lamp, IConcurrencyProvider concurrencyProvider, ILogger logger, IMessageBroker messageBroker,
                    AreaDescriptor areaDescriptor, MotionConfiguration motionConfiguration)
        {
            Uid                  = uid ?? throw new ArgumentNullException(nameof(uid));
            _neighbors           = neighbors ?? throw new ArgumentNullException(nameof(neighbors));
            _lamp                = lamp ?? throw new ArgumentNullException(nameof(lamp));
            _logger              = logger;
            _motionConfiguration = motionConfiguration;
            _concurrencyProvider = concurrencyProvider;
            _messageBroker       = messageBroker;
            _areaDescriptor      = areaDescriptor;

            if (areaDescriptor.WorkingTime == WorkingTime.DayLight)
            {
                _turnOnConditionsValidator.WithCondition(new IsDayCondition(_messageBroker));
            }
            else if (areaDescriptor.WorkingTime == WorkingTime.AfterDusk)
            {
                _turnOnConditionsValidator.WithCondition(new IsNightCondition(_messageBroker));
            }

            _turnOnConditionsValidator.WithCondition(new IsEnabledAutomationCondition(this));
            _turnOffConditionsValidator.WithCondition(new IsEnabledAutomationCondition(this));
            _turnOffConditionsValidator.WithCondition(new IsTurnOffAutomaionCondition(this));

            _TurnOffTimeOut = new Timeout(_areaDescriptor.TurnOffTimeout, _motionConfiguration.TurnOffPresenceFactor);
        }
Ejemplo n.º 2
0
        public RoomService(IEnumerable <Room> rooms, MotionConfiguration motionConfiguration)
        {
            _rooms = rooms.ToImmutableDictionary(k => k.Uid, v => v);

            var dic = new Dictionary <Room, IEnumerable <Room> >();

            foreach (var room in rooms)
            {
                dic.Add(room, room.Neighbors().Select(n => _rooms[n]));
            }

            _neighbors           = dic.ToImmutableDictionary();
            _motionConfiguration = motionConfiguration;
        }