public void Save(IAggregate aggregate) { Db4oAggregate dbAggregate = (from Db4oAggregate a in _database where a.Id == aggregate.Id select a).FirstOrDefault(); int version = 0; if (dbAggregate == null) { dbAggregate = new Db4oAggregate { Id = aggregate.Id, Type = aggregate.GetType().Name, Version = 0 }; } else { version = dbAggregate.Version; } IEnumerable<IDomainEvent> events = aggregate.GetChanges(); foreach (IDomainEvent e in events) { version++; var db4oEvent = new Db4oEvent { AggregateId = dbAggregate.Id, Event = e, Version = version }; _database.Store(db4oEvent); } dbAggregate.Version = version; _database.Store(dbAggregate); }
public void AddAggregate(IAggregate aggregate) { if (!_works.Contains(aggregate)) { _works.Add(aggregate); aggregate.Seed(); } }
public void Add(IAggregate aggregate) { var result = _all.GetOrAdd(aggregate.Id, aggregate); if(!Object.ReferenceEquals(aggregate, result)) { throw new AggregateVersionException(aggregate.Id, aggregate.GetType(), aggregate.Version, 0); } }
public void UpdateEventDetails(IDomainEvent e, IAggregate aggregate, EntityBase source) { versionProperty.SetValue(e, aggregate.GetVersion()); aggregateIdentityProperty.SetValue(e, aggregate.Identity.GetId()); if (entityIdentityProperty != null) { entityIdentityProperty.SetValue(e, source.Identity.GetId()); } }
public void Invoke(IAggregate aggregate, object eventData) { var handlers = AllHandlers.GetOrAdd(aggregate.GetType(), type => ScanAggregate(type)); Action<IAggregate, object> handler; if (handlers.TryGetValue(eventData.GetType(), out handler)) { handler(aggregate, eventData); } }
protected virtual void Save(IAggregate aggr, DomainEvent by) { foreach (DomainEvent evt in aggr.GetUncommittedEvents()) { if (!evt.TenantId.HasValue) evt.TenantId = @by.TenantId; if (!evt.IssuedBy.HasValue) evt.IssuedBy = @by.IssuedBy; if (!evt.SagaId.HasValue) evt.SagaId = @by.SagaId; evt.Version = aggr.Version; } repo.Save(aggr, Guid.NewGuid()); }
protected virtual void Save(IAggregate aggr, DomainCommand by, string bucketId) { if (OnSavedHook != null) OnSavedHook(this, aggr, by); foreach (DomainEvent evt in aggr.GetUncommittedEvents()) { if (!evt.TenantId.HasValue) evt.TenantId = @by.TenantId; if (!evt.IssuedBy.HasValue) evt.IssuedBy = @by.IssuedBy; if (!evt.SagaId.HasValue) evt.SagaId = @by.SagaId; evt.Version = aggr.Version; } repo.Save(bucketId, aggr, @by.CommitId); }
public void Save(IAggregate aggregate) { //Open file stream var aggregateName = aggregate.GetType().Name; string aggregateFileName = string.Format("{0}-{1}.evt", aggregateName, aggregate.Id); var pathToFile = Path.Combine(_path, aggregateFileName); var uncommittedEvents = aggregate.GetUncommittedEvents(); foreach (var uncommittedEvent in uncommittedEvents) { var serializeObject = JsonConvert.SerializeObject(uncommittedEvent); File.AppendAllText(pathToFile, serializeObject); } }
public void Write(IAggregate aggregate, Guid commitId, Action<IDictionary<string, object>> updateHeaders) { var streamName = _aggregateIdToStreamName(aggregate.Category, aggregate.Id); var newEvents = aggregate.GetUncommittedEvents().Cast<object>().ToList(); var eventsToSave = newEvents .Select(e => e.AsJsonEvent()) .ToList(); foreach (var eventData in eventsToSave) { var data = new StreamData(streamName, eventData); FakeDatabase.Events.Add(Guid.NewGuid(), data); } aggregate.ClearUncommittedEvents(); }
public static void Save(this IRepository repository, IAggregate aggregate, Guid commitId, object sourceMessage) { repository.Save(aggregate, commitId, (d) => Add_Source_Message_To_Headers(d, sourceMessage)); }
public static IEnumerable <Event> GetUncommittedEvents(this AggregateBase ar) { IAggregate a = ar; return(a.GetUncommittedEvents().Cast <Event>()); }
public static void Save(this IRepository repository, IAggregate aggregate, Guid commitId) { repository.Save(aggregate, commitId, a => { }); }
public static async Task <long?> Handle <S, C>(CommandEnvelope <C> commandEnvelope, IAggregate <S> aggregate, IEventStore eventStore, CancellationToken cancel = default) where C : class where S : class { if (commandEnvelope.AggregateId == null || commandEnvelope.Command == null) { throw new Exception(); } var streamName = aggregate.GetStreamName(commandEnvelope.AggregateId); var(version, state) = await Load(streamName, aggregate, eventStore, cancel); var events = aggregate.Handle(state, commandEnvelope.Command) .Select((e, i) => e.CreateEventEnvelope(commandEnvelope.AggregateId, version + i + 1)) .ToArray(); return(await eventStore.Save(streamName, cancel, events)); }
/// <summary> /// Gets the key from an object. /// If the key isn't unique and the property allows for key generation, a unique key is generated. /// </summary> /// <param name="target"></param> /// <param name="root"></param> /// <returns></returns> private static string GetKeyFromObject(IAggregate target, object root) { string key = null; int lastkey = 0; string[] property = target.Properties; int generatedProperty = -1; bool generationPossible = true; while (generationPossible) { key = null; lastkey++; generationPossible = false; for (int i = 0; i < property.Length; i++) { if ((Boolean) MetaInfo.GetAttributeDefault (target.Source.GetType(), property[i], "XmlKey", false)) { object KeyObject = target.GetValue(property[i]); if ((KeyObject != null) && (!KeyObject.ToString().Trim().Equals(""))) { key += KeyObject.ToString() + ";"; } else if ((Boolean) MetaInfo.GetAttributeDefault (target.Source.GetType(), property[i], "XmlAllowGeneration", true)) { generationPossible = true; generatedProperty = i; key += lastkey + ";"; } } } if (key != null) { key += target.Source.GetType().FullName; object registeredObject = XmlFile.GetRegisteredTarget(root, key); if ((registeredObject == null) || (registeredObject == target)) { if (generatedProperty != -1) { Type PropertyType = target.GetType(property[generatedProperty]); if (PropertyType.Equals(typeof(string))) { target.SetValue(property[generatedProperty], Convert.ToString(lastkey)); } else if (PropertyType.Equals(typeof(Int16)) || PropertyType.Equals(typeof(Int32)) || PropertyType.Equals(typeof(Int64))) { target.SetValue(property[generatedProperty], lastkey); } } return key; } } } return key; }
/// <summary> /// Collects all processed events for given aggregate and return them as a list /// used to build up an aggregate from its history (Domain.ReconstituteFromHistory) /// </summary> /// <param name="aggregate"></param> /// <returns></returns> public List<DomainEvent> EventsForAggregate(IAggregate aggregate) { return EventsForAggregate(new AggregateKey(aggregate)); }
public static string Name(this IAggregate aggregate) { var type = aggregate.GetType(); return(type.GenericTypeArguments.Aggregate(type.Name, (c, t) => c + t.Name)); }
public Task Save(IAggregate aggregate, Guid commitId, Action <IDictionary <string, object> > updateHeaders) { Events = aggregate.GetUncommittedEvents().Cast <DomainEvent>(); return(Task.CompletedTask); }
public static void Save(this IRepository @this, IAggregate aggregate, Action <IDictionary <string, object> > updateHeaders) { @this.Save(aggregate, Guid.NewGuid(), updateHeaders); }
public static async Task Save(this IRepository repository, IAggregate aggregate, Guid commitId) { await repository.Save(aggregate, commitId, a => { }); }
public static void Save(this IRepository @this, IAggregate aggregate) { @this.Save(aggregate, Guid.NewGuid(), d => { }); }
private int CalculateExpectedVersion <T>(IAggregate aggregate, List <T> events) { return(aggregate.Version - events.Count); }
/// <summary> /// Récupération de l'action /// </summary> /// <param name="aggregate">Agrégat.</param> /// <param name="handledEvent">Evènement intercepté.</param> /// <returns>Tâche asynchone.</returns> public Func <Task> GetHandleAction(IAggregate aggregate, IEvent handledEvent) { return(() => handlingFunction(aggregate, handledEvent)); }
public MyIterator(IAggregate aggregate) { aggregate_ = aggregate; }
public IValue Concat(IAggregate value) => value switch {
public Prototype(IAggregate aggregate) { this.aggregate = aggregate; }
private IAggregate ReadAggregate(JsonReader reader, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) { return(null); } reader.Read(); if (reader.TokenType != JsonToken.PropertyName) { return(null); } IAggregate aggregate = null; var propertyName = (string)reader.Value; if (_numeric.IsMatch(propertyName)) { aggregate = GetPercentilesAggregate(reader, serializer, oldFormat: true); } var meta = propertyName == Parser.Meta ? GetMetadata(reader) : null; if (aggregate != null) { aggregate.Meta = meta; return(aggregate); } propertyName = (string)reader.Value; switch (propertyName) { case Parser.Values: reader.Read(); reader.Read(); aggregate = GetPercentilesAggregate(reader, serializer); break; case Parser.Value: aggregate = GetValueAggregate(reader, serializer); break; case Parser.Buckets: case Parser.DocCountErrorUpperBound: aggregate = GetMultiBucketAggregate(reader, serializer); break; case Parser.Count: aggregate = GetStatsAggregate(reader, serializer); break; case Parser.DocCount: aggregate = GetSingleBucketAggregate(reader, serializer); break; case Parser.Bounds: aggregate = GetGeoBoundsAggregate(reader, serializer); break; case Parser.Hits: aggregate = GetTopHitsAggregate(reader, serializer); break; case Parser.Location: aggregate = GetGeoCentroidAggregate(reader, serializer); break; case Parser.Fields: aggregate = GetMatrixStatsAggregate(reader, serializer); break; default: return(null); } aggregate.Meta = meta; return(aggregate); }
/// <summary> /// Gets the property given a specific xml element name /// </summary> /// <param name="target">The object which will contain the property</param> /// <param name="name">The xml element name</param> /// <returns>The property name, null if not found</returns> private static string GetProperty (IAggregate target, string name) { string[] properties = target.Properties; for (int i = 0; i < properties.Length; i++) { string elementName = XmlFile.GetElementName (target.Source.GetType(), properties[i], false); if ((elementName != null) && (elementName.Equals(name))) { return properties[i]; } elementName = XmlFile.GetElementName (target.Source.GetType(), properties[i], true); if ((elementName != null) && (elementName.Equals(name))) { return properties[i]; } } return null; }
public void Add(IAggregate aggregate) { this.LockAndExecute(aggregate.Id, () => this.map[aggregate.Id] = aggregate); }
public IteratorClass(IAggregate aggregate) { Aggregate = aggregate; }
public void Register(IAggregate aggregate) { }
private static void ApplyEventsToAggregate(int versionToLoad, IEventStream stream, IAggregate aggregate) { if (versionToLoad == 0 || aggregate.Version < versionToLoad) { foreach (var @event in stream.CommittedEvents.Select(x => x.Body)) { aggregate.ApplyEvent(@event); } } }
public IValue Uncons(out IAggregate rest) { rest = this.Rest(); return(this.First()); }
public ConcreteIterator(IAggregate aggregate) { this.aggregate = aggregate; }
public ICommand Project(IAggregate aggregate) { throw new NotSupportedException("Clause don't supported by command."); }
public abstract IJoinTable <K, T1> LeftJoin <T1>(IAggregate <T1> aggregate, Expression <Func <K, T1, bool> > onExpression);
private IAggregate ReadAggregate(JsonReader reader, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) { return(null); } reader.Read(); if (reader.TokenType != JsonToken.PropertyName) { return(null); } IAggregate aggregate = null; var property = reader.Value as string; if (_numeric.IsMatch(property)) { aggregate = GetPercentilesAggregate(reader, serializer, oldFormat: true); } var meta = (property == "meta") ? GetMetadata(reader) : null; if (aggregate != null) { aggregate.Meta = meta; return(aggregate); } property = reader.Value as string; switch (property) { case "values": reader.Read(); reader.Read(); aggregate = GetPercentilesAggregate(reader, serializer); break; case "value": aggregate = GetValueAggregate(reader, serializer); break; case "buckets": case "doc_count_error_upper_bound": aggregate = GetMultiBucketAggregate(reader, serializer); break;; case "count": aggregate = GetStatsAggregate(reader, serializer); break; case "doc_count": aggregate = GetSingleBucketAggregate(reader, serializer); break; case "bounds": aggregate = GetGeoBoundsAggregate(reader, serializer); break; case "hits": aggregate = GetTopHitsAggregate(reader, serializer); break; case "location": aggregate = GetGeoCentroidAggregate(reader, serializer); break; case "fields": aggregate = GetMatrixStatsAggregate(reader, serializer); break; default: return(null); } aggregate.Meta = meta; return(aggregate); }
public abstract IJoinTable <K, T1> RightJoin <T1>(IAggregate <T1> aggregate, Expression <Func <K, T1, bool> > onExpression, JoinSetting joinSetting);
public AbstractFlyweight(params System.Object[] elements) : base() { _aggregate = new AbstractAggregate(elements); _repository = generateRepository(); }
public void SetAggregate(IAggregate ag) => this._aggregate = ag;
internal void UpdateEventDetails(IAggregateEvent @event, IAggregate aggregate) { var handler = eventHandlers.First(h => h.CanHandleEvent(@event)); handler.UpdateEventDetails(@event, aggregate, this); }
public static async Task SaveAsync(this IRepository repository, IAggregate aggregate, Guid commitId) { await repository.SaveAsync(aggregate, commitId, a => { }); }
public ConventionEventRouter(bool throwOnApplyNotFound, IAggregate aggregate) : this(throwOnApplyNotFound) { this.Register(aggregate); }
public void Save(IAggregate aggregate) { var repostiory = new FakeEventStoreRepository(); repostiory.Write(aggregate, Guid.NewGuid(), d => { }); }
public void Save(IAggregate aggregate, Guid commitId, object cmd) { var jsonCommand = Newtonsoft.Json.JsonConvert.SerializeObject(cmd); Save(aggregate, commitId, a => { a.Add(CommandHeader, jsonCommand); }); }
public static bool IsNew(this IAggregate aggregate) => aggregate.IsInitialized && aggregate.Version == 0;
public AutoVersioningConventionEventRouter(IAggregate aggregateRoot):base(true, aggregateRoot) { _source = aggregateRoot; }
public MyIterator(IAggregate aggregate) { this.aggregate = aggregate; }
public void Dispose() { aggregate = null; }
public void Handle(IAggregate aggregate) { throw new NotImplementedException("Call upsert statement"); }
/// <summary> /// Gets all properties of an aggregate in a sorted way. /// MetaInfo attribute "XmlIndex" is used for the sorting. /// </summary> /// <param name="aggregate">The aggregate</param> /// <returns>Sorted property names</returns> private static string[] GetSortedProperties (IAggregate aggregate) { SortedList list = new SortedList(); string[] properties = aggregate.Properties; for (int i = 0; i < properties.Length; i++) { int index = (int)MetaInfo.GetAttributeDefault (aggregate.Source.GetType(), properties[i], "XmlIndex", 1000); string listIndex = index.ToString("D9") + " " + properties[i].ToLower(); if (!list.Contains (listIndex)) { list.Add (listIndex, properties[i]); } } /* for (int i = 0; i < list.GetValueList()..Values.Count; i++) { propertyList.Add (list.GetByIndex(i)); }*/ ArrayList propertyList = new ArrayList(list.Values); return (string[]) propertyList.ToArray(typeof(string)); }
public bool Equals(IAggregate other) { return(Id.Equals(other?.Id) && Version == other?.Version); }
/// <summary> /// Reads the attributes of the current xml element and uses them to populute the target with /// </summary> /// <param name="target">The object which is populated with the xml attributes</param> /// <param name="reader">The xml stream</param> /// <param name="root">Top object of the xml stream</param> /// <exception cref="System.Exception">Cannot find class type</exception> /// <exception cref="System.Exception">Cannot instantiate object for known class type</exception> private static void ReadAttributes (IAggregate target, XmlReader reader, object root) { // Read all attributes string[] properties = target.Properties; for (int i = 0; i < properties.Length; i++) { string name = XmlFile.GetElementName (target.Source.GetType(), properties[i], false); if (name != null) { string attributeValue = reader.GetAttribute(name); if (attributeValue != null) { string classType = (string) MetaInfo.GetAttributeDefault (target.Source.GetType(), properties[i], "XmlType", target.GetType(properties[i]).FullName); Type type = ObjectSupport.GetType(classType); if (type == null) { throw new Exception("Could not find class type " + classType); } if (type.Equals(typeof(FileInfo))) { attributeValue = FileSupport.ExpandRelativePath (XmlFile.GetRegisteredFile(root).Directory, attributeValue).FullName; } if (type.Equals(typeof(DirectoryInfo))) { attributeValue = FileSupport.ExpandRelativeDirectory (XmlFile.GetRegisteredFile(root).Directory, attributeValue).FullName; } object targetValue = ObjectSupport.GetInstance (type, attributeValue, _culture); if (targetValue == null) { throw new Exception("Could not instantiate class type " + type.FullName); } if (target.CanWrite(properties[i])) { target.SetValue(properties[i], targetValue); } } } } }
public CommandHandler(IAggregate <TState> aggregate, IEventStore <TIdentity, TState> store, IIDGenerator <TIdentity> generator) { _aggregate = aggregate; _eventStore = store; _generator = generator; }
/// <summary> /// Stores the aggregate changes. /// </summary> /// <param name="aggregate"></param> public void SaveChanges(IAggregate aggregate) { SaveEvents(new AggregateKey(aggregate), aggregate.Revision, aggregate.UncommittedChanges()); aggregate.ClearUncommittedEvents(); }
public OrderedEventPayload[] Save(IAggregate aggregate) { return(Save(new[] { aggregate })); }
public void PublishUpdate(IAggregate aggregate) { _aggregateBus.Publish(aggregate); }
public Iterator(IAggregate colecao) { this.colecao = colecao; }