/// <summary> /// 为给定的聚合根实体创建快照数据对象。 /// </summary> /// <param name="acDomain"></param> /// <param name="aggregateRoot">快照为该聚合根对象创建。</param> /// <returns>快照数据对象。</returns> public static SnapshotDataObject CreateFromAggregateRoot(this IAcDomain acDomain, ISourcedAggregateRoot aggregateRoot) { var serializer = acDomain.RetrieveRequiredService<ISnapshotSerializer>(); var snapshot = aggregateRoot.CreateSnapshot(); return new SnapshotDataObject { AggregateRootId = aggregateRoot.Id, AggregateRootType = aggregateRoot.GetType().AssemblyQualifiedName, Version = aggregateRoot.Version, Branch = Constants.ApplicationRuntime.DefaultBranch, SnapshotType = snapshot.GetType().AssemblyQualifiedName, Timestamp = snapshot.Timestamp, SnapshotData = serializer.Serialize(snapshot) }; }
/// <summary> /// Initializes a new instance of <c>InlineDomainEventHandler</c> class. /// </summary> /// <param name="aggregateRoot">The instance of the aggregate root within which the domain event /// was raised and handled.</param> /// <param name="mi">The method which handles the domain event.</param> public InlineDomainEventHandler(ISourcedAggregateRoot aggregateRoot, MethodInfo mi) { ParameterInfo[] parameters = mi.GetParameters(); if (parameters == null || parameters.Count() == 0) { throw new ArgumentException(string.Format(Resources.EX_INVALID_HANDLER_SIGNATURE, mi.Name), "mi"); } domainEventType = parameters[0].ParameterType; action = domainEvent => { try { mi.Invoke(aggregateRoot, new object[] { domainEvent }); return true; } catch { return false; } }; }
/// <summary> /// Creates the snapshot data object from the aggregate root. /// </summary> /// <param name="aggregateRoot">The aggregate root for which the snapshot is being created.</param> /// <returns>The snapshot data object.</returns> public static SnapshotDataObject CreateFromAggregateRoot(ISourcedAggregateRoot aggregateRoot) { ISnapshotSerializer serializer = null; ApworksConfigSection config = AppRuntime.Instance.CurrentApplication.ConfigSource.Config; if (config.Serializers == null || config.Serializers.SnapshotSerializer == null || string.IsNullOrEmpty(config.Serializers.SnapshotSerializer.Provider) || string.IsNullOrWhiteSpace(config.Serializers.SnapshotSerializer.Provider)) { serializer = new SnapshotXmlSerializer(); } else { string typeName = config.Serializers.SnapshotSerializer.Provider; Type serializerType = Type.GetType(typeName); if (serializerType == null) throw new InfrastructureException("The serializer defined by type '{0}' doesn't exist.", typeName); serializer = (ISnapshotSerializer)Activator.CreateInstance(serializerType); } ISnapshot snapshot = aggregateRoot.CreateSnapshot(); return new SnapshotDataObject { AggregateRootID = aggregateRoot.ID, AggregateRootType = aggregateRoot.GetType().AssemblyQualifiedName, Version = aggregateRoot.Version, Branch = Constants.ApplicationRuntime.DefaultBranch, SnapshotType = snapshot.GetType().AssemblyQualifiedName, Timestamp = snapshot.Timestamp, SnapshotData = serializer.Serialize(snapshot) }; }
/// <summary> /// Creates or updates the snapshot for the given aggregate root. /// </summary> /// <param name="aggregateRoot">The aggregate root on which the snapshot is created or updated.</param> /// <remarks>For <c>SuppressedSnapshotProvider</c>, nothing is done in this method.</remarks> public override void CreateOrUpdateSnapshot(ISourcedAggregateRoot aggregateRoot) { }
/// <summary> /// Returns a <see cref="System.Boolean"/> value which indicates /// whether the snapshot should be created or updated for the given /// aggregate root. /// </summary> /// <param name="aggregateRoot">The aggregate root.</param> /// <returns>True if the snapshot should be created or updated, /// otherwise false.</returns> /// <remarks>This method always returns false in<c>SuppressedSnapshotProvider</c> /// to prevent the snapshots being created or updated.</remarks> public override bool CanCreateOrUpdateSnapshot(ISourcedAggregateRoot aggregateRoot) { return false; }
/// <summary> /// Creates or updates the snapshot for the given aggregate root. /// </summary> /// <param name="aggregateRoot">The aggregate root on which the snapshot is created or updated.</param> public abstract void CreateOrUpdateSnapshot(ISourcedAggregateRoot aggregateRoot);
/// <summary> /// Returns a <see cref="System.Boolean"/> value which indicates /// whether the snapshot should be created or updated for the given /// aggregate root. /// </summary> /// <param name="aggregateRoot">The aggregate root.</param> /// <returns>True if the snapshot should be created or updated, /// otherwise false.</returns> public abstract bool CanCreateOrUpdateSnapshot(ISourcedAggregateRoot aggregateRoot);
/// <summary> /// 从聚合根中创建快照数据对象 /// </summary> /// <param name="aggregateRoot">快照被创建的聚合根</param> /// <returns>快照数据对象</returns> public static SnapshotDataObject CreateFromAggregateRoot(ISourcedAggregateRoot aggregateRoot) { var serializer = GetSnapshotSerializer(); var snapshot = aggregateRoot.CreateSnapshot(); return new SnapshotDataObject { AggregateRootID = aggregateRoot.ID, AggregateRootType = aggregateRoot.GetType().AssemblyQualifiedName, Version = aggregateRoot.Version, SnapshotType = snapshot.GetType().AssemblyQualifiedName, Timestamp = snapshot.Timestamp, SnapshotData = serializer.Serialize(snapshot) }; }