protected internal override ICollection <MigrationContext> nextElements() { ICollection <MigrationContext> nextElements = new LinkedList <MigrationContext>(); MigrationContext currentElement = CurrentElement; // continue migration for non-leaf instances (i.e. scopes) if (currentElement.processElementInstance is MigratingScopeInstance) { // Child instances share the same scope instance branch; // This ensures "once-per-parent" instantiation semantics, // i.e. if a new parent scope is added to more than one child, all those children // will share the same new parent instance. // By changing the way how the branches are created here, it should be possible // to implement other strategies, e.g. "once-per-child" semantics MigratingScopeInstanceBranch childrenScopeBranch = currentElement.scopeInstanceBranch.copy(); MigratingScopeInstanceBranch childrenCompensationScopeBranch = currentElement.scopeInstanceBranch.copy(); MigratingScopeInstance scopeInstance = (MigratingScopeInstance)currentElement.processElementInstance; childrenScopeBranch.visited(scopeInstance); childrenCompensationScopeBranch.visited(scopeInstance); foreach (MigratingProcessElementInstance child in scopeInstance.Children) { MigratingScopeInstanceBranch instanceBranch = null; // compensation and non-compensation scopes cannot share the same scope instance branch // e.g. when adding a sub process, we want to create a new activity instance as well // as a new event scope instance for that sub process if (child is MigratingEventScopeInstance || child is MigratingCompensationEventSubscriptionInstance) { instanceBranch = childrenCompensationScopeBranch; } else { instanceBranch = childrenScopeBranch; } nextElements.Add(new MigrationContext(child, instanceBranch)); } } return(nextElements); }
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; } }
protected internal virtual void migrateProcessElementInstance(MigratingProcessElementInstance migratingInstance, MigratingScopeInstanceBranch migratingInstanceBranch) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final MigratingScopeInstance parentMigratingInstance = migratingInstance.getParent(); MigratingScopeInstance parentMigratingInstance = migratingInstance.Parent; ScopeImpl sourceScope = migratingInstance.SourceScope; ScopeImpl targetScope = migratingInstance.TargetScope; ScopeImpl targetFlowScope = targetScope.FlowScope; ScopeImpl parentActivityInstanceTargetScope = parentMigratingInstance != null ? parentMigratingInstance.TargetScope : null; if (sourceScope != sourceScope.ProcessDefinition && targetFlowScope != parentActivityInstanceTargetScope) { // create intermediate scopes // 1. manipulate execution tree // determine the list of ancestor scopes (parent, grandparent, etc.) for which // no executions exist yet IList <ScopeImpl> nonExistingScopes = collectNonExistingFlowScopes(targetFlowScope, migratingInstanceBranch); // get the closest ancestor scope that is instantiated already ScopeImpl existingScope = nonExistingScopes.Count == 0 ? targetFlowScope : nonExistingScopes[0].FlowScope; // and its scope instance MigratingScopeInstance ancestorScopeInstance = migratingInstanceBranch.getInstance(existingScope); // Instantiate the scopes as children of the scope execution instantiateScopes(ancestorScopeInstance, migratingInstanceBranch, nonExistingScopes); MigratingScopeInstance targetFlowScopeInstance = migratingInstanceBranch.getInstance(targetFlowScope); // 2. detach instance // The order of steps 1 and 2 avoids intermediate execution tree compaction // which in turn could overwrite some dependent instances (e.g. variables) migratingInstance.detachState(); // 3. attach to newly created activity instance migratingInstance.attachState(targetFlowScopeInstance); } // 4. update state (e.g. activity id) migratingInstance.migrateState(); // 5. migrate instance state other than execution-tree structure migratingInstance.migrateDependentEntities(); }
protected internal abstract void instantiateScopes(MigratingScopeInstance ancestorScopeInstance, MigratingScopeInstanceBranch executionBranch, IList <ScopeImpl> scopesToInstantiate);
/// <summary> /// Returns a list of flow scopes from the given scope until a scope is reached that is already present in the given /// <seealso cref="MigratingScopeInstanceBranch"/> (exclusive). The order of the returned list is top-down, i.e. the highest scope /// is the first element of the list. /// </summary> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: protected java.util.List<org.camunda.bpm.engine.impl.pvm.process.ScopeImpl> collectNonExistingFlowScopes(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl scope, final MigratingScopeInstanceBranch migratingExecutionBranch) protected internal virtual IList <ScopeImpl> collectNonExistingFlowScopes(ScopeImpl scope, MigratingScopeInstanceBranch migratingExecutionBranch) { FlowScopeWalker walker = new FlowScopeWalker(scope); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<org.camunda.bpm.engine.impl.pvm.process.ScopeImpl> result = new java.util.LinkedList<org.camunda.bpm.engine.impl.pvm.process.ScopeImpl>(); IList <ScopeImpl> result = new LinkedList <ScopeImpl>(); walker.addPreVisitor(new TreeVisitorAnonymousInnerClass(this, result)); walker.walkWhile(new WalkConditionAnonymousInnerClass(this, migratingExecutionBranch)); return(result); }
protected internal override void instantiateScopes(MigratingScopeInstance ancestorScopeInstance, MigratingScopeInstanceBranch executionBranch, IList <ScopeImpl> scopesToInstantiate) { if (scopesToInstantiate.Count == 0) { return; } // must always be an activity instance MigratingActivityInstance ancestorActivityInstance = (MigratingActivityInstance)ancestorScopeInstance; ExecutionEntity newParentExecution = ancestorActivityInstance.createAttachableExecution(); IDictionary <PvmActivity, PvmExecutionImpl> createdExecutions = newParentExecution.instantiateScopes((System.Collections.IList)scopesToInstantiate, skipCustomListeners, skipIoMappings); foreach (ScopeImpl scope in scopesToInstantiate) { ExecutionEntity createdExecution = (ExecutionEntity)createdExecutions[scope]; createdExecution.setActivity(null); createdExecution.Active = false; executionBranch.visited(new MigratingActivityInstance(scope, createdExecution)); } }
public MigrationContext(MigratingProcessElementInstance processElementInstance, MigratingScopeInstanceBranch scopeInstanceBranch) { this.processElementInstance = processElementInstance; this.scopeInstanceBranch = scopeInstanceBranch; }