コード例 #1
0
ファイル: AggregateRoot.cs プロジェクト: rodolfograve/ncqrs
 protected override void OnEventApplied(ISourcedEvent appliedEvent)
 {
     if(EventApplied != null)
     {
         EventApplied(this, new EventAppliedArgs(appliedEvent));
     }
 }
コード例 #2
0
        public byte[] SerializeEvent(ISourcedEvent e)
        {
            byte[] content;
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(e, e.GetType(), ms);
                content = ms.ToArray();
            }

            byte[] messageContractBuffer;
            using (var ms = new MemoryStream())
            {
                var name = e.GetType().GetContractName();
                var messageContract = new MessageContract(name, content.Length, 0, e.EventIdentifier, e.EventSequence);
                serializer.Serialize(messageContract, typeof(MessageContract), ms);
                messageContractBuffer = ms.ToArray();
            }

            using (var ms = new MemoryStream())
            {
                var headerContract = new MessageHeaderContract(messageContractBuffer.Length);
                headerContract.WriteHeader(ms);
                ms.Write(messageContractBuffer, 0, messageContractBuffer.Length);
                ms.Write(content, 0, content.Length);
                return ms.ToArray();
            }
        }
コード例 #3
0
        public void Retrieving_all_events_should_return_the_same_as_added()
        {
            var targetStore = new RavenDBEventStore(_documentStore);
            var id = Guid.NewGuid();

            int sequenceCounter = 0;

            var events = new ISourcedEvent[]
                             {
                                 new CustomerCreatedEvent(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow, "Foo",
                                                          35),
                                 new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                                         "Name" + sequenceCounter),
                                 new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                                         "Name" + sequenceCounter),
                                 new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                                         "Name" + sequenceCounter)
                             };

            var eventSource = MockRepository.GenerateMock<IEventSource>();
            eventSource.Stub(e => e.Id).Return(id);
            eventSource.Stub(e => e.InitialVersion).Return(0);
            eventSource.Stub(e => e.Version).Return(events.Length);
            eventSource.Stub(e => e.GetUncommittedEvents()).Return(events);

            targetStore.Save(eventSource);

            var result = targetStore.GetAllEvents(id);
            result.Count().Should().Be(events.Length);
            result.First().EventIdentifier.Should().Be(events.First().EventIdentifier);
            Assert.IsTrue(result.SequenceEqual(events));
        }
コード例 #4
0
        public void Saving_event_source_should_succeed()
        {
            var targetStore = new RavenDBEventStore(_documentStore);
            var id = Guid.NewGuid();

            int sequenceCounter = 0;

            var events = new ISourcedEvent[]
                             {
                                 new CustomerCreatedEvent(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow, "Foo",
                                                          35),
                                 new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                                         "Name" + sequenceCounter),
                                 new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                                         "Name" + sequenceCounter),
                                 new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                                         "Name" + sequenceCounter)
                             };

            var eventSource = MockRepository.GenerateMock<IEventSource>();
            eventSource.Stub(e => e.Id).Return(id);
            eventSource.Stub(e => e.InitialVersion).Return(0);
            eventSource.Stub(e => e.Version).Return(events.Length);
            eventSource.Stub(e => e.GetUncommittedEvents()).Return(events);

            targetStore.Save(eventSource);
        }
コード例 #5
0
 public BusinessBalanceCreatedProjectedNotification(Guid balanceId, ISourcedEvent o)
 {
     BalanceId   = balanceId;
     SourceId    = o.SourceId;
     SagaId      = o.SagaId;
     CreatedTime = o.CreatedTime;
 }
コード例 #6
0
        public byte[] SerializeEvent(ISourcedEvent e)
        {
            byte[] content;
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(e, e.GetType(), ms);
                content = ms.ToArray();
            }

            byte[] messageContractBuffer;
            using (var ms = new MemoryStream())
            {
                var name            = e.GetType().GetContractName();
                var messageContract = new MessageContract(name, content.Length, 0, e.EventIdentifier, e.EventSequence);
                serializer.Serialize(messageContract, typeof(MessageContract), ms);
                messageContractBuffer = ms.ToArray();
            }

            using (var ms = new MemoryStream())
            {
                var headerContract = new MessageHeaderContract(messageContractBuffer.Length);
                headerContract.WriteHeader(ms);
                ms.Write(messageContractBuffer, 0, messageContractBuffer.Length);
                ms.Write(content, 0, content.Length);
                return(ms.ToArray());
            }
        }
コード例 #7
0
        private void SaveEvent(ISourcedEvent evnt, Guid eventSourceId, SQLiteTransaction transaction)
        {
            if (evnt == null || transaction == null)
            {
                throw new ArgumentNullException();
            }
            using (var dataStream = new MemoryStream())
            {
                var bag = _converter.Convert(evnt);

                var formatter = new BinaryFormatter();
                formatter.Serialize(dataStream, bag);
                var data = dataStream.ToArray();

                using (var cmd = new SQLiteCommand(Query.InsertNewEventQuery, transaction.Connection))
                {
                    cmd.SetTransaction(transaction)
                    .AddParam("Id", eventSourceId)
                    .AddParam("Name", evnt.GetType().FullName)
                    .AddParam("Sequence", evnt.EventSequence)
                    .AddParam("Timestamp", evnt.EventTimeStamp.Ticks)
                    .AddParam("Data", data);
                    cmd.ExecuteNonQuery();
                }
            }
        }
コード例 #8
0
 protected override void OnEventApplied(ISourcedEvent appliedEvent)
 {
     if (EventApplied != null)
     {
         EventApplied(this, new EventAppliedArgs(appliedEvent));
     }
 }
コード例 #9
0
ファイル: EventSource.cs プロジェクト: mojamcpds/ncqrs
        internal protected void ApplyEvent(ISourcedEvent evnt)
        {
            _uncommittedEvents.Append(evnt);

            HandleEvent(evnt);

            OnEventApplied(evnt);
        }
コード例 #10
0
ファイル: AggregateRoot.cs プロジェクト: kajaljatakia/ncqrs
        protected override void OnEventApplied(ISourcedEvent appliedEvent)
        {
            var callbacks = _eventAppliedCallbacks;

            foreach(var callback in callbacks)
            {
                callback(this, appliedEvent);
            }
        }
コード例 #11
0
ファイル: SourcedEventEntity.cs プロジェクト: Andrea/ncqrs
        public static SourcedEventEntity FromEventSource(ISourcedEvent evnt)
        {
            Contract.Requires<ArgumentNullException>(evnt != null, "The evnt cannot be null.");

            return new SourcedEventEntity
            {
                RowKey = evnt.EventIdentifier.ToString(), PartitionKey = evnt.EventSourceId.ToString(), Sequence = evnt.EventSequence
            };
        }
コード例 #12
0
        protected override void OnEventApplied(ISourcedEvent appliedEvent)
        {
            var callbacks = _eventAppliedCallbacks;

            foreach (var callback in callbacks)
            {
                callback(this, appliedEvent);
            }
        }
コード例 #13
0
        //TODO: add custom saga id mapping
        protected virtual Guid GetSagaId(TMessage msg)
        {
            ISourcedEvent e = msg as ISourcedEvent;

            if (e != null)
            {
                return(e.SagaId);
            }
            return(Guid.Empty);
        }
 public void Invoke(object record, ISourcedEvent @event)
 {
     var projectionType = typeof(IProjection<,>).MakeGenericType(record.GetType(), @event.GetType());
     var projection = _container.Resolve(projectionType);
     if (projection != null)
     {
         var method = projectionType.GetMethod("Project", new[] { record.GetType(), @event.GetType() });
         method?.Invoke(projection, new [] { record, @event });
     }
 }
コード例 #15
0
        Boolean ISourcedEventHandler.HandleEvent(ISourcedEvent evnt)
        {
            Boolean handled = false;

            if (evnt is TEvent)
            {
                handled |= HandleEvent((TEvent)evnt);
            }

            return(handled);
        }
コード例 #16
0
 public bool HandleEvent(ISourcedEvent sourcedEvent)
 {
     var sourcedEntityEvent = sourcedEvent as SourcedEntityEvent;
     if (sourcedEntityEvent == null)
     {
         return false;
     }
     if (sourcedEntityEvent.EntityId != _entityId)
     {
         return false;
     }
     return _wrappedHandler.HandleEvent(sourcedEvent);
 }
コード例 #17
0
        public bool HandleEvent(ISourcedEvent sourcedEvent)
        {
            var sourcedEntityEvent = sourcedEvent as SourcedEntityEvent;

            if (sourcedEntityEvent == null)
            {
                return(false);
            }
            if (sourcedEntityEvent.EntityId != _entityId)
            {
                return(false);
            }
            return(_wrappedHandler.HandleEvent(sourcedEvent));
        }
コード例 #18
0
        /// <summary>
        ///   Handles the event.
        /// </summary>
        /// <param name = "evnttData">The event data to handle.
        ///   <remarks>
        ///     This value should not be <c>null</c>.
        ///   </remarks>
        /// </param>
        /// <returns>
        ///   <c>true</c> when the event was handled; otherwise, <c>false</c>.
        ///   <remarks>
        ///     <c>false</c> does not mean that the handling failed, but that the
        ///     handler was not interested in handling this event.
        ///   </remarks>
        /// </returns>
        public bool HandleEvent(ISourcedEvent evnt)
        {
            Contract.Requires <ArgumentNullException>(evnt != null, "The Event cannot be null.");

            var handled = false;

            if (ShouldHandleThisEventData(evnt))
            {
                _handler(evnt);
                handled = true;
            }

            return(handled);
        }
コード例 #19
0
        /// <summary>
        ///   Handles the event.
        /// </summary>
        /// <param name = "evnttData">The event data to handle.
        ///   <remarks>
        ///     This value should not be <c>null</c>.
        ///   </remarks>
        /// </param>
        /// <returns>
        ///   <c>true</c> when the event was handled; otherwise, <c>false</c>.
        ///   <remarks>
        ///     <c>false</c> does not mean that the handling failed, but that the
        ///     handler was not interested in handling this event.
        ///   </remarks>
        /// </returns>
        public bool HandleEvent(ISourcedEvent evnt)
        {
            Contract.Requires<ArgumentNullException>(evnt != null, "The Event cannot be null.");

            var handled = false;

            if (ShouldHandleThisEventData(evnt))
            {
                _handler(evnt);
                handled = true;
            }

            return handled;
        }
コード例 #20
0
        private static void SetEntityIdIfEntityEvent(StoredEvent <JObject> obj, ISourcedEvent theEvent)
        {
            var entityEvent = theEvent as ISourcedEntityEvent;

            if (entityEvent != null)
            {
                var eventAllowingSettingOfEntityId = entityEvent as IAllowSettingEntityId;
                if (eventAllowingSettingOfEntityId != null)
                {
                    var entityId = new Guid((string)obj.Data["EntityId"]);
                    eventAllowingSettingOfEntityId.SetEntityId(entityId);
                }
            }
        }
コード例 #21
0
ファイル: EventSource.cs プロジェクト: mojamcpds/ncqrs
        private void ValidateHistoricalEvent(ISourcedEvent evnt)
        {
            if (evnt.EventSourceId != EventSourceId)
            {
                var message = String.Format("Cannot apply historical event from other event source.");
                throw new InvalidOperationException(message);
            }

            if (evnt.EventSequence != InitialVersion + 1)
            {
                var message = String.Format("Cannot apply event with sequence {0}. Since the initial version of the " +
                                            "aggregate root is {1}. Only an event with sequence number {2} can be applied.",
                                            evnt.EventSequence, InitialVersion, InitialVersion + 1);
                throw new InvalidOperationException(message);
            }
        }
コード例 #22
0
ファイル: EventSource.cs プロジェクト: mojamcpds/ncqrs
        protected virtual void HandleEvent(ISourcedEvent evnt)
        {
            Contract.Requires <ArgumentNullException>(evnt != null, "The Event cannot be null.");
            Boolean handled = false;

            // Get a copy of the handlers because an event
            // handler can register a new handler. This will
            // cause the _eventHandlers list to be modified.
            // And modification while iterating it not allowed.
            var handlers = new List <ISourcedEventHandler>(_eventHandlers);

            foreach (var handler in handlers)
            {
                handled |= handler.HandleEvent(evnt);
            }

            if (!handled)
            {
                throw new EventNotHandledException(evnt);
            }
        }
コード例 #23
0
        /// <summary>
        /// Saves the event to the data store.
        /// </summary>
        /// <param name="evnt">The event to save.</param>
        /// <param name="eventSourceId">The id of the event source that owns the event.</param>
        /// <param name="transaction">The transaction.</param>
        private void SaveEvent(ISourcedEvent evnt, SqlTransaction transaction)
        {
            Contract.Requires <ArgumentNullException>(evnt != null, "The argument evnt could not be null.");
            Contract.Requires <ArgumentNullException>(transaction != null, "The argument transaction could not be null.");

            var document = _formatter.Serialize(evnt);
            var raw      = _translator.TranslateToRaw(document);

            using (var command = new SqlCommand(Queries.InsertNewEventQuery, transaction.Connection))
            {
                command.Transaction = transaction;
                command.Parameters.AddWithValue("EventId", raw.EventIdentifier);
                command.Parameters.AddWithValue("TimeStamp", raw.EventTimeStamp);
                command.Parameters.AddWithValue("EventSourceId", raw.EventSourceId);
                command.Parameters.AddWithValue("Name", raw.EventName);
                command.Parameters.AddWithValue("Version", raw.EventVersion.ToString());
                command.Parameters.AddWithValue("Sequence", raw.EventSequence);
                command.Parameters.AddWithValue("Data", raw.Data);
                command.ExecuteNonQuery();
            }
        }
コード例 #24
0
        public StoredEvent <JObject> Serialize(ISourcedEvent theEvent)
        {
            var eventName = _typeResolver.EventNameFor(theEvent.GetType());
            var data      = JObject.FromObject(theEvent, _serializer);

            StoredEvent <JObject> obj = new StoredEvent <JObject>(
                theEvent.EventIdentifier,
                theEvent.EventTimeStamp,
                eventName,
                theEvent.EventVersion,
                theEvent.EventSourceId,
                theEvent.EventSequence,
                data);

            data.Remove("EventIdentifier");
            data.Remove("EventTimeStamp");
            data.Remove("EventName");
            data.Remove("EventVersion");
            data.Remove("EventSourceId");
            data.Remove("EventSequence");

            return(obj);
        }
コード例 #25
0
 private void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, ISourcedEvent evnt)
 {
     RegisterDirtyInstance(aggregateRoot);
 }
コード例 #26
0
ファイル: MsSqlServerEventStore.cs プロジェクト: HAXEN/ncqrs
        /// <summary>
        /// Saves the event to the data store.
        /// </summary>
        /// <param name="evnt">The event to save.</param>
        /// <param name="eventSourceId">The id of the event source that owns the event.</param>
        /// <param name="transaction">The transaction.</param>
        private void SaveEvent(ISourcedEvent evnt, SqlTransaction transaction)
        {
            Contract.Requires<ArgumentNullException>(evnt != null, "The argument evnt could not be null.");
            Contract.Requires<ArgumentNullException>(transaction != null, "The argument transaction could not be null.");

            var document = _formatter.Serialize(evnt);
            var raw = _translator.TranslateToRaw(document);

            using (var command = new SqlCommand(Queries.InsertNewEventQuery, transaction.Connection))
            {
                command.Transaction = transaction;
                command.Parameters.AddWithValue("EventId", raw.EventIdentifier);
                command.Parameters.AddWithValue("TimeStamp", raw.EventTimeStamp);
                command.Parameters.AddWithValue("EventSourceId", raw.EventSourceId);
                command.Parameters.AddWithValue("Name", raw.EventName);
                command.Parameters.AddWithValue("Version", raw.EventVersion.ToString());
                command.Parameters.AddWithValue("Sequence", raw.EventSequence);
                command.Parameters.AddWithValue("Data", raw.Data);
                command.ExecuteNonQuery();
            }
        }
コード例 #27
0
 public new void ApplyEvent(ISourcedEvent e)
 {
     base.ApplyEvent(e);
 }
コード例 #28
0
 private void OnFoo(ISourcedEvent e)
 {
     FooEventHandlerInvokeCount++;
 }
コード例 #29
0
        public void Saving_event_source_while_there_is_a_newer_event_source_should_throw_concurency_exception()
        {
            var targetStore = new RavenDBEventStore(_documentStore);
            var id = Guid.NewGuid();

            int sequenceCounter = 0;

            var events = new ISourcedEvent[]
                             {
                                 new CustomerCreatedEvent(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow, "Foo",
                                                          35),
                                 new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                                         "Name" + sequenceCounter)
                             };

            var eventSource = MockRepository.GenerateMock<IEventSource>();
            eventSource.Stub(e => e.Id).Return(id).Repeat.Any();
            eventSource.Stub(e => e.InitialVersion).Return(0).Repeat.Any();
            eventSource.Stub(e => e.Version).Return(events.Length).Repeat.Any();
            eventSource.Stub(e => e.GetUncommittedEvents()).Return(events).Repeat.Any();

            targetStore.Save(eventSource);

            Action act = () => targetStore.Save(eventSource);
            act.ShouldThrow<ConcurrencyException>();
        }
コード例 #30
0
        public bool HandleEvent(ISourcedEvent sourcedEvent)
        {
            Contract.Requires <ArgumentNullException>(sourcedEvent != null, "The sourcedEvent cannot be null.");

            return(default(bool));
        }
コード例 #31
0
 public EventAppliedArgs(ISourcedEvent appliedEvent)
 {
     AppliedEvent = appliedEvent;
 }
コード例 #32
0
ファイル: EventSource.cs プロジェクト: HAXEN/ncqrs
        protected internal void ApplyEvent(ISourcedEvent evnt)
        {
            _uncommittedEvents.Append(evnt);

            HandleEvent(evnt);

            OnEventApplied(evnt);
        }
コード例 #33
0
ファイル: IEventFormatter.cs プロジェクト: mojamcpds/ncqrs
 public StoredEvent <T> Serialize(ISourcedEvent theEvent)
 {
     Contract.Requires <ArgumentNullException>(theEvent != null, "theEvent");
     Contract.Ensures(Contract.Result <StoredEvent <T> >() != null);
     return(default(StoredEvent <T>));
 }
コード例 #34
0
ファイル: EventContext.cs プロジェクト: mojamcpds/ncqrs
 private void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, ISourcedEvent evnt)
 {
     _events.Add(evnt);
 }
コード例 #35
0
        /// <summary>
        /// Saves the event to the data store.
        /// </summary>
        /// <param name="evnt">The event to save.</param>
        /// <param name="eventSourceId">The id of the event source that owns the event.</param>
        /// <param name="transaction">The transaction.</param>
        private void SaveEvent(ISourcedEvent evnt, OleDbTransaction transaction)
        {
            Contract.Requires<ArgumentNullException>(evnt != null, "The argument evnt could not be null.");
            Contract.Requires<ArgumentNullException>(transaction != null, "The argument transaction could not be null.");

            var document = _formatter.Serialize(evnt);
            var raw = _translator.TranslateToRaw(document);

            var sql = String.Format(AccessQueries.InsertNewEventQuery, raw.EventIdentifier, raw.EventSourceId, raw.EventName, raw.EventVersion, raw.Data, raw.EventSequence, raw.EventTimeStamp);
            var command = new OleDbCommand(sql, transaction.Connection);
            command.Transaction = transaction;
            command.ExecuteNonQuery();
        }
コード例 #36
0
 public new void ApplyEvent(ISourcedEvent e)
 {
     base.ApplyEvent(e);
 }
コード例 #37
0
ファイル: SourcedEventArgs.cs プロジェクト: mojamcpds/ncqrs
 public EventAppliedArgs(ISourcedEvent appliedEvent)
 {
     AppliedEvent = appliedEvent;
 }
コード例 #38
0
ファイル: EventSource.cs プロジェクト: HAXEN/ncqrs
        protected virtual void HandleEvent(ISourcedEvent evnt)
        {
            Contract.Requires<ArgumentNullException>(evnt != null, "The Event cannot be null.");
            Boolean handled = false;

            // Get a copy of the handlers because an event
            // handler can register a new handler. This will
            // cause the _eventHandlers list to be modified.
            // And modification while iterating it not allowed.
            var handlers = new List<ISourcedEventHandler>(_eventHandlers);

            foreach (var handler in handlers)
            {
                handled |= handler.HandleEvent(evnt);
            }

            if (!handled)
                throw new EventNotHandledException(evnt);
        }
コード例 #39
0
ファイル: ISourcedEventHandler.cs プロジェクト: HAXEN/ncqrs
        public bool HandleEvent(ISourcedEvent sourcedEvent)
        {
            Contract.Requires<ArgumentNullException>(sourcedEvent != null, "The sourcedEvent cannot be null.");

            return default(bool);
        }
コード例 #40
0
ファイル: EventSource.cs プロジェクト: HAXEN/ncqrs
 protected virtual void OnEventApplied(ISourcedEvent appliedEvent)
 {
     // Nothing to do. Allow override from subclassers.
 }
コード例 #41
0
ファイル: EventSource.cs プロジェクト: HAXEN/ncqrs
 private void ApplyEventFromHistory(ISourcedEvent evnt)
 {
     ValidateHistoricalEvent(evnt);
     HandleEvent(evnt);
 }
コード例 #42
0
ファイル: EventSource.cs プロジェクト: mojamcpds/ncqrs
 private void ApplyEventFromHistory(ISourcedEvent evnt)
 {
     ValidateHistoricalEvent(evnt);
     HandleEvent(evnt);
 }
コード例 #43
0
ファイル: EventSource.cs プロジェクト: HAXEN/ncqrs
        private void ValidateHistoricalEvent(ISourcedEvent evnt)
        {
            if (evnt.EventSourceId != EventSourceId)
            {
                var message = String.Format("Cannot apply historical event from other event source.");
                throw new InvalidOperationException(message);
            }

            if (evnt.EventSequence != InitialVersion + 1)
            {
                var message = String.Format("Cannot apply event with sequence {0}. Since the initial version of the " +
                                            "aggregate root is {1}. Only an event with sequence number {2} can be applied.",
                                            evnt.EventSequence, InitialVersion, InitialVersion + 1);
                throw new InvalidOperationException(message);
            }
        }
コード例 #44
0
ファイル: EventSource.cs プロジェクト: mojamcpds/ncqrs
 protected virtual void OnEventApplied(ISourcedEvent appliedEvent)
 {
     // Nothing to do. Allow override from subclassers.
 }
コード例 #45
0
 private void OnFoo(ISourcedEvent e)
 {
     FooEventHandlerInvokeCount++;
 }
コード例 #46
0
ファイル: SimpleSqlEventStore.cs プロジェクト: Andrea/ncqrs
        /// <summary>
        /// Saves the event to the data store.
        /// </summary>
        /// <param name="evnt">The event to save.</param>
        /// <param name="eventSourceId">The id of the event source that owns the event.</param>
        /// <param name="transaction">The transaction.</param>
        private static void SaveEvent(ISourcedEvent evnt, Guid eventSourceId, SqlTransaction transaction)
        {
            Contract.Requires<ArgumentNullException>(evnt != null, "The argument evnt could not be null.");
            Contract.Requires<ArgumentNullException>(transaction != null, "The argument transaction could not be null.");

            using (var dataStream = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(dataStream, evnt);
                byte[] data = dataStream.ToArray();

                using (var command = new SqlCommand(InsertNewEventQuery, transaction.Connection))
                {
                    command.Transaction = transaction;
                    command.Parameters.AddWithValue("Id", eventSourceId);
                    command.Parameters.AddWithValue("Name", evnt.GetType().FullName);
                    command.Parameters.AddWithValue("Sequence", evnt.EventSequence);
                    command.Parameters.AddWithValue("Data", data);
                    command.ExecuteNonQuery();
                }
            }
        }
コード例 #47
0
        /// <summary>
        /// Saves the event to the data store.
        /// </summary>
        /// <param name="evnt">The event to save.</param>
        /// <param name="eventSourceId">The id of the event source that owns the event.</param>
        /// <param name="transaction">The transaction.</param>
        private void SaveEvent(ISourcedEvent evnt, SqlTransaction transaction)
        {
            Contract.Requires<ArgumentNullException>(evnt != null, "The argument evnt could not be null.");
            Contract.Requires<ArgumentNullException>(transaction != null, "The argument transaction could not be null.");

            var bag = _converter.Convert(evnt);
            byte[] data = ToBinary(bag);

            using (var command = new SqlCommand(InsertNewEventQuery, transaction.Connection))
            {
                command.Transaction = transaction;
                command.Parameters.AddWithValue("EventId", evnt.EventIdentifier);
                command.Parameters.AddWithValue("EventSourceId", evnt.EventSourceId);
                command.Parameters.AddWithValue("Name", evnt.GetType().FullName);
                command.Parameters.AddWithValue("Sequence", evnt.EventSequence);
                command.Parameters.AddWithValue("Data", data);
                command.ExecuteNonQuery();
            }
        }
コード例 #48
0
        private void SaveEvent(ISourcedEvent evnt, Guid eventSourceId, SQLiteTransaction transaction)
        {
            if (evnt == null || transaction == null) throw new ArgumentNullException();
            using (var dataStream = new MemoryStream())
            {
                var bag = _converter.Convert(evnt);

                var formatter = new BinaryFormatter();
                formatter.Serialize(dataStream, bag);
                var data = dataStream.ToArray();

                using (var cmd = new SQLiteCommand(Query.InsertNewEventQuery, transaction.Connection))
                {
                    cmd.SetTransaction(transaction)
                        .AddParam("Id", eventSourceId)
                        .AddParam("Name", evnt.GetType().FullName)
                        .AddParam("Sequence", evnt.EventSequence)
                        .AddParam("Timestamp", evnt.EventTimeStamp.Ticks)
                        .AddParam("Data", data);
                    cmd.ExecuteNonQuery();
                }
            }
        }
コード例 #49
0
ファイル: EventContext.cs プロジェクト: kajaljatakia/ncqrs
 private void AggregateRootEventAppliedHandler(AggregateRoot aggregateRoot, ISourcedEvent evnt)
 {
     _events.Add(evnt);
 }