예제 #1
0
        public static bool InstallSepticTankSensors(this IRepository <IDbProperties> repository, SepticTankState state, out SepticTankState septicTankState)
        {
            var sensors      = state.Sensors;
            var dbProperties = new List <IDbProperties>();

            foreach (var sensor in sensors.ToList())
            {
                var dataTypes = new List <IDataTypes>
                {
                    new DataTypes("@septictank", SqlDbType.NVarChar, 50, state.SepticTankId, ParameterDirection.Input, false, false, ""),
                    new DataTypes("@tag", SqlDbType.NVarChar, 50, sensor.Tag, ParameterDirection.Input, false, false, ""),
                    new DataTypes("@role", SqlDbType.NVarChar, 50, sensor.Role, ParameterDirection.Input, false, false, ""),
                    new DataTypes("@sensorid", SqlDbType.UniqueIdentifier, 0, string.Empty, ParameterDirection.Output, false, false, "@sensorid")
                };
                var repos = new DbProperties("InstallSepticSensor", dataTypes, string.Empty, true, "@sensorid", sensor.Tag);
                dbProperties.Add(repos);
            }
            var x = repository.Update(dbProperties);

            if (x > 0)
            {
                var sensorsSpec = new List <SensorSpec>();
                foreach (var sensor in sensors.ToList())
                {
                    var outputs = repository.OutPuts;
                    sensor.SensorId = outputs.ToList().FirstOrDefault(y => y.Identifier == sensor.Tag).Value;
                    sensorsSpec.Add(sensor);
                }
                septicTankState = new SepticTankState(state.SepticTankId, state.Height, state.AlertHeight, sensorsSpec);
                return(true);
            }
            septicTankState = state;
            return(false);
        }
예제 #2
0
        protected override void OnPersist(IEvent persistedEvent)
        {
            switch (persistedEvent)
            {
            case ConstructedHostel hostel:
            {
                var construct = hostel.Construction;
                foreach (var floor in construct.Floors)
                {
                    if (Context.Child(floor.Tag).IsNobody())
                    {
                        floor.HostelId = hostel.Construction.Detail.HostelId;
                        var createFloor = new CreateFloor(floor);
                        Self.Tell(createFloor);
                        Context.System.Log.Info($"FloorActor", $"Creating Floor - {floor.Tag}");
                    }
                }
                if (Context.Child(construct.SepticTank.Tag).IsNobody())
                {
                    var septicSpec = construct.SepticTank;
                    septicSpec.HostelId = hostel.Construction.Detail.HostelId;
                    var septic = new CreateSepticTank(septicSpec);
                    Self.Tell(septic);
                }
                if (Context.Child(construct.Reservoir.Tag).IsNobody())
                {
                    var waterSpec = construct.Reservoir;
                    waterSpec.HostelId = hostel.Construction.Detail.HostelId;;
                    var water = new CreateWaterReservoir(waterSpec);
                    Self.Tell(water);
                }
            }
            break;

            case CreatedFloor createdFloor:
            {
                var floor = createdFloor.Floor;
                floor.HostelId = State.ConstructionRecord.Detail.HostelId;
                var floorState = new FloorState(floor);
                var floorActor = Context.ActorOf(FloorActor.Prop(new FloorHandler(), floorState, floor.Tag, _connectionString), floor.Tag);
                floorActor.Tell(new LayoutFloor());
            }
            break;

            case CreatedSepticTank createdSepticTank:
            {
                var septic = createdSepticTank.SepticTankSpec;
                septic.HostelId = State.ConstructionRecord.Detail.HostelId;
                var septicState = new SepticTankState(septic.SepticTankId, septic.Height, septic.AlertHeight, septic.Sensors);
                var septicActor = Context.ActorOf(SepticTankActor.Prop(new SepticTankHandler(), septicState, septic.Tag, _connectionString), septic.Tag);
                septicActor.Tell(new InstallSensor());
            }
            break;

            case CreatedWaterReservoir createdWater:
            {
                var water = createdWater.ReservoirSpec;
                water.HostelId = State.ConstructionRecord.Detail.HostelId;
                var reservoirState = new WaterReservoirState(water.ReservoirId, water.Height, water.AlertHeight, water.Sensors);
                var waterActor     = Context.ActorOf(WaterReservoirActor.Prop(new WaterReservoirHandler(), reservoirState, water.Tag, _connectionString), water.Tag);
                waterActor.Tell(new InstallSensor());
            }
            break;
            }
            base.OnPersist(persistedEvent);
        }