Exemple #1
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       = (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;
            }
        }
            public override object Execute(CommandContext commandContext)
            {
                ExecutionEntity execution = commandContext.ExecutionManager.FindExecutionById(executionId);

                // fetch the variable instance but not the value (make sure the byte array is lazily fetched)
                VariableInstanceEntity varInstance = (VariableInstanceEntity)execution.GetVariableInstanceLocal(varName);
                string byteArrayValueId            = varInstance.ByteArrayId;

                Assert.NotNull("Byte array id is expected to be not null", byteArrayValueId);

                var cachedByteArray = commandContext.ByteArrayManager.Get(byteArrayValueId);

                Assert.IsNull(cachedByteArray, "Byte array is expected to be not fetched yet / lazily fetched.");

                Monitor.Sync();

                // now update the value
                execution.SetVariableLocal(varInstance.Name, newValue);

                return(null);
            }