예제 #1
0
        /// <summary>
        /// Helper method, that sets the scope decision entry and exit nodes.
        /// If source vertex is scope and target vertex is exit decision node, it sets that source scope vertex ExitDecisionNode property to the given target exit node.
        /// Similarly, if target vertex is a scope node, and source vertex is decision, it sets that target scope vertex Decision property to the given source decision node.
        /// </summary>
        /// <param name="sourceVert">The source vert.</param>
        /// <param name="targetVert">The target vert.</param>
        public static void TryFixScopeDecisionEntryAndExitNodes(ExperimentNode sourceVert, ExperimentNode targetVert)
        {
            //case 1: sourceVert is ScopeNode, and target is ExitDecisionNode
            ScopeNode scopeNode = sourceVert as ScopeNode;

            if (scopeNode != null)
            {
                ExitDecisionNode exitDecisionNode = targetVert as ExitDecisionNode;
                if (exitDecisionNode != null)
                {
                    scopeNode.ExitDecisionNode = exitDecisionNode;
                }
            }
            else
            {
                //case 2: targetNode is ScopeNode, and source is DecisionNode
                scopeNode = targetVert as ScopeNode;
                if (scopeNode != null)
                {
                    ExperimentDecisionNode decisionNode = sourceVert as ExperimentDecisionNode;
                    if (decisionNode != null)
                    {
                        scopeNode.DecisionNode = decisionNode;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Generates the correct node based on metadata contained in serialized vertex data
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>Experiment node</returns>
        private ExperimentNode NodeGenerator(string id, SerializedVertexData nodeData)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (nodeData == null)
            {
                throw new ArgumentNullException("nodeData");
            }

            ExperimentNode node;

            if (nodeData.Metadata is StartNodeMetadata)
            {
                node = new ExperimentStartNode(id, nodeData);
            }
            else if (nodeData.Metadata is EndNodeMetadata)
            {
                node = new ExperimentEndNode(id, nodeData);
            }
            else if (nodeData.Metadata is DecisionMetadata)
            {
                node = new ExperimentDecisionNode(id, nodeData);
            }
            else if (nodeData.Metadata is ScopeMetadata)
            {
                node = new ScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is LoopScopeMetadata)
            {
                node = new LoopScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is CompositeComponentMetadata)
            {
                node = new CompositeComponentNode(id, nodeData);
            }
            else if (nodeData.Metadata is ExitDecisionMetadata)
            {
                node = new ExitDecisionNode(id, nodeData);
            }
            else
            {
                ComponentNode componentNode = new ComponentNode(id, nodeData);
                node = componentNode;
            }

            return(node);
        }
예제 #3
0
        /// <summary>
        /// Creates the decision component.
        /// </summary>
        /// <param name="experiment">The experiment to which new component is added.</param>
        /// <param name="decisionMetadataDefinition">The decision metadata definition.</param>
        /// <param name="data">The data containing position of new vertex</param>
        /// <returns>Newly added desicion node (note, that in case of decision additional nodes are constructed, two scopes and exit decision node). They are not returned.</returns>
        private static ExperimentDecisionNode CreateDecisionComponent(IEditableExperiment experiment, DecisionMetadataDefinition decisionMetadataDefinition, SerializedVertexData data)
        {
            data.Metadata = new DecisionMetadata(decisionMetadataDefinition.Label);

            ExperimentDecisionNode decisionNode = new ExperimentDecisionNode(Guid.NewGuid().ToString(), data);

            experiment.AddVertex(decisionNode);

            if (decisionMetadataDefinition.ID == DecisionMetadataDefinition.DecisionGuid)
            {
                //generate corresponding scopes and exit nodes
                GenerateScopesAndExit(experiment, data, decisionNode);
            }
            //otherwise it is GoTo decision that does not have corresponding scopes, so simply return it

            return(decisionNode);
        }
        /// <summary>
        /// Adds a new decision node at the specified coordinates
        /// </summary>
        public ExperimentDecisionNode AddDecisionToExperiment(Experiment experiment, double positionX, double positionY)
        {
            ExperimentDecisionNode newNode = null;

            SerializedVertexData data = new SerializedVertexData();
            data.X = positionX;
            data.Y = positionY;
            data.Metadata = new DecisionMetadata("Decision");

            newNode = new ExperimentDecisionNode(Guid.NewGuid().ToString(), data);
            experiment.AddVertex(newNode);

            return newNode;
        }
예제 #5
0
 /// <summary>
 /// If the given decision node is not null, the method updates its code by replacing templateNodeLabel with replacementNodeLabel
 /// of all Select(" label ") statements in the decision code.
 /// </summary>
 /// <param name="templateNodeLabel">The template node label.</param>
 /// <param name="replacementNodeLabel">The replacement node label.</param>
 /// <param name="decisionNode">The decision node.</param>
 private static void FixDecisionCode(string templateNodeLabel, string replacementNodeLabel, ExperimentDecisionNode decisionNode)
 {
     if (decisionNode != null)
     {
         string decisionCode = ((DecisionMetadata)decisionNode.Data.Metadata).DecisionCode;
         string selectStatementOldLabel = string.Format("Select(\"{0}\")", templateNodeLabel);
         if (decisionCode.Contains(selectStatementOldLabel))
         {
             //replace old label with new label of Select("...") statements;
             string selectStatementNewLabel = string.Format("Select(\"{0}\")", replacementNodeLabel);
             decisionCode = decisionCode.Replace(selectStatementOldLabel, selectStatementNewLabel);
             ((DecisionMetadata)decisionNode.Data.Metadata).DecisionCode = decisionCode;
         }
     }
 }
        /// <summary>
        /// Determines whether the given decision is an old version decision.
        /// Previously decisions were independent nodes without scopes and corresponding exit node.
        /// Thus for old decisions we want to choose another template.
        /// </summary>
        /// <param name="decisionNode">The decision node.</param>
        /// <returns>
        ///   <c>true</c> if the specified decision node is old decision; otherwise, <c>false</c>.
        /// </returns>
        private static bool IsGotoDecision(ExperimentDecisionNode decisionNode)
        {
            IEditableExperiment experiment = decisionNode.Owner as IEditableExperiment;

            IEnumerable<ExperimentNodeConnection> outEdges;
            if (experiment.TryGetOutEdges(decisionNode, out outEdges))
            {
                foreach (ExperimentNodeConnection connection in outEdges)
                {
                    if (connection.Target is ExitDecisionNode)
                    {
                        return false;
                    }
                }
            }
            
            return true;
        }
예제 #7
0
        /// <summary>
        /// Adds the scope to decision.
        /// Default scope size is 160 by 160
        /// </summary>
        /// <param name="label">The label.</param>
        /// <param name="positionX">The center X position of the scope.</param>
        /// <param name="positionY">The center Y position of the scope.</param>
        /// <param name="decisionNode">The decision node.</param>
        /// <param name="exitDecisionNode">The exit decision node.</param>
        /// <param name="experiment">The experiment.</param>
        public static void AddScopeToDecision(string label, double positionX, double positionY, ExperimentDecisionNode decisionNode, ExitDecisionNode exitDecisionNode, IEditableExperiment experiment, double width = 160, double height = 160)
        {
            ScopeNode scopeNode = GenerateScopeNode(label, experiment, positionX, positionY, width, height);

            //set decision and exit decision references
            //(also note that ExperimentFactory also sets it when deseralizing experiment)
            scopeNode.DecisionNode     = decisionNode;
            scopeNode.ExitDecisionNode = exitDecisionNode;

            experiment.AddVertex(scopeNode);
            experiment.AddFixedConnection(decisionNode, scopeNode, true);
            experiment.AddFixedConnection(scopeNode, exitDecisionNode, true);

            experiment.SetLogLevelSettings(scopeNode);
        }
예제 #8
0
        private static void GenerateScopesAndExit(IEditableExperiment experiment, SerializedVertexData data, ExperimentDecisionNode decisionNode)
        {
            ExitDecisionNode exitDecisionNode = GenerateExitDecisionNode(data.X, data.Y + 240);

            experiment.AddVertex(exitDecisionNode);

            //add invisible fixed connection between decision and exit - so that if scope can be skipped upon condition
            experiment.AddFixedConnection(decisionNode, exitDecisionNode, true);

            //set the log settings of all new nodes
            experiment.SetLogLevelSettings(decisionNode);
            experiment.SetLogLevelSettings(exitDecisionNode);

            AddScopeToDecision("Scope 1", data.X - 90, data.Y + 120, decisionNode, exitDecisionNode, experiment);
            AddScopeToDecision("Scope 2", data.X + 90, data.Y + 120, decisionNode, exitDecisionNode, experiment);
        }
예제 #9
0
        /// <summary>
        /// Generates the correct node based on metadata contained in serialized vertex data
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>Experiment node</returns>
        private ExperimentNode NodeGenerator(string id, SerializedVertexData nodeData)
        {
            if (id == null)
                throw new ArgumentNullException("id");
            if (nodeData == null)
                throw new ArgumentNullException("nodeData");

            ExperimentNode node;

            if (nodeData.Metadata is StartNodeMetadata)
            {
                node = new ExperimentStartNode(id, nodeData);
            }
            else if (nodeData.Metadata is EndNodeMetadata)
            {
                node = new ExperimentEndNode(id, nodeData);
            }
            else if (nodeData.Metadata is DecisionMetadata)
            {
                node = new ExperimentDecisionNode(id, nodeData);
            }
            else if (nodeData.Metadata is ScopeMetadata)
            {
                node = new ScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is LoopScopeMetadata)
            {
                node = new LoopScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is CompositeComponentMetadata)
            {
                node = new CompositeComponentNode(id, nodeData);
            }
            else if (nodeData.Metadata is ExitDecisionMetadata)
            {
                node = new ExitDecisionNode(id, nodeData);
            }
            // HERZUM SPRINT 1.0
            else if (nodeData.Metadata is CommentMetadata)
            {
                // HERZUM SPRINT 1.2
                // node = new CommentNode(id, nodeData);
                node = new CommentNode(id, (SerializedVertexDataWithSize) nodeData);
                // END HERZUM SPRINT 1.2
            }
            // END HERZUM SPRINT 1.0
            // HERZUM SPRINT 2.0: TLAB-65 CLASS
            else if (nodeData.Metadata is ChallengeMetadata)
            {
                node = new ChallengeNode(id, (SerializedVertexDataWithSize) nodeData);
            }
            // END HERZUM SPRINT 2.0: TLAB-65 CLASS
            else
            {
                ComponentNode componentNode = new ComponentNode(id, nodeData);
                node = componentNode;
            }

            return node;
        }
예제 #10
0
        /// <summary>
        /// Generates the correct node based on metadata contained in serialized vertex data
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>Experiment node</returns>
        private ExperimentNode NodeGenerator(string id, SerializedVertexData nodeData)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (nodeData == null)
            {
                throw new ArgumentNullException("nodeData");
            }

            ExperimentNode node;

            if (nodeData.Metadata is StartNodeMetadata)
            {
                node = new ExperimentStartNode(id, nodeData);
            }
            else if (nodeData.Metadata is EndNodeMetadata)
            {
                node = new ExperimentEndNode(id, nodeData);
            }
            else if (nodeData.Metadata is DecisionMetadata)
            {
                node = new ExperimentDecisionNode(id, nodeData);
            }
            else if (nodeData.Metadata is ScopeMetadata)
            {
                node = new ScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is LoopScopeMetadata)
            {
                node = new LoopScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is CompositeComponentMetadata)
            {
                node = new CompositeComponentNode(id, nodeData);
            }
            else if (nodeData.Metadata is ExitDecisionMetadata)
            {
                node = new ExitDecisionNode(id, nodeData);
            }
            // HERZUM SPRINT 1.0
            else if (nodeData.Metadata is CommentMetadata)
            {
                // HERZUM SPRINT 1.2
                // node = new CommentNode(id, nodeData);
                node = new CommentNode(id, (SerializedVertexDataWithSize)nodeData);
                // END HERZUM SPRINT 1.2
            }
            // END HERZUM SPRINT 1.0
            // HERZUM SPRINT 2.0: TLAB-65 CLASS
            else if (nodeData.Metadata is ChallengeMetadata)
            {
                node = new ChallengeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            // END HERZUM SPRINT 2.0: TLAB-65 CLASS
            else
            {
                ComponentNode componentNode = new ComponentNode(id, nodeData);
                node = componentNode;
            }

            return(node);
        }
        /// <summary>
        /// Adds the scope to decision.
        /// Default scope size is 160 by 160
        /// </summary>
        /// <param name="label">The label.</param>
        /// <param name="positionX">The center X position of the scope.</param>
        /// <param name="positionY">The center Y position of the scope.</param>
        /// <param name="decisionNode">The decision node.</param>
        /// <param name="exitDecisionNode">The exit decision node.</param>
        /// <param name="experiment">The experiment.</param>
        public static void AddScopeToDecision(string label, double positionX, double positionY, ExperimentDecisionNode decisionNode, ExitDecisionNode exitDecisionNode, IEditableExperiment experiment, double width = 160, double height = 160)
        {
            ScopeNode scopeNode = GenerateScopeNode(label, experiment, positionX, positionY, width, height);
            
            //set decision and exit decision references
            //(also note that ExperimentFactory also sets it when deseralizing experiment)
            scopeNode.DecisionNode = decisionNode;
            scopeNode.ExitDecisionNode = exitDecisionNode;
            
            experiment.AddVertex(scopeNode);
            experiment.AddFixedConnection(decisionNode, scopeNode, true);
            experiment.AddFixedConnection(scopeNode, exitDecisionNode, true);

            experiment.SetLogLevelSettings(scopeNode);
        }
        private static void GenerateScopesAndExit(IEditableExperiment experiment, SerializedVertexData data, ExperimentDecisionNode decisionNode)
        {
            ExitDecisionNode exitDecisionNode = GenerateExitDecisionNode(data.X, data.Y + 240);
            experiment.AddVertex(exitDecisionNode);

            //add invisible fixed connection between decision and exit - so that if scope can be skipped upon condition
            experiment.AddFixedConnection(decisionNode, exitDecisionNode, true);

            //set the log settings of all new nodes
            experiment.SetLogLevelSettings(decisionNode);
            experiment.SetLogLevelSettings(exitDecisionNode);

            AddScopeToDecision("Scope 1", data.X - 90, data.Y + 120, decisionNode, exitDecisionNode, experiment);
            AddScopeToDecision("Scope 2", data.X + 90, data.Y + 120, decisionNode, exitDecisionNode, experiment);
        }
        /// <summary>
        /// Creates the decision component.
        /// </summary>
        /// <param name="experiment">The experiment to which new component is added.</param>
        /// <param name="decisionMetadataDefinition">The decision metadata definition.</param>
        /// <param name="data">The data containing position of new vertex</param>
        /// <returns>Newly added desicion node (note, that in case of decision additional nodes are constructed, two scopes and exit decision node). They are not returned.</returns>
        private static ExperimentDecisionNode CreateDecisionComponent(IEditableExperiment experiment, DecisionMetadataDefinition decisionMetadataDefinition, SerializedVertexData data)
        {
            data.Metadata = new DecisionMetadata(decisionMetadataDefinition.Label);
            
            ExperimentDecisionNode decisionNode = new ExperimentDecisionNode(Guid.NewGuid().ToString(), data);
            experiment.AddVertex(decisionNode);

            if (decisionMetadataDefinition.ID == DecisionMetadataDefinition.DecisionGuid)
            {
                //generate corresponding scopes and exit nodes
                GenerateScopesAndExit(experiment, data, decisionNode);
            }
            //otherwise it is GoTo decision that does not have corresponding scopes, so simply return it

            return decisionNode;
        }
        /// <summary>
        /// Generates the correct node based on metadata contained in serialized vertex data
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="nodeData">The node data.</param>
        /// <returns>Experiment node</returns>
        private ExperimentNode NodeGenerator(string id, SerializedVertexData nodeData)
        {
            if (id == null)
                throw new ArgumentNullException("id");
            if (nodeData == null)
                throw new ArgumentNullException("nodeData");

            ExperimentNode node;

            if (nodeData.Metadata is StartNodeMetadata)
            {
                node = new ExperimentStartNode(id, nodeData);
            }
            else if (nodeData.Metadata is EndNodeMetadata)
            {
                node = new ExperimentEndNode(id, nodeData);
            }
            else if (nodeData.Metadata is DecisionMetadata)
            {
                node = new ExperimentDecisionNode(id, nodeData);
            }
            else if (nodeData.Metadata is ScopeMetadata)
            {
                node = new ScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is LoopScopeMetadata)
            {
                node = new LoopScopeNode(id, (SerializedVertexDataWithSize)nodeData);
            }
            else if (nodeData.Metadata is CompositeComponentMetadata)
            {
                node = new CompositeComponentNode(id, nodeData);
            }
            else if (nodeData.Metadata is ExitDecisionMetadata)
            {
                node = new ExitDecisionNode(id, nodeData);
            }
            else
            {
                ComponentNode componentNode = new ComponentNode(id, nodeData);
                node = componentNode;
            }

            return node;
        }