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... }); }
public void Apply(Events.DeviceDeactivated evt) { this.RetiredDate = evt.RetiredOnDate; Status = DeviceStatus.Deactivated; }