/// <summary> /// Construtor padrão. /// </summary> /// <param name="info">Informações do evento da entidade.</param> /// <param name="entityType">Nome completo do tipo da entidade.</param> /// <param name="subscription"></param> public EventSubscriptionInfo(EntityEventInfo info, Reflection.TypeName entityType, Domain.IExecuteSubscription <TPayLoad> subscription) { subscription.Require("subscription").NotNull(); this.Info = info; this.EntityType = entityType; this.Subscription = subscription; }
/// <summary> /// Método acionado quando ocorre um erro no registro do EntityEventInfo. /// </summary> /// <param name="typeName"></param> /// <param name="eventInfo"></param> /// <param name="error"></param> private void OnRegisterEventInfoError(Reflection.TypeName typeName, EntityEventInfo eventInfo, Exception error) { if (RegisterEventInfoError != null) { RegisterEventInfoError(this, new RegisterEntityEventInfoErrorArgs(typeName, eventInfo, error)); } }
/// <summary> /// Registra o evento para a entidade. /// </summary> /// <param name="entityType">Nome da entidade.</param> /// <param name="info">Informações do evento.</param> private void Register(Reflection.TypeName entityType, EntityEventInfo info) { Domain.SubscriptionToken token = null; switch (info.EventType) { case EntityEventType.Initialized: token = RegisterEvent <EntityInitializedEvent, IEntityInitializedEventSubscription, EntityInitializedEventArgs>(entityType, info); break; case EntityEventType.PropertyChanging: token = RegisterEvent <EntityPropertyChangingEvent, IEntityPropertyChangingEventSubscription, EntityPropertyChangingEventArgs>(entityType, info); break; case EntityEventType.PropertyChanged: token = RegisterEvent <EntityPropertyChangedEvent, IEntityPropertyChangedEventSubscription, EntityPropertyChangedEventArgs>(entityType, info); break; case EntityEventType.Validating: token = RegisterEvent <EntityValidatingEvent, IEntityValidatingEventSubscription, EntityValidatingEventArgs>(entityType, info); break; case EntityEventType.Validated: token = RegisterEvent <EntityValidatedEvent, IEntityValidatedEventSubscription, EntityValidatedEventArgs>(entityType, info); break; case EntityEventType.Saving: token = RegisterEvent <EntitySavingEvent, IEntitySavingEventSubscription, EntitySavingEventArgs>(entityType, info); break; case EntityEventType.Saved: token = RegisterEvent <EntitySavedEvent, IEntitySavedEventSubscription, EntitySavedEventArgs>(entityType, info); break; case EntityEventType.Deleting: token = RegisterEvent <EntityDeletingEvent, IEntityDeletingEventSubscription, EntityDeletingEventArgs>(entityType, info); break; case EntityEventType.Deleted: token = RegisterEvent <EntityDeletedEvent, IEntityDeletedEventSubscription, EntityDeletedEventArgs>(entityType, info); break; } if (token != null) { List <Domain.SubscriptionToken> tokens = _eventSubscribers[info.EventType]; lock (tokens) tokens.Add(token); } }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="typeName"></param> /// <param name="eventInfo"></param> /// <param name="error"></param> public RegisterEntityEventInfoErrorArgs(Reflection.TypeName typeName, EntityEventInfo eventInfo, Exception error) { this.TypeName = typeName; this.EventInfo = eventInfo; this.Error = error; }
/// <summary> /// Registra o evento para a entidade. /// </summary> /// <typeparam name="TEvent">Tipo da classe do evento.</typeparam> /// <typeparam name="TExecuteSubscription">Tipo da inscrição de execução.</typeparam> /// <typeparam name="TArgs">Tipo dos argumentos do evento.</typeparam> /// <param name="entityType">Nome da entidade associada.</param> /// <param name="info"></param> private Domain.SubscriptionToken RegisterEvent <TEvent, TExecuteSubscription, TArgs>(Reflection.TypeName entityType, EntityEventInfo info) where TEvent : Domain.CompositeDomainEvent <TArgs>, new() where TExecuteSubscription : Domain.IExecuteSubscription <TArgs> where TArgs : IEntityEventArgs { TExecuteSubscription subscription = default(TExecuteSubscription); try { subscription = Extensions.ExtensionServiceLocator.Current.GetInstance <TExecuteSubscription>(info.ExportId); } catch (Exception ex) { ex = new RegisterEntityEventException(ResourceMessageFormatter.Create(() => Properties.Resources.EntityEventManager_GetEventTypeImplementationError, info.EventType.ToString(), entityType, info.ExportId), ex); OnRegisterEventInfoError(entityType, info, ex); return(null); } var subscriptionInfo = new EventSubscriptionInfo <TArgs>(info, entityType, subscription); return(Domain.DomainEvents.Instance.GetEvent <TEvent>().Subscribe(subscriptionInfo.Execute, Domain.DomainEventThreadOption.PublisherThread, true, subscriptionInfo.CanExecute, false, subscriptionInfo.ToString())); }