public IExecution TransformBack(ExecutionModel model, IWorkflowDefinition workflowDefinition, IExecutionPlan plan) { if (model == null) { return null; } var root = FindRoot(model); var transformedRoot = TransformBack(root, plan, workflowDefinition, null); var collector = new ExecutionCollector(e => e.Identifier == model.Identifier); transformedRoot.Accept(collector); return collector.Result.First(); }
private void PopulateExecutionModel(ExecutionModel model, ExecutionModel transformedParent, IExecution execution) { model.Identifier = execution.Identifier; model.WorkflowInstanceIdentifier = execution.WorkflowInstanceIdentifier; model.WorkflowDefinitionIdentifier = execution.WorkflowDefinition.Identifier; model.IsActive = execution.IsActive; model.IsFinished = execution.IsFinished; model.IncomingTransition = execution.IncomingTransition; model.CurrentNodeIdentifier = execution.CurrentNode == null ? null : execution.CurrentNode.Identifier; model.Parent = transformedParent; model.Children = execution.Children.Select(c => (ExecutionModel) CreateExecutionModel((dynamic) c, model)).ToList(); model.Variables = execution.Data.Select(entry => new ExecutionVariableModel { VariableKey = entry.Key, SerializedValue = serializer.Serialize(entry.Value), ValueType = entry.Value.GetType().AssemblyQualifiedName }).ToList(); }
protected bool Equals(ExecutionModel other) { return string.Equals(Identifier, other.Identifier); }
public IExecution ExecuteTransform(ExecutionModel executionModel) { var transformer = new Transform.ExecutionDefinitionTransformer(objectSerializer); return transformer.TransformBack(executionModel, workflowDefinition.Object, plan.Object); }
public void AddsParent() { ExecutionModel parent = new ExecutionModel(); var child = new ExecutionModel() { Children = new List<ExecutionModel>(), Variables = new List<ExecutionVariableModel>(), Parent = parent, Identifier = "child" }; parent.Children = new List<ExecutionModel>() {child}; parent.Variables = new List<ExecutionVariableModel>(); parent.Identifier = "parentId"; IExecution result = new TestContext() .ExecuteTransform(child); Assert.That(result.Parent.Identifier, Is.EqualTo("parentId")); }
private IExecution TransformBack(ExecutionModel model, IExecutionPlan plan, IWorkflowDefinition workflowDefinition, IExecution parent) { IDictionary<string, object> data = new Dictionary<string, object>(); foreach (var variable in model.Variables) { data.Add(variable.VariableKey, serializer.Deserialize(variable.SerializedValue, Type.GetType(variable.ValueType))); } IList<IExecution> children = new List<IExecution>(); var execution = new Execution(parent, workflowDefinition.Nodes.FirstOrDefault(n => n.Identifier == model.CurrentNodeIdentifier), model.IsActive, model.IsFinished, data, model.IncomingTransition, model.Identifier, model.WorkflowInstanceIdentifier, plan, children, workflowDefinition); foreach (var child in model.Children) { children.Add(TransformBack(child, plan, workflowDefinition, execution)); } return execution; }
private ExecutionModel CreateExecutionModel(IExecution execution, ExecutionModel transformedParent) { var executionModel = new ExecutionModel(); PopulateExecutionModel(executionModel, transformedParent, execution); return executionModel; }
private ExecutionModel FindModel(ExecutionModel root, string identifier) { if (root.Identifier == identifier) { return root; } foreach (var child in root.Children) { var found = FindModel(child, identifier); if (found != null) { return found; } } return null; }
private ExecutionModel FindRoot(ExecutionModel model) { if (model.Parent == null) { return model; } return FindRoot(model.Parent); }