示例#1
0
        public ScenarioCoordinator(IScenarioEngine engine)
        {
            this.engine = engine;

            engine.SetDevice  += Engine_SetDevice;
            engine.SetGateway += Engine_SetGateway;

            Receive <EvalutateScenari>(msg => {
                Console.WriteLine("Evalutate Scenario");
                //Console.WriteLine(JsonSeriliaze.Serialize(msg));
                engine.Evalutate(msg.Status);
            });
        }
示例#2
0
        public DeviceManagerCoordinator(string id, string ClientMQTTId, IScenarioEngine engine)
        {
            _id            = id;
            senderMQTT     = Context.ActorOf(ClientMQTT.Props(ClientMQTTId), "senderMQTT");
            scenariManager = Context.ActorOf(ScenarioCoordinator.Props(engine), "scenari");

            gateways = new Dictionary <string, IActorRef>();

            Receive <GatewayPhysicalCreated>(msg =>
            {
                gateways.TryGetValue(msg.Source, out var gateway);
                if (gateway == null)
                {
                    gateway = Context.ActorOf(DeviceManager.Props(msg.Source));
                    gateways.Add(msg.Source, gateway);
                    Context.TellOrc(new GatewayStatus(msg.Source));
                }
            });

            Receive <DevicePhysicalCreated>(msg =>
                                            Forward(msg.Source.Gateway, msg));

            Receive <GatewayPhysicalDroped>(msg =>
            {
                gateways.Remove(msg.Source);
            });

            Receive <DevicePhysicalDroped>(msg =>
                                           Forward(msg.Source.Gateway, msg));

            Receive <GatewayPhysicalSended>(msg =>
                                            Forward(msg.Source, msg));

            Receive <DevicePhysicalSended>(msg =>
                                           Forward(msg.Source.Gateway, msg));

            Receive <GatewayPhysicalStarted>(msg =>
                                             Forward(msg.Source, msg));

            Receive <DevicePhysicalStarted>(msg =>
                                            Forward(msg.Source.Gateway, msg));

            Receive <GatewayPhysicalDisconnected>(msg =>
                                                  Forward(msg.Source, msg));

            Receive <DevicePhysicalDisconnected>(msg =>
                                                 Forward(msg.Source.Gateway, msg));

            Receive <GatewayPhysicalSet>(msg =>
                                         Forward(msg.Source, msg));

            Receive <DevicePhysicalSet>(msg =>
                                        Forward(msg.Source.Gateway, msg));

            Receive <GatewayPhysicalStatus>(msg =>
                                            senderMQTT.Tell(new MsgMQTTSend($"{msg.Source}/status", "")));

            Receive <DevicePhysicalStatus>(msg =>
                                           senderMQTT.Tell(new MsgMQTTSend($"{msg.Source.Gateway}/devices/{msg.Source.Source}/status", "")));

            Receive <GatewayPhysicalSetMsg>(msg =>
                                            senderMQTT.Tell(new MsgMQTTSend($"{msg.Source}/set", msg.Value)));

            Receive <DevicePhysicalSetMsg>(msg =>
                                           senderMQTT.Tell(new MsgMQTTSend($"{msg.Source.Gateway}/devices/{msg.Source.Source}/set", msg.Value)));

            Receive <EvalutatePhysical>(msg => {
                var gatewaysStatus = new List <GatewayPhysical>();
                foreach (var gateway in gateways)
                {
                    gatewaysStatus.Add(gateway.Value.Ask <GatewayPhysical>(new GatewayGetPhysical()).Result);
                }
                scenariManager.Tell(new EvalutateScenari(new PhysicalStatus(gatewaysStatus.ToArray())));
            });
        }
示例#3
0
 public static Props Props(string id, string ClientMQTTId, IScenarioEngine engine)
 {
     return(Akka.Actor.Props.Create(() => new DeviceManagerCoordinator(id, ClientMQTTId, engine)));
 }
示例#4
0
 public static Props Props(IScenarioEngine engine)
 {
     return(Akka.Actor.Props.Create(() => new ScenarioCoordinator(engine)));
 }
示例#5
0
        public IoT(DashBoard dashBoard, ServerMQTT mqtt, string mqttClientId, IRepository repository, IScenarioEngine engine)
        {
            this.dashBoard = dashBoard;
            system         = ActorSystem.Create("iot");
            orchastraion   = system.ActorOf(Orchestration.Props(this.dashBoard, mqttClientId, repository, engine), "orch");

            //AddGateway(new GatewayDashBoard("1"));
            //AddDevice(new GatewayDashBoard("1"), new DeviceDashBoard("2"));

            orchastraion.Tell(new SystemStart());

            this.mqtt        = mqtt;
            mqtt.ReceiveMsg += Mqtt_ReceiveMsg;
        }
示例#6
0
 public static Props Props(DashBoard dashBoard, string MQTTClientId, IRepository repository, IScenarioEngine engine)
 {
     return(Akka.Actor.Props.Create(() => new Orchestration(dashBoard, MQTTClientId, repository, engine)));
 }
示例#7
0
        public Orchestration(DashBoard dashBoard, string MQTTClientId, IRepository repository, IScenarioEngine engine)
        {
            deviceManager     = Context.ActorOf(DeviceManagerCoordinator.Props("patano", MQTTClientId, engine), "physicaldevice");
            dashboardManager  = Context.ActorOf(DashdoardCoordinator.Props("dashboard", dashBoard), "dashboard");
            repositoryManager = Context.ActorOf(RepositoryCoordinator.Props(repository), "repo");

            Receive <GatewayCreated>(msg =>
            {
                deviceManager.Tell(msg.GatewayPhysicalCreated);
                dashboardManager.Tell(msg.GatewayDashBoardCreated);
                repositoryManager.Tell(msg.GatewayRepositoryCreated);
            });

            Receive <DeviceCreated>(msg =>
            {
                deviceManager.Tell(msg.DevicePhysicalCreated);
                dashboardManager.Tell(msg.DeviceDashBoardCreated);
                repositoryManager.Tell(msg.DeviceRepositoryCreated);
            });

            Receive <GatewayDroped>(msg =>
            {
                deviceManager.Tell(msg.GatewayPhysicalDroped);
                dashboardManager.Tell(msg.GatewayDashBoardDroped);
                repositoryManager.Tell(msg.GatewayRepositoryDroped);
            });

            Receive <DeviceDroped>(msg =>
            {
                deviceManager.Tell(msg.DevicePhysicalDroped);
                dashboardManager.Tell(msg.DeviceDashBoardDroped);
                repositoryManager.Tell(msg.DeviceRepositoryDroped);
            });

            Receive <GatewaySended>(msg =>
            {
                deviceManager.Tell(msg.GatewayPhysicalSended);
                dashboardManager.Tell(msg.GatewayDashBoardSended);
                repositoryManager.Tell(msg.GatewayRepositorySended);
            });

            Receive <DeviceSended>(msg =>
            {
                deviceManager.Tell(msg.DevicePhysicalSended);
                dashboardManager.Tell(msg.DeviceDashBoardSended);
                repositoryManager.Tell(msg.DeviceRepositorySended);
            });

            Receive <GatewayStarted>(msg =>
            {
                deviceManager.Tell(msg.GatewayPhysicalStarted);
                dashboardManager.Tell(msg.GatewayDashBoardStarted);
                repositoryManager.Tell(msg.GatewayRepositoryStarted);
            });

            Receive <DeviceStarted>(msg =>
            {
                deviceManager.Tell(msg.DevicePhysicalStarted);
                dashboardManager.Tell(msg.DeviceDashBoardStarted);
                repositoryManager.Tell(msg.DeviceRepositoryStarted);
            });

            Receive <GatewayDisconnected>(msg =>
            {
                deviceManager.Tell(msg.GatewayPhysicalDisconnected);
                dashboardManager.Tell(msg.GatewayDashBoardDisconnected);
                repositoryManager.Tell(msg.GatewayRepositoryDisconnected);
            });

            Receive <DeviceDisconnected>(msg =>
            {
                deviceManager.Tell(msg.DeviceDashBoardDisconnected);
                dashboardManager.Tell(msg.DeviceDashBoardDisconnected);
                repositoryManager.Tell(msg.DeviceRepositoryDisconnected);
            });

            Receive <GatewaySet>(msg =>
            {
                deviceManager.Tell(msg.GatewayPhysicalSet);
                dashboardManager.Tell(msg.GatewayDashBoardSet);
                repositoryManager.Tell(msg.GatewayRepositorySet);
            });

            Receive <DeviceSet>(msg =>
            {
                deviceManager.Tell(msg.DevicePhysicalSet);
                dashboardManager.Tell(msg.DeviceDashBoardSet);
                repositoryManager.Tell(msg.DeviceRepositorySet);
            });

            Receive <GatewayUpdate>(msg =>
            {
                dashboardManager.Tell(msg.GatewayDashBoardUpdate);
                repositoryManager.Tell(msg.GatewayRepositoryUpdate);
            });

            Receive <DeviceUpdate>(msg =>
            {
                dashboardManager.Tell(msg.DeviceDashBoardUpdate);
                repositoryManager.Tell(msg.DeviceRepositoryUpdate);
            });

            Receive <GatewayStatus>(msg =>
            {
                deviceManager.Tell(msg.GatewayPhysicalStatus);
            });

            Receive <DeviceStatus>(msg =>
            {
                deviceManager.Tell(msg.DevicePhysicalStatus);
            });

            Receive <GetGatewaysBoard>(msg =>
            {
                var result = dashboardManager.Ask <List <GatewayDashBoard> >(msg).Result;
                Sender.Tell(result);
            });

            Receive <StatusChanged>(msg => { dashBoard.HasChange(); });

            Receive <SystemStart>(msg => InitSystem());

            Receive <Evalutate>(msg => deviceManager.Tell(msg.EvalutatePhysical));

            Receive <PhysicalSetEnd>(msg
                                     => Self.Tell(new Evalutate()));
        }