예제 #1
0
        /// <summary>
        /// Initializes a new instance of <c>SnapshotDataObject</c> class.
        /// </summary>
        public SnapshotDataObject()
        {
            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);
            }
        }
예제 #2
0
        /// <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>
        /// Gets the serializer for domain events.
        /// </summary>
        /// <returns>The domain event serializer instance.</returns>
        private static IDomainEventSerializer GetDomainEventSerializer()
        {
            IDomainEventSerializer serializer = null;
            ApworksConfigSection   config     = AppRuntime.Instance.CurrentApplication.ConfigSource.Config;

            if (config.Serializers == null ||
                config.Serializers.EventSerializer == null ||
                string.IsNullOrEmpty(config.Serializers.EventSerializer.Provider) ||
                string.IsNullOrWhiteSpace(config.Serializers.EventSerializer.Provider))
            {
                serializer = new DomainEventXmlSerializer();
            }
            else
            {
                string typeName       = config.Serializers.EventSerializer.Provider;
                Type   serializerType = Type.GetType(typeName);
                if (serializerType == null)
                {
                    throw new InfrastructureException("The serializer defined by type '{0}' doesn't exist.", typeName);
                }
                serializer = (IDomainEventSerializer)Activator.CreateInstance(serializerType);
            }
            return(serializer);
        }
예제 #4
0
        private ExceptionManager()
        {
            try
            {
                ApworksConfigSection config = AppRuntime.Instance.CurrentApplication.ConfigSource.Config;
                if (config.Exceptions != null &&
                    config.Exceptions.Count > 0)
                {
                    ExceptionElementCollection exceptionElementCollection = config.Exceptions;
                    foreach (ExceptionElement exceptionElement in exceptionElementCollection)
                    {
                        Type exceptionType = Type.GetType(exceptionElement.Type);
                        if (exceptionType == null)
                        {
                            continue;
                        }

                        if (exceptionType.IsAbstract ||
                            !typeof(Exception).IsAssignableFrom(exceptionType))
                        {
                            continue;
                        }

                        ExceptionHandlingBehavior handlingBehavior = exceptionElement.Behavior;
                        if (exceptionElement.Handlers != null &&
                            exceptionElement.Handlers.Count > 0)
                        {
                            foreach (ExceptionHandlerElement exceptionHandlerElement in exceptionElement.Handlers)
                            {
                                Type handlerType = Type.GetType(exceptionHandlerElement.Type);
                                if (handlerType != null)
                                {
                                    if (handlerType.IsAbstract ||
                                        !handlerType.GetInterfaces().Any(p => p.Equals(typeof(IExceptionHandler))))
                                    {
                                        continue;
                                    }

                                    try
                                    {
                                        IExceptionHandler exceptionHandler = (IExceptionHandler)Activator.CreateInstance(handlerType);
                                        this.RegisterHandlerOrig(exceptionType, handlingBehavior, exceptionHandler);
                                    }
                                    catch
                                    {
                                        continue;
                                    } // try
                                }     // if
                            }         // foreach - exception handler
                        }
                        else
                        {
                            handlersOrig.Add(exceptionType, new ExceptionConfigItem {
                                Behavior = handlingBehavior, Handlers = new List <IExceptionHandler>()
                            });
                        }
                    } // foreach - exception
                    BuildResponsibilityChain();
                }     // if
            }
            catch { }
        }