void IQueueMessageHandler.Handle(QueueMessage queueMessage, IMessageContext context) { var messageType = _typeCodeProvider.GetType(queueMessage.Code); var message = _jsonSerializer.Deserialize(Encoding.UTF8.GetString(queueMessage.Body), messageType) as IApplicationMessage; var processContext = new EQueueProcessContext(queueMessage, context); var processingMessage = new ProcessingApplicationMessage(message, processContext); _processor.Process(processingMessage); }
public IAggregateRoot RestoreFromSnapshot(Snapshot snapshot) { if (snapshot == null) { throw new ArgumentNullException("snapshot");; } var aggregateRootType = _aggregateRootTypeCodeProvider.GetType(snapshot.AggregateRootTypeCode); return(_binarySerializer.Deserialize(snapshot.Payload, aggregateRootType) as IAggregateRoot); }
private int GetDefineVersion(int aggregateTypeCode) { var aggregateType = _typeCodeProvider.GetType(aggregateTypeCode); if (!aggregateType.IsDefined <SnapshotPolicyAttribute>(false)) { return(20); } return(aggregateType.GetAttribute <SnapshotPolicyAttribute>(false).TriggeredVersion); }
public IEnumerable <TEvent> Deserialize <TEvent>(IDictionary <int, string> data) where TEvent : class, IDomainEvent { var evnts = new List <TEvent>(); foreach (var entry in data) { var eventType = _typeCodeProvider.GetType(entry.Key); var evnt = _jsonSerializer.Deserialize(entry.Value, eventType) as TEvent; evnts.Add(evnt); } return(evnts); }
void IQueueMessageHandler.Handle(QueueMessage queueMessage, IMessageContext context) { var exceptionMessage = _jsonSerializer.Deserialize<PublishableExceptionMessage>(Encoding.UTF8.GetString(queueMessage.Body)); var exceptionType = _publishableExceptionTypeCodeProvider.GetType(exceptionMessage.ExceptionTypeCode); var exception = FormatterServices.GetUninitializedObject(exceptionType) as IPublishableException; exception.Id = exceptionMessage.UniqueId; exception.Timestamp = exceptionMessage.Timestamp; exception.RestoreFrom(exceptionMessage.SerializableInfo); var sequenceMessage = exception as ISequenceMessage; if (sequenceMessage != null) { sequenceMessage.AggregateRootTypeCode = exceptionMessage.AggregateRootTypeCode; sequenceMessage.AggregateRootId = exceptionMessage.AggregateRootId; } var processContext = new EQueueProcessContext(queueMessage, context); var processingMessage = new ProcessingPublishableExceptionMessage(exception, processContext); _publishableExceptionProcessor.Process(processingMessage); }
private void RefreshAggregateMemoryCache(DomainEventStream aggregateFirstEventStream) { try { var aggregateRootType = _aggregateRootTypeCodeProvider.GetType(aggregateFirstEventStream.AggregateRootTypeCode); var aggregateRoot = _memoryCache.Get(aggregateFirstEventStream.AggregateRootId, aggregateRootType); if (aggregateRoot == null) { aggregateRoot = _aggregateRootFactory.CreateAggregateRoot(aggregateRootType); aggregateRoot.ReplayEvents(new DomainEventStream[] { aggregateFirstEventStream }); _memoryCache.Set(aggregateRoot); _logger.DebugFormat("Aggregate added into memory, commandId:{0}, aggregateRootType:{1}, aggregateRootId:{2}, aggregateRootVersion:{3}", aggregateFirstEventStream.CommandId, aggregateRootType.Name, aggregateRoot.UniqueId, aggregateRoot.Version); } } catch (Exception ex) { _logger.Error(string.Format("Refresh memory cache by aggregate first event stream failed, {0}", aggregateFirstEventStream), ex); } }
public void RefreshAggregateFromEventStore(int aggregateRootTypeCode, string aggregateRootId) { try { var aggregateRootType = _aggregateRootTypeCodeProvider.GetType(aggregateRootTypeCode); if (aggregateRootType == null) { _logger.ErrorFormat("Could not find aggregate root type by aggregate root type code [{0}].", aggregateRootTypeCode); return; } var aggregateRoot = _aggregateStorage.Get(aggregateRootType, aggregateRootId); if (aggregateRoot != null) { _aggregateRootDict[aggregateRoot.UniqueId] = aggregateRoot; } } catch (Exception ex) { _logger.Error(string.Format("Exception raised when refreshing aggregate from event store, aggregateRootTypeCode:{0}, aggregateRootId:{1}", aggregateRootTypeCode, aggregateRootId), ex); } }