Exemplo n.º 1
0
        /// <summary>
        /// Copies data into this experiment from another given experiment
        /// </summary>
        /// <param name="other">The other experiment from which data is copied.</param>
        protected virtual void CopyFrom(BaseExperiment other)
        {
            // Clone experiment info.
            this.m_experimentInfo = other.m_experimentInfo.Clone();

            // Clone vertices
            Dictionary <ExperimentNode, ExperimentNode> clonedNodeLookup = new Dictionary <ExperimentNode, ExperimentNode>();

            foreach (ExperimentNode node in other.Vertices)
            {
                var clonedNode = node.Clone();
                clonedNodeLookup[node] = clonedNode;
                SetLogLevelSettings(clonedNode, Settings);
                AddVertex(clonedNode);
            }

            // Populate our Start and End node properties - this can only be done after the vertices are added.
            ReloadStartAndEndNode();

            // Clone edges
            foreach (ExperimentNodeConnection connection in other.Edges)
            {
                ExperimentNode           cloneSource      = clonedNodeLookup[connection.Source];
                ExperimentNode           cloneTarget      = clonedNodeLookup[connection.Target];
                ExperimentNodeConnection clonedConnection = new ExperimentNodeConnection(connection.ID, cloneSource, cloneTarget, connection.IsFixed, connection.IsVisible);
                //copy also all route points
                clonedConnection.RoutePoints.CopyPointsFrom(connection.RoutePoints);

                AddEdge(clonedConnection);

                //special case - fix scope node references
                ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(cloneSource, cloneTarget);
            }

            // Do deep copy of errors.
            this.m_errors = new ObservableDictionary <ExperimentNode, ExperimentNodeError>();
            foreach (KeyValuePair <ExperimentNode, ExperimentNodeError> pair in other.m_errors)
            {
                m_errors[clonedNodeLookup[pair.Key]] = new ExperimentNodeError(pair.Value.ErrorMessage, pair.Value.ErrorType);
            }

            if (other.References != null)
            {
                if (!RuntimeInfo.IsRunInMono)
                {
                    References = new ObservableCollection <TraceLabSDK.PackageSystem.IPackageReference>(other.References);
                }
                else
                {
                    // Mono currently has not implemented constructor of ObservableCollection(IEnumerable<T> collection)
                    // thus we have to add references manually
                    References = new ObservableCollection <TraceLabSDK.PackageSystem.IPackageReference>();
                    foreach (TraceLabSDK.PackageSystem.IPackageReference reference in other.References)
                    {
                        References.Add(reference);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Copies data into this experiment from another given experiment
        /// </summary>
        /// <param name="other">The other experiment from which data is copied.</param>
        protected virtual void CopyFrom(BaseExperiment other)
        {
            // Clone experiment info.
            this.m_experimentInfo = other.m_experimentInfo.Clone();

            // Clone vertices
            Dictionary <ExperimentNode, ExperimentNode> clonedNodeLookup = new Dictionary <ExperimentNode, ExperimentNode>();

            foreach (ExperimentNode node in other.Vertices)
            {
                var clonedNode = node.Clone();
                clonedNodeLookup[node] = clonedNode;
                SetLogLevelSettings(clonedNode, Settings);
                AddVertex(clonedNode);
            }

            // Populate our Start and End node properties - this can only be done after the vertices are added.
            ReloadStartAndEndNode();

            // Clone edges
            foreach (ExperimentNodeConnection connection in other.Edges)
            {
                ExperimentNode           cloneSource      = clonedNodeLookup[connection.Source];
                ExperimentNode           cloneTarget      = clonedNodeLookup[connection.Target];
                ExperimentNodeConnection clonedConnection = new ExperimentNodeConnection(connection.ID, cloneSource, cloneTarget, connection.IsFixed, connection.IsVisible);
                //copy also all route points
                clonedConnection.RoutePoints.CopyPointsFrom(connection.RoutePoints);

                AddEdge(clonedConnection);

                //special case - fix scope node references
                ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(cloneSource, cloneTarget);
            }

            // Do deep copy of errors.
            this.m_errors = new ObservableDictionary <ExperimentNode, ExperimentNodeError>();
            foreach (KeyValuePair <ExperimentNode, ExperimentNodeError> pair in other.m_errors)
            {
                m_errors[clonedNodeLookup[pair.Key]] = new ExperimentNodeError(pair.Value.ErrorMessage, pair.Value.ErrorType);
            }

            if (other.References != null)
            {
                References = other.References.CopyCollection();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs experiment node connection from given xml xpath navigator to the edge.
        /// </summary>
        /// <param name="reader">The reader with edge root.</param>
        /// <returns>experiment node connection</returns>
        public ExperimentNodeConnection EdgeFactory(XPathNavigator reader)
        {
            string id     = reader.GetAttribute("id", String.Empty);
            string source = reader.GetAttribute("source", String.Empty);
            string target = reader.GetAttribute("target", String.Empty);

            //try read is fixed attribute
            string isFixedAttrib = reader.GetAttribute("isFixed", String.Empty);
            bool   isFixed;

            if (!Boolean.TryParse(isFixedAttrib, out isFixed))
            {
                isFixed = false;
            }

            //try read is visible attribute
            string isVisibleAttrib = reader.GetAttribute("isVisible", String.Empty);
            bool   isVisible;

            if (!Boolean.TryParse(isVisibleAttrib, out isVisible))
            {
                isVisible = true;
            }

            //validate
            if (m_vertices.ContainsKey(source) == false || m_vertices.ContainsKey(target) == false)
            {
                throw new TraceLab.Core.Exceptions.ExperimentLoadException("The experiment is corrupted and could not be loaded. Experiment xml contains edge that refers to non-existing nodes.");
            }
            ExperimentNode sourceVert = m_vertices[source];
            ExperimentNode targetVert = m_vertices[target];

            ExperimentNodeConnection edge = new ExperimentNodeConnection(id, sourceVert, targetVert, isFixed, isVisible);

            edge.IsModified = false;
            m_edges[id]     = edge;

            //read in route points from xml
            edge.RoutePoints.ReadXml(reader.ReadSubtree());

            //perform fixes for scopes
            ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(sourceVert, targetVert);

            return(edge);
        }
Exemplo n.º 4
0
        // END HERZUM SPRINT 4.0: TLAB-204

        #region Create Composite Component

        /// <summary>
        /// Constructs the graph from selected nodes of the given experiment graph.
        /// </summary>
        /// <param name="graph">The graph.</param>
        /// <returns></returns>
        public static CompositeComponentGraph ConstructGraphFromSelectedNodes(BaseExperiment originalExperiment)
        {
            var compositeComponentGraph = new CompositeComponentGraph();

            // Clone experiment info.
            compositeComponentGraph.ExperimentInfo = new ExperimentInfo();

            AssureCompleteDecisionSelection(originalExperiment);

            //keep lookup from original node to its clone for later edge reproduction
            Dictionary <ExperimentNode, ExperimentNode> clonedNodeLookup = new Dictionary <ExperimentNode, ExperimentNode>();

            // Clone vertices that are selected and add them to the composite component graph
            foreach (ExperimentNode node in originalExperiment.Vertices)
            {
                if (node.IsSelected)
                {
                    var clonedNode = node.Clone();
                    clonedNodeLookup[node] = clonedNode;
                    compositeComponentGraph.SetLogLevelSettings(clonedNode, compositeComponentGraph.Settings);

                    compositeComponentGraph.AddVertex(clonedNode);

                    if (clonedNode.ID == "Start" && compositeComponentGraph.StartNode == null)
                    {
                        compositeComponentGraph.StartNode = (ExperimentStartNode)clonedNode;
                    }
                    else if (clonedNode.ID == "End" && compositeComponentGraph.EndNode == null)
                    {
                        compositeComponentGraph.EndNode = (ExperimentEndNode)clonedNode;
                    }
                }
            }

            // Clone edges
            foreach (ExperimentNodeConnection connection in originalExperiment.Edges)
            {
                ExperimentNode cloneSourceNode, cloneTargetNode;

                //add edges only if both source and target nodes has been found in clones lookup
                bool foundSourceNode = clonedNodeLookup.TryGetValue(connection.Source, out cloneSourceNode);
                bool foundTargetNode = clonedNodeLookup.TryGetValue(connection.Target, out cloneTargetNode);
                if (foundSourceNode && foundTargetNode)
                {
                    ExperimentNodeConnection clonedConnection = new ExperimentNodeConnection(connection.ID, cloneSourceNode, cloneTargetNode, connection.IsFixed, connection.IsVisible);
                    //copy also all route points
                    clonedConnection.RoutePoints.CopyPointsFrom(connection.RoutePoints);

                    compositeComponentGraph.AddEdge(clonedConnection);

                    //perform fixes for scopes
                    ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(cloneSourceNode, cloneTargetNode);
                }
            }

            ConnectNodesToStartAndEndNode(compositeComponentGraph);

            //move graph closer to the origin point
            TraceLab.Core.Utilities.ExperimentHelper.MoveGraphCloserToOriginPoint(compositeComponentGraph, 200, 200);

            if (originalExperiment.References != null)
            {
                compositeComponentGraph.References = originalExperiment.References.CopyCollection();
            }

            compositeComponentGraph.OwnerNode = null;

            return(compositeComponentGraph);
        }
Exemplo n.º 5
0
        public void CopyAndAdd(CompositeComponentGraph subExperiment, double x, double y, bool first)
        {
            if (subExperiment == null)
            {
                return;
            }

            if (subExperiment.IsVerticesEmpty)
            {
                return;
            }

            bool   firstNode = true;
            double minX      = 0;
            double minY      = 0;
            double offsetX   = 0;
            double offsetY   = 0;

            if (first)
            {
                foreach (ExperimentNode node in subExperiment.Vertices)
                {
                    // HERZUM SPRINT 2.6 TLAB-175
                    // if (node.ID != "Start" && node.ID != "End"){
                    if ((node.ID != "Start" && node.ID != "End") && !(first && (node is ExperimentStartNode || node is ExperimentEndNode)))
                    {
                        // END HERZUM SPRINT 2.6 TLAB-175
                        if (firstNode)
                        {
                            minX      = node.Data.X;
                            minY      = node.Data.Y;
                            firstNode = false;
                        }
                        else
                        {
                            if (node.Data.X < minX)
                            {
                                minX = node.Data.X;
                            }
                            if (node.Data.Y < minY)
                            {
                                minY = node.Data.Y;
                            }
                        }
                    }
                }
            }

            offsetX = x - minX;
            offsetY = y - minY;

            //keep lookup from original node to its clone for later edge reproduction
            Dictionary <ExperimentNode, ExperimentNode> clonedNodeLookup = new Dictionary <ExperimentNode, ExperimentNode>();

            // Clone vertices and add them to the composite component graph
            foreach (ExperimentNode node in subExperiment.Vertices)
            {
                // HERZUM SPRINT 2.6 TLAB-175
                // if (node.ID != "Start" && node.ID != "End")
                if ((node.ID != "Start" && node.ID != "End") && !(first && (node is ExperimentStartNode || node is ExperimentEndNode)))
                // END HERZUM SPRINT 2.6 TLAB-175
                {
                    var clonedNode = node.Clone();
                    clonedNode.ID = Guid.NewGuid().ToString();
                    SetLogLevelSettings(clonedNode, Settings);
                    clonedNodeLookup[node] = clonedNode;

                    clonedNode.Owner = this;

                    if (first)
                    {
                        clonedNode.Data.X = clonedNode.Data.X + offsetX;
                        clonedNode.Data.Y = clonedNode.Data.Y + offsetY;
                    }

                    AddVertex(clonedNode);

                    ScopeBaseMetadata scopeBaseMetadata       = node.Data.Metadata as ScopeBaseMetadata;
                    ScopeBaseMetadata clonedScopeBaseMetadata = clonedNode.Data.Metadata as ScopeBaseMetadata;
                    if ((scopeBaseMetadata != null && clonedScopeBaseMetadata != null) &&
                        (scopeBaseMetadata.ComponentGraph != null))
                    {
                        clonedScopeBaseMetadata.ComponentGraph.Clear();
                        clonedScopeBaseMetadata.ComponentGraph.GetExperiment().ExperimentInfo = clonedScopeBaseMetadata.ComponentGraph.GetExperiment().ExperimentInfo.CloneWithNewId();
                        clonedScopeBaseMetadata.ComponentGraph.CopyAndAdd(scopeBaseMetadata.ComponentGraph, x, y, false);
                    }
                }
            }

            // Clone edges
            foreach (ExperimentNodeConnection connection in subExperiment.Edges)
            {
                ExperimentNode cloneSourceNode, cloneTargetNode;

                //add edges only if both source and target nodes has been found in clones lookup
                bool foundSourceNode = clonedNodeLookup.TryGetValue(connection.Source, out cloneSourceNode);
                bool foundTargetNode = clonedNodeLookup.TryGetValue(connection.Target, out cloneTargetNode);
                if (foundSourceNode && foundTargetNode)
                {
                    ExperimentNodeConnection clonedConnection = new ExperimentNodeConnection(Guid.NewGuid().ToString(), cloneSourceNode, cloneTargetNode, connection.IsFixed, connection.IsVisible);
                    //copy also all route points
                    clonedConnection.RoutePoints.CopyPointsFrom(connection.RoutePoints);
                    AddEdge(clonedConnection);

                    //special case - fix scope node references
                    ScopeNodeHelper.TryFixScopeDecisionEntryAndExitNodes(cloneSourceNode, cloneTargetNode);
                }
            }

            // HERZUM SPRINT 2.4 TLAB-56 TLAB-57 TLAB-58 TLAB-59
            if (first)
            {
                if (subExperiment.References != null)
                {
                    References = subExperiment.References.CopyCollection();
                }
            }
            // HERZUM SPRINT 2.4 TLAB-56 TLAB-57 TLAB-58 TLAB-59

            // Do deep copy of errors.
            this.m_errors = new ObservableDictionary <ExperimentNode, ExperimentNodeError>();
            foreach (KeyValuePair <ExperimentNode, ExperimentNodeError> pair in m_errors)
            {
                m_errors[clonedNodeLookup[pair.Key]] = new ExperimentNodeError(pair.Value.ErrorMessage, pair.Value.ErrorType);
            }
        }