コード例 #1
0
ファイル: Kernel.cs プロジェクト: rafysanchez/Apollo
        /// <summary>
        /// Determines the ideal service startup order of the services.
        /// </summary>
        /// <returns>
        /// An ordered collection of services. Where the order indicates the ideal startup order.
        /// </returns>
        private List <KernelService> DetermineServiceStartupOrder()
        {
            var graph = new AdjacencyGraph <ServiceVertex, Edge <ServiceVertex> >();

            {
                var typedCollection = new Dictionary <Type, ServiceVertex>();
                foreach (var pair in m_Services)
                {
                    var vertex = new ServiceVertex(pair.Value);
                    graph.AddVertex(vertex);
                    typedCollection.Add(pair.Key, vertex);
                }

                // The edges point from a dependency to the dependent vertex
                foreach (var pair in typedCollection)
                {
                    var target = pair.Value;
                    if (target.HasDependencies)
                    {
                        var dependencies = m_Connections[target.Service];
                        foreach (var dependent in dependencies)
                        {
                            Debug.Assert(typedCollection.ContainsKey(dependent.Applied.GetType()), "Missing a service type.");
                            var source = typedCollection[dependent.Applied.GetType()];

                            graph.AddEdge(new Edge <ServiceVertex>(source, target));
                        }
                    }
                }
            }

            return(graph.TopologicalSort()
                   .Select(vertex => vertex.Service)
                   .ToList());
        }
コード例 #2
0
ファイル: Kernel.cs プロジェクト: pvandervelde/Apollo
        /// <summary>
        /// Determines the ideal service startup order of the services.
        /// </summary>
        /// <returns>
        /// An ordered collection of services. Where the order indicates the ideal startup order.
        /// </returns>
        private List<KernelService> DetermineServiceStartupOrder()
        {
            var graph = new AdjacencyGraph<ServiceVertex, Edge<ServiceVertex>>();
            {
                var typedCollection = new Dictionary<Type, ServiceVertex>();
                foreach (var pair in m_Services)
                {
                    var vertex = new ServiceVertex(pair.Value);
                    graph.AddVertex(vertex);
                    typedCollection.Add(pair.Key, vertex);
                }

                // The edges point from a dependency to the dependent vertex
                foreach (var pair in typedCollection)
                {
                    var target = pair.Value;
                    if (target.HasDependencies)
                    {
                        var dependencies = m_Connections[target.Service];
                        foreach (var dependent in dependencies)
                        {
                            Debug.Assert(typedCollection.ContainsKey(dependent.Applied.GetType()), "Missing a service type.");
                            var source = typedCollection[dependent.Applied.GetType()];

                            graph.AddEdge(new Edge<ServiceVertex>(source, target));
                        }
                    }
                }
            }

            return graph.TopologicalSort()
                .Select(vertex => vertex.Service)
                .ToList();
        }