コード例 #1
0
ファイル: CompensationUtil.cs プロジェクト: zf321/ESS.FW.Bpm
        /// <summary>
        ///     creates an event scope for the given execution:
        ///     create a new event scope execution under the parent of the given execution
        ///     and move all event subscriptions to that execution.
        ///     this allows us to "remember" the event subscriptions after finishing a
        ///     scope
        /// </summary>
        public static void CreateEventScopeExecution(ExecutionEntity execution)
        {
            // parent execution is a subprocess or a miBody
            ActivityImpl    activity       = (ActivityImpl)execution.Activity;
            ExecutionEntity scopeExecution = (ExecutionEntity)execution.FindExecutionForFlowScope(activity.FlowScope);

            IList <EventSubscriptionEntity> eventSubscriptions = execution.CompensateEventSubscriptions;

            if (eventSubscriptions.Count > 0 || HasCompensationEventSubprocess(activity))
            {
                ExecutionEntity eventScopeExecution = scopeExecution.CreateExecution();
                eventScopeExecution.Activity = (execution.Activity);
                eventScopeExecution.ActivityInstanceStarting();
                eventScopeExecution.EnterActivityInstance();
                eventScopeExecution.IsActive     = false;
                eventScopeExecution.IsConcurrent = false;
                eventScopeExecution.IsEventScope = true;

                // copy local variables to eventScopeExecution by value. This way,
                // the eventScopeExecution references a 'snapshot' of the local variables
                IDictionary <string, object> variables = execution.VariablesLocal;
                foreach (KeyValuePair <string, object> variable in variables)
                {
                    eventScopeExecution.SetVariableLocal(variable.Key, variable.Value);
                }

                // set event subscriptions to the event scope execution:
                foreach (EventSubscriptionEntity eventSubscriptionEntity in eventSubscriptions)
                {
                    EventSubscriptionEntity newSubscription = EventSubscriptionEntity.CreateAndInsert(eventScopeExecution, EventType.Compensate, eventSubscriptionEntity.Activity);
                    newSubscription.Configuration = eventSubscriptionEntity.Configuration;
                    // use the original date
                    newSubscription.Created = eventSubscriptionEntity.Created;
                }

                // set existing event scope executions as children of new event scope execution
                // (ensuring they don't get removed when 'execution' gets removed)
                foreach (var childEventScopeExecution in execution.EventScopeExecutions)
                {
                    childEventScopeExecution.Parent = eventScopeExecution;
                }

                ActivityImpl            compensationHandler = getEventScopeCompensationHandler(execution);
                EventSubscriptionEntity eventSubscription   = EventSubscriptionEntity.CreateAndInsert(scopeExecution, EventType.Compensate, compensationHandler);
                eventSubscription.Configuration = eventScopeExecution.Id;
            }
        }