public void ChangeObserved(DataEventArgs @event) { log4net.LogicalThreadContext.Properties["TransactionId"] = @event.SourceTransactionId; _log.Debug($"Change Observed Event='{@event.SourceApiName}'"); OperationStartedEvent?.Invoke(Operation.ChangeObserved, @event.SourceTransactionId, @event, null); //Find all subscribers and then put the notification in the queue using (var subscriberQueue = DependencyContainer.Resolve <ISubscriberQueue>()) { var allSubscribers = GetSubscriberForEvent(@event.SourceApiName); if (allSubscribers == null) { _log.Warn($"No subscribers found for the SourceApiName={@event.SourceApiName}. Maybe it is disabled? This event will now be considered as handled so it does not fill up the queue."); } else { //For each subscriber referenced put the notification in the queue. foreach (var subscriber in allSubscribers) { subscriberQueue.SubscriberNotification(new SubscriberNotification() { Event = @event, CreatedDate = DateTime.Now, Subscriber = subscriber }); } } } OperationEndedEvent?.Invoke(Operation.ChangeObserved, @event.SourceTransactionId, null, @event, null); }
public void SubscriberNotification(SubscriberNotification notification) { log4net.LogicalThreadContext.Properties["TransactionId"] = notification.Event.SourceTransactionId; _log.Info($"Notifying Subscriber='{notification.Subscriber.SubscriberName}' via Workflow='{notification.Subscriber.WorkFlowType.FullName}' IdleAction={IdleAction}"); using (ApplicationHelper application = new ApplicationHelper(notification.Subscriber.GetActivity(), notification.Subscriber.GetIdentity(), notification.Event, notification.Subscriber)) { application.IdleAction = IdleAction; if (OperationEndedEvent != null) { application.ActivityStartedEvent += (Guid instanceId, System.Activities.Activity activity) => { OperationStartedEvent?.Invoke(Operation.SubscriberNotification, notification.Event.SourceTransactionId, notification, instanceId.ToString()); }; application.ActivityUnhandledExceptionEvent += (System.Activities.WorkflowApplicationUnhandledExceptionEventArgs args) => { OperationEndedEvent?.Invoke(Operation.SubscriberNotification, notification.Event.SourceTransactionId, args.UnhandledException, notification, args.InstanceId.ToString()); }; application.ActivityCompletedEvent += (System.Activities.WorkflowApplicationCompletedEventArgs args) => { OperationEndedEvent?.Invoke(Operation.SubscriberNotification, notification.Event.SourceTransactionId, null, notification, args.InstanceId.ToString()); }; } application.Run(); } }