Example #1
0
        private static ComponentGraph ParseArchitecture(string architecture, bool isNested)
        {
            // split architecture into elements that include layers, modules, and edges
            IList <string> components = ComponentGraph.SplitArchitecture(architecture, NetworkGraphBuilder.Delimiter);

            // extract elements that defines edges and modules (in A=... format)
            Dictionary <string, string>         elements;
            Dictionary <string, ComponentGraph> modules;

            NetworkGraphBuilder.ParseComponents(components, out elements, out modules);

            // components must now contain edges only (in A-B-... format)
            ComponentGraph graph = ComponentGraph.FromComponents(components, elements, modules);

            // process nested graphs
            if (isNested)
            {
                // nested graphs must start with a single split layer
                IList <ComponentVertex> sources = graph.Sources.ToList();
                if (sources.Count > 1)
                {
                    ComponentVertex split = new ComponentVertex(
                        Guid.NewGuid().ToString(),
                        string.Format(CultureInfo.InvariantCulture, "SP{0}", sources.Count));

                    graph.AddEdges(sources.Select(x => new Edge <ComponentVertex>(split, x)));
                }

                // nested graphs must end with a single concat layer
                IList <ComponentVertex> sinks = graph.Sinks.ToList();
                if (sinks.Count > 1)
                {
                    ComponentVertex concat = new ComponentVertex(Guid.NewGuid().ToString(), "CONCAT");

                    graph.AddEdges(sinks.Select(x => new Edge <ComponentVertex>(x, concat)));
                }
            }

            return(graph);
        }