Пример #1
0
        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);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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));
        }
Пример #5
0
 /// <inheritdoc />
 public bool Equals(IEntityId <TEntity, Guid>?other)
 {
     if (ReferenceEquals(other, null))
     {
         return(false);
     }
     return(Value.Equals(other.Value));
 }
Пример #6
0
 /// <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));
 }
Пример #7
0
        public IEntity Get(IEntityId entityId)
        {
            if (!entityIdPool.IsValid(entityId))
            {
                throw new Exception("Invalid EntityId");
            }

            return(entityFactory.Create(_id: entityId));
        }
Пример #8
0
        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[] { }));
            }));
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        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());
        }
Пример #11
0
 protected override void OnEntityUpdated(Type entityType, IEntityId entityModel)
 {
     if (entityType != typeof(ExternalClaimTransformation))
     {
         base.OnEntityUpdated(typeof(Models.ExternalProvider), Model);
     }
     else
     {
         base.OnEntityUpdated(entityType, entityModel);
     }
 }
Пример #12
0
 /// <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));
 }
Пример #13
0
 public virtual bool Equals(IEntityId other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(ByteArrayHelper.Compare(RawId, other.RawId));
 }
Пример #14
0
            public void ShouldBeEqualWithIEntityIdWhenBothNull()
            {
                // arrange
                IdFor <Order, Guid>     stronglyTypedId        = null;
                IEntityId <Order, Guid> anotherStronglyTypedId = null;

                // act
                var result = stronglyTypedId != anotherStronglyTypedId;

                // assert
                result.Should().BeFalse();
            }
Пример #15
0
 /// <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));
 }
Пример #16
0
        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();
            }
Пример #18
0
            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();
            }
Пример #20
0
            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();
            }
Пример #22
0
        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);
            }
        }
Пример #23
0
        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);
            }
        }
Пример #24
0
        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);
            }
        }
Пример #26
0
        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++;
            }
        }
Пример #27
0
        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);
        }
Пример #28
0
        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);
        }
Пример #29
0
 protected virtual void OnEntityUpdated(Type entityType, IEntityId entityModel)
 {
     HandleModificationState.EntityUpdated(entityType, entityModel);
 }
Пример #30
0
 public static Expression <Func <EntityDTO, bool> > HasEntity(IEntityId entityId)
 {
     return(ed => ed.EntityId.Id == entityId.Id);
 }