Exemplo n.º 1
0
        public static bool TryParse(string id, out T result)
        {
            try
            {
                var instance = (T)Activator.CreateInstance(typeof(T), true);

                var stringTenantUrn = AggregateRootId.Parse(id, urnFormatProvider);
                var newId           = instance.Construct(stringTenantUrn.Id, stringTenantUrn.Tenant);
                if (stringTenantUrn.AggregateRootName == newId.AggregateRootName)
                {
                    result = newId;
                }
                else
                {
                    throw new Exception("bum");
                }
                //todo check if ar name mateches..

                return(true);
            }
            catch (Exception ex)
            {
                result = null;
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 返回此实例的哈希代码
 /// </summary>
 public override int GetHashCode()
 {
     return(new int[] {
         AggregateRootTypeCode.GetHashCode(),
         AggregateRootId.GetHashCode()
     }.Aggregate((x, y) => x ^ y));
 }
Exemplo n.º 3
0
 private TakeSnapshotCommand BuildTakeUserSnapshotCommand(string userId)
 {
     return(new TakeSnapshotCommand()
     {
         AggregateRootId = AggregateRootId.FromString(userId), EntityId = EntityId.FromString(userId), AggregateRootType = typeof(User), EntityType = typeof(User)
     });
 }
Exemplo n.º 4
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((AggregateRootId.GetHashCode() * 397) ^ EntityId.GetHashCode());
     }
 }
Exemplo n.º 5
0
    /// <inheritdoc />
    public async Task<IEnumerable<AggregateRootInstance>> FetchFor(AggregateRootId aggregateRoot)
    {
        var aggregates = await _aggregates
            .Aggregates
            .Find(_filter.Eq(_ => _.AggregateType, aggregateRoot.Id.Value))
            .ToListAsync().ConfigureAwait(false);

        return aggregates.Select(_ => new AggregateRootInstance(aggregateRoot, _.EventSource, _.Version));
    }
Exemplo n.º 6
0
 public CommandDescriptor(CommandId commandId, AggregateRootId aggregateRootId, TimeSpan created, string aggregateRootType, string commandType, string commandData)
 {
     CommandId         = commandId;
     AggregateRootId   = aggregateRootId;
     Created           = created;
     AggregateRootType = aggregateRootType;
     CommandType       = commandType;
     CommandData       = commandData;
 }
 public CommandDescriptor(CommandId commandId, AggregateRootId aggregateRootId, TimeSpan created, string aggregateRootType, string commandType, string commandData)
 {
     CommandId = commandId;
     AggregateRootId = aggregateRootId;
     Created = created;
     AggregateRootType = aggregateRootType;
     CommandType = commandType;
     CommandData = commandData;
 }
Exemplo n.º 8
0
        public override string ToString()
        {
            string commitInfo =
                "AggregateCommit details" + Environment.NewLine +
                "RootId:" + AggregateRootId.ToString() + Environment.NewLine +
                "Revision:" + Revision + Environment.NewLine +
                "Events:" + string.Join(Environment.NewLine, Events.Select(e => "\t" + e.ToString()));

            return(commitInfo);
        }
Exemplo n.º 9
0
 private List <CommandDescriptor> CommandDescriptorsFor(AggregateRootId aggregateRootId)
 {
     if (CommandDescriptors.Keys.Any(s => s == aggregateRootId))
     {
         return(CommandDescriptors[aggregateRootId]);
     }
     else
     {
         var commandDescriptors = new List <CommandDescriptor>();
         CommandDescriptors.Add(aggregateRootId, commandDescriptors);
         return(commandDescriptors);
     }
 }
Exemplo n.º 10
0
        public DomainEventStream AppendDomainEventStream(IDomainEventStream streamToAppend)
        {
            if (streamToAppend == null)
            {
                throw new ArgumentNullException(nameof(streamToAppend));
            }

            if (!AggregateRootId.Equals(streamToAppend.AggregateRootId))
            {
                throw new InvalidOperationException("Cannot append domain events belonging to a different aggregate root.");
            }

            return(new DomainEventStream(AggregateRootId, this.Concat(streamToAppend)));
        }
Exemplo n.º 11
0
        public static T Parse(string id)
        {
            var instance = (T)Activator.CreateInstance(typeof(T), true);

            var stringTenantUrn = AggregateRootId.Parse(id, urnFormatProvider);
            var newId           = instance.Construct(stringTenantUrn.Id, stringTenantUrn.Tenant);

            if (stringTenantUrn.AggregateRootName == newId.AggregateRootName)
            {
                return(newId);
            }
            else
            {
                throw new Exception("bum");
            }
            //todo check if ar name mateches..
        }
Exemplo n.º 12
0
 /// <summary>
 /// Convert a <see cref="AggregateRootId"/> to <see cref="Artifact"/>.
 /// </summary>
 /// <param name="identifier"><see cref="AggregateRootId"/> to convert from.</param>
 /// <returns>Converted <see cref="Artifact"/>.</returns>
 public static Artifact ToProtobuf(this AggregateRootId identifier) =>
Exemplo n.º 13
0
 public override string GetRoutingKey() => AggregateRootId?.ToString();
Exemplo n.º 14
0
 public HeadquarterId(AggregateRootId id) : base(id, "Headquarter", "elders")
 {
 }
Exemplo n.º 15
0
 public override int GetHashCode()
 {
     return(AggregateRootId.GetHashCode() + StreamVersion.GetHashCode());
 }
Exemplo n.º 16
0
 private string AggregateRootType(AggregateRootId aggregateRootId)
 {
     return(aggregateRootId.GetType().AssemblyQualifiedName);
 }
Exemplo n.º 17
0
 public FooId(AggregateRootId id) : base(id, "Foo", id.Tenant)
 {
 }
Exemplo n.º 18
0
 /// <inheritdoc />
 public async Task <AggregateRootWithInstances> GetFor(AggregateRootId identifier)
 => new(identifier, await FetchInstances(identifier).ConfigureAwait(false));
Exemplo n.º 19
0
 public BarId(AggregateRootId id) : base(id, "Bar", id.Tenant)
 {
 }
Exemplo n.º 20
0
 public string GetAggregateId()
 {
     return(AggregateRootId.ToString());
 }
 private string AggregateRootType(AggregateRootId aggregateRootId)
 {
     return aggregateRootId.GetType().AssemblyQualifiedName;
 }
Exemplo n.º 22
0
 public override int GetHashCode()
 {
     return(AggregateRootName.GetHashCode() + AggregateRootId.GetHashCode() + Version.GetHashCode());
 }
 private List<CommandDescriptor> CommandDescriptorsFor(AggregateRootId aggregateRootId)
 {
     if (CommandDescriptors.Keys.Any(s => s == aggregateRootId))
     {
         return CommandDescriptors[aggregateRootId];
     }
     else
     {
         var commandDescriptors = new List<CommandDescriptor>();
         CommandDescriptors.Add(aggregateRootId, commandDescriptors);
         return commandDescriptors;
     }
 }