Пример #1
0
        public HouseActor()
        {
            var configuration = new SensorsConfiguration();

            Receive <RegisterSensor>(msg =>
            {
                var child = msg.Type switch
                {
                    SensorType.AirQuality => Context.ActorOf(Props.Create(() => new AirQualitySensorActor())),
                    SensorType.CarbonMonoxide => Context.ActorOf(Props.Create(() => new CarbonMonoxideSensorActor())),
                    SensorType.Gas => Context.ActorOf(Props.Create(() => new GasSensorActor())),
                    SensorType.Flood => Context.ActorOf(Props.Create(() => new FloodSensorActor())),
                    SensorType.Door => Context.ActorOf(Props.Create(() => new DoorSensorActor())),
                    SensorType.Motion => Context.ActorOf(Props.Create(() => new MotionSensorActor())),
                    SensorType.Window => Context.ActorOf(Props.Create(() => new WindowSensorActor())),
                    _ => throw new ArgumentOutOfRangeException()
                };

                Context.System.Scheduler.ScheduleTellRepeatedly(TimeSpan.Zero,
                                                                configuration.GetTimeInterval(msg.Type),
                                                                child,
                                                                new ReadSensorValue(),
                                                                Context.Self);
            });

            Receive <CloseHouse>(msg =>
            {
                _state.CloseTheHouse();

                Context
                .GetOrCreate <CheckSensorValueActor>("checkTheSensorValue")
                .Forward(msg);
            });

            Receive <SensorValueRetrieved>(msg =>
            {
                Console.WriteLine(
                    $"Message of type {msg.GetType()} handled in {nameof(HouseActor)} actor named {Context.Self.Path}. Sensor Value: {msg.Value}, Sensor Type: {msg.GetType().Name}");

                Context
                .GetOrCreate <CheckSensorValueActor>("checkTheSensorValue")
                .Forward(msg);
            });

            Receive <RaiseAlarm>(msg =>
            {
                Context
                .GetOrCreate <SendNotificationActor>("notifier")
                .Forward(new SendNotification {
                    Type = NotificationType.Sms, Message = msg.Message
                });
            });
        }
Пример #2
0
        public SensorsConfigurationViewModel()
        {
            SensorsConfiguration = SensorsConfiguration.Load();

            Sensors = new ObservableCollection <SensorConfiguration>(SensorsConfiguration.Sensors);

            AddIotSensor       = ReactiveCommand.Create(AddNewIotSensor);
            AddWeatherSensor   = ReactiveCommand.Create(AddNewWeatherSensor);
            ApplyConfiguration = ReactiveCommand.Create(ApplyNewConfiguration);

            RemoveSensor = ReactiveCommand.Create <string>(ApplyRemoveSensor);
        }
Пример #3
0
        private void ApplyNewConfiguration()
        {
            foreach (var sensor in Sensors)
            {
                if (sensor.SensorId == -1)
                {
                    sensor.SensorId = SensorsStorage.GetNewSensorId(sensor.Name);
                }
            }

            SensorsConfiguration.Sensors = new List <SensorConfiguration>(Sensors);

            SensorsConfiguration.Save();

            SensorsManager.ReloadConfiguration();
        }
Пример #4
0
        static public void ReloadConfiguration()
        {
            Sensors.Clear();
            SensorsConfiguration = SensorsConfiguration.Load();

            foreach (var sensorConfiguration in SensorsConfiguration.Sensors)
            {
                switch (sensorConfiguration.SensorType)
                {
                case Configuration.SensorType.GrovePi:

                    var grovePiSensorConfiguration = sensorConfiguration as GrovePiSensorConfiguration;

                    Sensors.Add(GrovePiSensorBuilder.CreateSensor(
                                    grovePiSensorConfiguration.GroveSensorType,
                                    grovePiSensorConfiguration.GrovePort,
                                    grovePiSensorConfiguration.Name,
                                    grovePiSensorConfiguration.SensorId,
                                    grovePiSensorConfiguration.RgbDisplay
                                    ));
                    break;

                case Configuration.SensorType.OpenWeatherMap:

                    var openWeatherMapSensorConfiguration = sensorConfiguration as OpenWeatherMapSensorConfiguration;

                    Sensors.Add(WeatherSensorBuilder.GetSensor(
                                    openWeatherMapSensorConfiguration.SensorWeatherType,
                                    openWeatherMapSensorConfiguration.Name,
                                    openWeatherMapSensorConfiguration.SensorId,
                                    openWeatherMapSensorConfiguration.RgbDisplay
                                    ));
                    break;

                default:
                    throw new Exception("Unsupported SensorType in SensorsManager");
                }
            }
        }