예제 #1
0
파일: Node.cs 프로젝트: dkschlos/PVM.NET
 protected bool Equals(Node other)
 {
     return string.Equals(Identifier, other.Identifier);
 }
예제 #2
0
        public IWorkflowDefinition LoadWorkflowDefinition(string workflowDefinitionIdentifier)
        {
            IDictionary<string, INode> allNodes = new Dictionary<string, INode>();
            List<INode> endNodes = new List<INode>();

            var initialNodeResult = graphClient.Cypher.Match("(wf:WorkflowDefinition {Identifier: {wfId}})")
                                               .Match("(wf)-[:STARTS_AT]->(initialNode:Node)")
                                               .WithParams(new
                                               {
                                                   wfId = workflowDefinitionIdentifier
                                               })
                                               .ReturnDistinct(initialNode => initialNode.As<NodeModel>());

            var initialNodeModel = initialNodeResult.Results.First();
            INode initial = new Node(initialNodeModel.Identifier, Type.GetType(initialNodeModel.OperationType));
            allNodes.Add(initial.Identifier, initial);
            if (initialNodeModel.IsEndNode)
            {
                endNodes.Add(initial);
            }

            var result = graphClient.Cypher
                                    .Match(
                                        "(source:Node {Identifier: {initialNodeId}})-[transition:TRANSITION*]->(destination:Node)")
                                    .WithParams(new
                                    {
                                        initialNodeId = initialNodeModel.Identifier
                                    })
                                    .ReturnDistinct((source, transition, destination) => new
                                    {
                                        Source = source.As<NodeModel>(),
                                        Transition = transition.As<List<TransitionModel>>(),
                                        Destination = destination.As<NodeModel>()
                                    });


            foreach (var r in result.Results)
            {
                INode source;

                if (allNodes.ContainsKey(r.Source.Identifier))
                {
                    source = allNodes[r.Source.Identifier];
                }
                else
                {
                    source = new Node(r.Source.Identifier, Type.GetType(r.Source.OperationType));
                    allNodes.Add(source.Identifier, source);

                    if (r.Source.IsEndNode && !endNodes.Contains(source))
                    {
                        endNodes.Add(source);
                    }
                }


                if (r.Transition.Count > 1)
                {
                    for (int i = 0; i < r.Transition.Count - 1; i++)
                    {
                        var transitionToTake =
                            source.OutgoingTransitions.First(t => t.Identifier == r.Transition[i].Identifier);
                        source = transitionToTake.Destination;
                    }
                }

                INode destination;

                if (allNodes.ContainsKey(r.Destination.Identifier))
                {
                    destination = allNodes[r.Destination.Identifier];
                }
                else
                {
                    destination = new Node(r.Destination.Identifier, Type.GetType(r.Destination.OperationType));
                    allNodes.Add(destination.Identifier, destination);

                    if (r.Destination.IsEndNode && !endNodes.Contains(destination))
                    {
                        endNodes.Add(destination);
                    }
                }


                var lastTransition = r.Transition.Last();
                var transition = new Transition(lastTransition.Identifier, lastTransition.IsDefault, source,
                    destination);
                source.AddOutgoingTransition(transition);
                destination.AddIncomingTransition(transition);
            }

            var workflowDefinition = new WorkflowDefinition(workflowDefinitionIdentifier,
                new List<INode>(allNodes.Values), endNodes,
                initial);

            // TODO: smells
            workflowDefinition.AddStartTransition();

            return workflowDefinition;
        }
예제 #3
0
        public void SetsCurrentNode()
        {
            var currentNode = new Node("myCurrentNode");

            IExecution result =
                new TestContext().WithCurrentNode("myCurrentNode").WithExistingNode(currentNode).ExecuteTransform();

            Assert.That(result.CurrentNode, Is.SameAs(currentNode));
        }