Example #1
0
        protected internal override void instantiateScopes(MigratingScopeInstance ancestorScopeInstance, MigratingScopeInstanceBranch executionBranch, IList <ScopeImpl> scopesToInstantiate)
        {
            if (scopesToInstantiate.Count == 0)
            {
                return;
            }

            ExecutionEntity ancestorScopeExecution = ancestorScopeInstance.resolveRepresentativeExecution();

            ExecutionEntity parentExecution = ancestorScopeExecution;

            foreach (ScopeImpl scope in scopesToInstantiate)
            {
                ExecutionEntity compensationScopeExecution = parentExecution.createExecution();
                compensationScopeExecution.Scope      = true;
                compensationScopeExecution.EventScope = true;

                compensationScopeExecution.setActivity((PvmActivity)scope);
                compensationScopeExecution.Active = false;
                compensationScopeExecution.activityInstanceStarting();
                compensationScopeExecution.enterActivityInstance();

                EventSubscriptionEntity eventSubscription = EventSubscriptionEntity.createAndInsert(parentExecution, EventType.COMPENSATE, (ActivityImpl)scope);
                eventSubscription.Configuration = compensationScopeExecution.Id;

                executionBranch.visited(new MigratingEventScopeInstance(eventSubscription, compensationScopeExecution, scope));

                parentExecution = compensationScopeExecution;
            }
        }
Example #2
0
            protected internal virtual void becomeScope()
            {
                foreach (MigratingInstance dependentInstance in outerInstance.migratingDependentInstances)
                {
                    dependentInstance.detachState();
                }

                ExecutionEntity currentExecution = resolveRepresentativeExecution();

                currentExecution = currentExecution.createExecution();
                ExecutionEntity parent = currentExecution.Parent;

                parent.setActivity(null);

                if (!parent.Concurrent)
                {
                    parent.leaveActivityInstance();
                }

                outerInstance.representativeExecution = currentExecution;
                foreach (MigratingInstance dependentInstance in outerInstance.migratingDependentInstances)
                {
                    dependentInstance.attachState(outerInstance);
                }

                outerInstance.instanceBehavior = new MigratingScopeActivityInstanceBehavior(outerInstance);
            }
Example #3
0
        /// <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       = execution.getActivity();
            ExecutionEntity scopeExecution = (ExecutionEntity)execution.findExecutionForFlowScope(activity.FlowScope);

            IList <EventSubscriptionEntity> eventSubscriptions = execution.CompensateEventSubscriptions;

            if (eventSubscriptions.Count > 0 || hasCompensationEventSubprocess(activity))
            {
                ExecutionEntity eventScopeExecution = scopeExecution.createExecution();
                eventScopeExecution.setActivity(execution.getActivity());
                eventScopeExecution.activityInstanceStarting();
                eventScopeExecution.enterActivityInstance();
                eventScopeExecution.Active     = false;
                eventScopeExecution.Concurrent = false;
                eventScopeExecution.EventScope = 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.SetOfKeyValuePairs())
                {
                    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 (PvmExecutionImpl childEventScopeExecution in execution.EventScopeExecutions)
                {
                    childEventScopeExecution.Parent = eventScopeExecution;
                }

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