public TOutput Submit <TInput, TOutput>( ISerialization <TInput> input, ISerialization <TOutput> output, IServiceLocator locator, IDomainEventStore domainStore, bool returnInstance, TInput data) { TEvent domainEvent; try { domainEvent = data != null?input.Deserialize <TInput, TEvent>(data, locator) : Activator.CreateInstance <TEvent>(); } catch (Exception ex) { throw new ArgumentException("Error deserializing domain event.", ex); } string uri; try { uri = domainStore.Submit(domainEvent); } catch (SecurityException) { throw; } catch (Exception ex) { throw new ArgumentException( ex.Message, data == null ? new FrameworkException("Error while submitting event: {0}. Data not sent.".With(ex.Message), ex) : new FrameworkException(@"Error while submitting event: {0}. Sent data: {1}".With(ex.Message, input.Serialize(domainEvent)), ex)); } try { if (returnInstance) { return(output.Serialize(domainEvent)); } else { return(output.Serialize(uri)); } } catch (Exception ex) { throw new ArgumentException( ex.Message, new FrameworkException(@"Error serializing result: " + ex.Message, ex)); } }
/// <summary> /// Submit single domain event to the store. /// Redirects call to the collection API. /// </summary> /// <typeparam name="TEvent">domain event type</typeparam> /// <param name="store">domain event store</param> /// <param name="domainEvent">raise domain event</param> /// <returns>event identifier</returns> public static string Submit <TEvent>(this IDomainEventStore <TEvent> store, TEvent domainEvent) where TEvent : IDomainEvent { Contract.Requires(store != null); Contract.Requires(domainEvent != null); var uris = store.Submit(new[] { domainEvent }); if (uris != null && uris.Length == 1) { return(uris[0]); } return(null); }
public static Task <TAggregate> Submit <TEvent, TAggregate>(this IDomainEventStore store, TEvent domainEvent, TAggregate aggregate) where TEvent : class, IDomainEvent <TAggregate> where TAggregate : class, IAggregateRoot { if (store == null) { throw new ArgumentNullException("store can't be null"); } if (domainEvent == null) { throw new ArgumentNullException("domainEvent can't be null"); } if (aggregate == null) { throw new ArgumentNullException("aggregate can't be null"); } return(store.Submit <TEvent, TAggregate>(domainEvent, aggregate.URI)); }
public TOutput Submit <TInput, TOutput>( ISerialization <TInput> input, ISerialization <TOutput> output, IServiceLocator locator, IDomainEventStore domainStore, string uri, TInput data) { TEvent domainEvent; try { domainEvent = data != null?input.Deserialize <TInput, TEvent>(data, locator) : Activator.CreateInstance <TEvent>(); } catch (Exception ex) { throw new ArgumentException("Error deserializing domain event.", ex); } var repository = locator.Resolve <IRepository <TAggregate> >(); var aggregate = repository.Find(uri); if (aggregate == null) { throw new ArgumentException("Can't find aggregate with Uri: {0}".With(uri)); } try { domainEvent.Apply(aggregate); } catch (SecurityException) { throw; } catch (Exception ex) { throw new ArgumentException(ex.Message, ex); } try { domainStore.Submit(domainEvent); } catch (SecurityException) { throw; } catch (Exception ex) { throw new ArgumentException( ex.Message, data == null ? new FrameworkException("Error while submitting event: {0}. Data not sent.".With(ex.Message), ex) : new FrameworkException(@"Error while submitting event: {0}. Sent data: {1}".With(ex.Message, output.Serialize(domainEvent)), ex)); } return(output.Serialize(aggregate)); }