Exemple #1
0
        void SetupCommands()
        {
            Command <Commands.ActivateDevice>(cmd => {
                Console.WriteLine($"{this.PersistenceId} -- COMMAND: ActivateDevice");
                var evt = new Events.DeviceActivated(cmd.IMEI, cmd.ICCID, cmd.EncryptionKey, cmd.EncryptionSalt);
                Persist(evt, e =>
                {
                    if (this.Entity == null)
                    {
                        this.Entity = new DeviceState();
                    }
                    this.Entity.Apply(e);
                    this.CheckForSnapshot();
                    Context.System.EventStream.Publish(e);
                });
            });
            Command <Commands.DeployDevice>(cmd =>
            {
                Console.WriteLine($"{this.PersistenceId} -- COMMAND: DeployDevice");
                var evt = new Events.DeviceDeployed(this.Entity.IMEI, cmd.DeviceDeploymentDate, cmd.ShipperId, cmd.Consignee, cmd.ShippingLine, cmd.VesselName, cmd.VoyageNumber, cmd.ContainerNumber, cmd.SecuritySealNumber, cmd.OriginPort, cmd.DestinationPort, cmd.EstimatedDeparture, cmd.EstimateArrival);
                Persist(evt, e =>
                {
                    this.Entity.Apply(e);
                    this.CheckForSnapshot();
                    Context.System.EventStream.Publish(e);
                });
            });
            Command <Commands.RetireDevice>(cmd =>
            {
                Console.WriteLine($"{this.PersistenceId} -- COMMAND: RetireDevice");
                var evt = new Events.DeviceDeactivated(this.Entity.IMEI, cmd.RetiredOnDate);
                Persist(evt, e =>
                {
                    this.Entity.Apply(e);
                    this.CheckForSnapshot();
                    Context.System.EventStream.Publish(e);
                });
            });
            Command <Commands.RecordMessage>(cmd => this.ParseDeviceMessage(cmd));
            Command <SaveSnapshotSuccess>(success => {
                // handle snapshot save success...
                // DeleteMessages(success.Metadata.SequenceNr);
                this.DeleteSnapshots(new SnapshotSelectionCriteria(success.Metadata.SequenceNr - 50));
                _eventsSinceLastSnapshot = 0;
            });

            Command <SaveSnapshotFailure>(failure => {
                // handle snapshot save failure...
            });
        }
Exemple #2
0
 public void Apply(Events.DeviceDeployed evt)
 {
     Status = DeviceStatus.Active;
     this.DeviceDeploymentDate = evt.DeviceDeploymentDate;
     this.ShipperId            = evt.ShipperId;
     this.Consignee            = evt.Consignee;
     this.ShippingLine         = evt.ShippingLine;
     this.VesselName           = evt.VesselName;
     this.VoyageNumber         = evt.VoyageNumber;
     this.ContainerNumber      = evt.ContainerNumber;
     this.SecuritySealNumber   = evt.SecuritySealNumber;
     this.OriginPort           = evt.OriginPort;
     this.DestinationPort      = evt.DestinationPort;
     this.EstimatedDeparture   = evt.EstimatedDeparture;
     this.EstimateArrival      = evt.EstimateArrival;
 }