public void AddTrackingEntity(IEntityId id, string name, string icon) { var row = this.trackingRows.FirstOrDefault(r => r.IsShown() == false); if (row == null) { row = (IGrindOMeterTrackingRow)Global.FrameProvider.CreateFrame( FrameType.Frame, "GrindOMeterTrackingRow" + (this.trackingRows.Count + 1), this.frame.TrackingContainer, "GrindOMeterTrackingRowTemplate"); var previousRow = this.trackingRows.LastOrDefault(); if (previousRow == null) { row.SetPoint(FramePoint.TOPLEFT, this.frame.TrackingContainer, FramePoint.TOPLEFT); row.SetPoint(FramePoint.TOPRIGHT, this.frame.TrackingContainer, FramePoint.TOPRIGHT); } else { row.SetPoint(FramePoint.TOPLEFT, previousRow, FramePoint.BOTTOMLEFT); row.SetPoint(FramePoint.TOPRIGHT, previousRow, FramePoint.BOTTOMRIGHT); } this.ApplyTrackingEntityHandlersToRow(row); this.trackingRows.Add(row); } else { row.Show(); } row.Id = id; row.Name.SetText(name); row.IconTexture.SetTexture(icon); }
public async Task SaveAsync(IEntityId aggregateId, int originalVersion, IReadOnlyCollection <IDomainEvent> events, string name = "Aggregate name") { if (events.Count == 0) { return; } var query = $@"INSERT INTO {EventStoreTableName} ({EventStoreListOfColumnsInsert}) VALUES (@Id, @CreatedAt, @Version, @Name, @AggregateId, @Data, @Aggregate)"; var listOfEvents = events.Select(ev => new { Id = Guid.NewGuid(), Data = JsonConvert.SerializeObject(ev, Formatting.Indented, _serializerService._jsonSerializerSettings), Aggregate = name, ev.CreatedAt, ev.GetType().Name, AggregateId = aggregateId.ToString(), Version = ++originalVersion }); using (var connection = _connectionFactory.SqlConnection()) { await connection.ExecuteAsync(query, listOfEvents); } }
public async Task SaveEventsAsync(IEntityId aggregateId, int expectedVersion, IEnumerable <IDomainEvent> events) { if (events.Count() == 0) { return; } var query = $@"INSERT INTO {EventStoreTableName} ({EventStoreListOfColumnsInsert}) VALUES (@Id,@CreatedAt,@Version,@Name,@AggregateId,@Data);"; var listOfEvents = events.Select(ev => new { ev.CreatedAt, Data = JsonConvert.SerializeObject(ev, Formatting.Indented, _jsonSerializerSettings), Id = Guid.NewGuid(), ev.GetType().Name, AggregateId = aggregateId.ToString(), Version = ++expectedVersion }); using (var connection = _connectionFactory.SqlConnection()) { await connection.ExecuteAsync(query, listOfEvents); } }
public void UpdateTrackingEntityVelocity(IEntityId id, int count, double velocity) { var row = this.trackingRows.First(r => r.Id.Equals(id)); row.Amount.SetText(count + string.Empty); row.Velocity.SetText(Strings.format(VelocityString, velocity)); }
/// <inheritdoc /> public bool Equals(IEntityId <TEntity, Guid>?other) { if (ReferenceEquals(other, null)) { return(false); } return(Value.Equals(other.Value)); }
/// <summary> /// 相等判断 /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool Equals(IEntityId <TPrimaryKey> obj) { if (obj.IsEmpty) { return(false); } return(Equals(obj.Id, this.Id)); }
public IEntity Get(IEntityId entityId) { if (!entityIdPool.IsValid(entityId)) { throw new Exception("Invalid EntityId"); } return(entityFactory.Create(_id: entityId)); }
public async Task SaveEventsAsync(IEntityId aggregateId, int version, IReadOnlyCollection <IDomainEvent> events) { var stream = $"{aggregateId.GetType().Name}-{aggregateId.ToString()}"; await Connection.AppendToStreamAsync(stream, version, events.Select(e => { var json = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(e, SerializerSettings)); return(new EventData(Guid.NewGuid(), e.GetType().Name, true, json, new byte[] { })); })); }
public void EntityUpdated(Type entityType, IEntityId entity) { var modifications = GetModifications(entityType); if (!string.IsNullOrEmpty(entity?.Id) && !modifications.ContainsKey(entity)) { Console.WriteLine($"Add update modification for entity {entityType}"); modifications.Add(entity, ModificationKind.Update); } }
public async Task <IReadOnlyCollection <IDomainEvent> > LoadEventsAsync(IEntityId aggregateId) { var stream = $"{aggregateId.GetType().Name}-{aggregateId.ToString()}"; var streamEvents = await Connection.ReadStreamEventsForwardAsync(stream, 0, 4096, false); return(streamEvents.Events .Select(DeserializeDomainEvent) .ToList() .AsReadOnly()); }
protected override void OnEntityUpdated(Type entityType, IEntityId entityModel) { if (entityType != typeof(ExternalClaimTransformation)) { base.OnEntityUpdated(typeof(Models.ExternalProvider), Model); } else { base.OnEntityUpdated(entityType, entityModel); } }
/// <inheritdoc /> public int CompareTo(IEntityId <TEntity, TId>?other) { if (ReferenceEquals(null, other)) { return(1); } if (ReferenceEquals(this, other)) { return(0); } return(Comparer <TId> .Default.Compare(Value, other.Value)); }
public virtual bool Equals(IEntityId other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(ByteArrayHelper.Compare(RawId, other.RawId)); }
public void ShouldBeEqualWithIEntityIdWhenBothNull() { // arrange IdFor <Order, Guid> stronglyTypedId = null; IEntityId <Order, Guid> anotherStronglyTypedId = null; // act var result = stronglyTypedId != anotherStronglyTypedId; // assert result.Should().BeFalse(); }
/// <inheritdoc /> public bool Equals(IEntityId <TEntity, TId>?other) { if (ReferenceEquals(other, null)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(EqualityComparer <TId> .Default.Equals(Value, other.Value)); }
public async Task <IReadOnlyCollection <IDomainEvent> > LoadAsync(IEntityId aggregateRootId, CancellationToken cancellationToken) { if (aggregateRootId == null) { throw new AggregateException($"{nameof(aggregateRootId)} cannot be null"); } var events = await _dbContext.EventStoreRecords.Where(record => record.AggregateRootId == aggregateRootId.ToString()) .OrderBy(record => record.Version).ToListAsync(cancellationToken).ConfigureAwait(false); return(events.Select(Transform).ToList().AsReadOnly()); }
public void ShouldBeEqualWithIEntityIdWhenIdIsTheSame() { // arrange var targetId = Guid.NewGuid(); var stronglyTypedId = new IdFor <Order, Guid>(targetId); IEntityId <Order, Guid> anotherStronglyTypedId = stronglyTypedId; // act var result = stronglyTypedId.Equals(anotherStronglyTypedId); // assert result.Should().BeTrue(); }
public void ShouldNotBeEqualWithIEntityIdWhenNull() { // arrange var targetId = Faker.Random.Int(); var stronglyTypedId = new IntFor <Order>(targetId); IEntityId <Order, int> anotherStronglyTypedId = null; // act var result = stronglyTypedId.Equals(anotherStronglyTypedId); // assert result.Should().BeFalse(); }
public void ShouldNotBeEqualWithIEntityIdWhenNull() { // arrange var targetId = Faker.Random.Long(); var stronglyTypedId = new LongFor <Order>(targetId); IEntityId <Order, long> anotherStronglyTypedId = null; // act var result = stronglyTypedId != anotherStronglyTypedId; // assert result.Should().BeTrue(); }
public void ShouldNotBeEqualWithIEntityIdWhenSecondNull() { // arrange var targetId = Guid.NewGuid(); var stronglyTypedId = new IdFor <Order, Guid>(targetId); IEntityId <Order, Guid> anotherStronglyTypedId = null; // act var result = stronglyTypedId != anotherStronglyTypedId; // assert result.Should().BeTrue(); }
public void ShouldNotBeEqualWithIEntityIdWhenNull() { // arrange var targetId = Guid.NewGuid(); var stronglyTypedId = new GuidFor <Order>(targetId); IEntityId <Order, Guid> anotherStronglyTypedId = null; // act var result = stronglyTypedId.Equals(anotherStronglyTypedId); // assert result.Should().BeFalse(); }
protected Entity(TAggregateRoot root, IEntityId entityId) { this.root = root; this.state = new TEntityState(); var dynamicState = (dynamic)this.state; dynamicState.EntityId = (dynamic)entityId; var mapping = new DomainObjectEventHandlerMapping(); foreach (var handlerAction in mapping.GetEventHandlers(() => this.state)) { root.RegisterEventHandler(state.EntityId, handlerAction.Key, handlerAction.Value); } }
public async Task <IReadOnlyCollection <IDomainEvent> > LoadAsync(IEntityId aggregateId) { if (aggregateId == null) { throw new Exception("Not found"); } var query = new StringBuilder($@"SELECT {EventStoreListOfColumnsSelect} FROM {EventStoreTableName}"); query.Append(" WHERE [AggregateId] = @AggregateId "); query.Append(" ORDER BY [Version] ASC;"); using (var connection = _connectionFactory.SqlConnection()) { var events = (await connection.QueryAsync <EventStoreDao>(query.ToString(), new { AggregateId = aggregateId.ToString() })); var domainEvents = events.Select(_serializerService.TransformEvent).Where(@event => @event != null).ToList().AsReadOnly(); return(domainEvents); } }
public void Register(IEntityId entityId, Type eventType, Action <IEvent> handler) { Dictionary <Type, Action <IEvent> > specificEntityHandlers; if (entityHandlers.TryGetValue(entityId, out specificEntityHandlers)) { if (specificEntityHandlers.ContainsKey(eventType) == false) { specificEntityHandlers.Add(eventType, handler); } } else { entityHandlers.Add(entityId, new Dictionary <Type, Action <IEvent> >() { { eventType, handler } }); } }
public async Task <IReadOnlyCollection <IDomainEvent> > LoadAsync(IEntityId aggregateRootId) { if (aggregateRootId == null) { throw new AggregateRootNotProvidedException("AggregateRootId cannot be null"); } var query = new StringBuilder($@"SELECT {EventStoreListOfColumnsSelect} FROM {EventStoreTableName}"); query.Append(" WHERE [AggregateId] = @AggregateId "); query.Append(" ORDER BY [Version] ASC;"); using (var connection = _connectionFactory.SqlConnection()) { var events = (await connection.QueryAsync <EventStoreDao>(query.ToString(), aggregateRootId != null ? new { AggregateId = aggregateRootId.ToString() } : null)).ToList(); var domainEvents = events.Select(TransformEvent).Where(x => x != null).ToList().AsReadOnly(); return(domainEvents); } }
public void RemoveTrackingEntity(IEntityId id) { var index = this.trackingRows.IndexOf(this.trackingRows.First(row => row.Id.Equals(id))); while (true) { var row = this.trackingRows[index]; if (row.IsShown() == true && row != this.trackingRows.Last(r => r.IsShown())) { var nextRow = this.trackingRows[index + 1]; CloneRow(row, nextRow); } else { row.Hide(); break; } index++; } }
public async Task SaveAsync(IEntityId aggregateId, int originatingVersion, IReadOnlyCollection <IDomainEvent> events, string aggregateName, CancellationToken cancellationToken) { if (!events.Any()) { return; } var records = events.Select(evt => EventStoreRecord.CreateRecord( recordId: Guid.NewGuid(), serializedData: JsonConvert.SerializeObject(evt, Formatting.Indented, _jsonSettings), version: ++originatingVersion, createdAt: evt.CreatedAt, domainEventName: evt.GetType().Name, aggregateName: aggregateName, aggregateRootId: aggregateId.ToString() )); await _dbContext.EventStoreRecords.AddRangeAsync(records, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); }
public void ViewTriggersHandlersForButtons() { var containerMock = new Mock <IFrame>(); this.frameMock.SetupGet(frame => frame.TrackingContainer).Returns(containerMock.Object); var frameProviderMock = new Mock <IFrameProvider>(); Global.FrameProvider = frameProviderMock.Object; var trackingRowMocks = new List <Mock <IGrindOMeterTrackingRow> >(); frameProviderMock.Setup(fp => fp.CreateFrame(FrameType.Frame, It.IsAny <string>(), containerMock.Object, TrackingRowTemplateXmlName)) .Returns((FrameType frameType, string name, IRegion parent, string template) => { var mock = CreateTrackingRowMock(parent); trackingRowMocks.Add(mock); return(mock.Object); }); var viewUnderTest = new View(this.entitySelectionDropdownHandlerMock.Object, this.wrapperMock.Object); IEntityId resetId = null; IEntityId removeId = null; viewUnderTest.SetTrackingEntityHandlers(id => resetId = id, id => removeId = id); var idA = new Mock <IEntityId>().Object; var idB = new Mock <IEntityId>().Object; var idC = new Mock <IEntityId>().Object; viewUnderTest.AddTrackingEntity(idA, "EntityA", "IconA"); viewUnderTest.AddTrackingEntity(idB, "EntityB", "IconB"); viewUnderTest.AddTrackingEntity(idC, "EntityC", "IconC"); trackingRowMocks[1].Object.ResetButton.Click(); Assert.AreEqual(idB, resetId); trackingRowMocks[2].Object.RemoveButton.Click(); Assert.AreEqual(idC, removeId); }
protected virtual void OnEntityUpdated(Type entityType, IEntityId entityModel) { HandleModificationState.EntityUpdated(entityType, entityModel); }
public static Expression <Func <EntityDTO, bool> > HasEntity(IEntityId entityId) { return(ed => ed.EntityId.Id == entityId.Id); }