private ComponentDeploymentGraph GetAdjacencyGraphForProductGroup(ComponentDeploymentGraph componentDeploymentDependancies, int productGroup)
        {
            var vertices = componentDeploymentDependancies.Vertices
                           .Where(vertex => vertex.ProductGroup == productGroup);
            var edges = componentDeploymentDependancies.Edges
                        .Where(edge => edge.Source.ProductGroup == productGroup);

            var relatedComponentDependancies = new ComponentDeploymentGraph();

            relatedComponentDependancies.AddVertexRange(vertices);
            relatedComponentDependancies.AddEdgeRange(edges);

            return(relatedComponentDependancies);
        }
        public ComponentDeploymentGraph GetComponentDeploymentGraph(EnvironmentDeploymentPlan environmentDeploymentPlan)
        {
            var componentVertices = new Dictionary <string, ComponentDeploymentVertex>();

            foreach (var componentDependancy in environmentDeploymentPlan.DeploymentPlans)
            {
                var version            = componentDependancy.ComponentFrom == null ? null : componentDependancy.ComponentFrom.Version;
                var deploymentDuration = componentDependancy.ComponentFrom == null ? null : componentDependancy.ComponentFrom.DeploymentDuration;

                var componentVertex = new ComponentDeploymentVertex(componentDependancy.Id, componentDependancy.Name, version, componentDependancy.Action, deploymentDuration);
                componentVertices.Add(componentDependancy.Name, componentVertex);
            }

            var componentEdges = new List <ComponentDeploymentEdge>();

            foreach (var componentDependancy in environmentDeploymentPlan.DeploymentPlans)
            {
                if (componentDependancy.ComponentFrom == null)
                {
                    continue;
                }

                var source = componentVertices[componentDependancy.Name];

                foreach (var dependancy in componentDependancy.ComponentFrom.Dependancies)
                {
                    ComponentDeploymentVertex target;
                    var targetExists = componentVertices.TryGetValue(dependancy, out target);

                    if (!targetExists)
                    {
                        //The dependancy points to a vertex that does not exist (spelling mistake/dependant components have changed their name/component dependancies have changed)
                        target = new ComponentDeploymentVertex(dependancy, dependancy, null, PlanAction.Skip, null, false);
                        componentVertices.Add(dependancy, target);
                    }

                    var componentEdge = new ComponentDeploymentEdge(source, target);
                    componentEdges.Add(componentEdge);
                }
            }

            var componentDependanciesAdjacencyGraph = new ComponentDeploymentGraph();

            componentDependanciesAdjacencyGraph.AddVertexRange(componentVertices.Values);
            componentDependanciesAdjacencyGraph.AddEdgeRange(componentEdges);

            return(componentDependanciesAdjacencyGraph);
        }