private void OnSpotCharterCreated(SpotCharterCreated @event)
 {
     this.Id = @event.AggregateId;
     this.CharterpartyDate = @event.CharterpartyDate;
     this.CharterpartyId   = @event.CounterpartyId;
     this.CharterpartyName = @event.CounterpartyCurrentName;
     this.VesselId         = @event.VesselId;
     this.VesselName       = @event.VesselCurrentName;
     this.MinimumQuantity  = @event.MinimumQuantity;
 }
        public SpotCharter(IEnumerable <IEvent <SpotCharterId> > events)
            : this()
        {
            SpotCharterCreated firstEvent = events.FirstOrDefault(e => e is SpotCharterCreated) as SpotCharterCreated;

            if (firstEvent == null)
            {
                throw new InvalidOperationException("Missing creation event");
            }

            this.Id = firstEvent.AggregateId;
            this.ReplayEvents(events);
        }
Exemple #3
0
        public void DispatchSpotCreated()
        {
            using (IEventDispatcher dispatcher = new RabbitMQEventDispatcher.RabbitMQEventDispatcher(
                       host: rabbitConfig.host,
                       exchangeName: rabbitConfig.exchange,
                       username: rabbitConfig.username,
                       password: rabbitConfig.password,
                       vhost: rabbitConfig.vhost,
                       port: rabbitConfig.port
                       ))
            {
                var spotCreated = new SpotCharterCreated(new SpotCharterId(Guid.NewGuid()), new BaseDomainObjects.Entities.Login("stefano"), DateTime.Now, new CounterpartyId(Guid.NewGuid()), "Counterparty", new VesselId(Guid.NewGuid()), "Vessel", new CargoQuantity("MT", 5000));
                var freight     = new FreightRateChanged(new SpotCharterId(Guid.NewGuid()), new BaseDomainObjects.Entities.Login("stefano"), 1, new SpotCharterDomain.ValueObjects.FreightRate(100000));

                BaseDomainObjects.IEvent <SpotCharterId> @event = spotCreated;

                var dispatchEvent = new DispatchEvent()
                {
                    EventName = @event.EventName,
                    Id        = @event.Id,
                    Source    = @event.Source,
                    Version   = @event.Version,
                    Timestamp = spotCreated.CharterpartyDate,
                    Payload   = JsonConvert.SerializeObject(spotCreated),
                };

                dispatcher.Publish(dispatchEvent);

                @event = freight;
                dispatcher.Publish(new DispatchEvent()
                {
                    EventName = @event.EventName,
                    Id        = @event.Id,
                    Source    = @event.Source,
                    Version   = @event.Version,
                    Timestamp = DateTime.Now,
                    Payload   = JsonConvert.SerializeObject(freight),
                });
            }
        }