コード例 #1
0
        public virtual void TopologicalSort()
        {
            var graph = new TopologicalSorting.DependencyGraph();

            foreach (var t in this.Types)
            {
                var finder = new DependencyFinderVisitor(this, t);
                t.TypeDeclaration.AcceptVisitor(finder);

                var tProcess = graph.Processes.FirstOrDefault(p => p.Name == t.Type.ReflectionName);
                if (tProcess == null)
                {
                    tProcess = new TopologicalSorting.OrderedProcess(graph, t.Type.ReflectionName);
                }

                if (finder.Dependencies.Count > 0)
                {
                    foreach (var dependency in finder.Dependencies)
                    {
                        if (tProcess.Predecessors.All(p => p.Name != dependency.Type.ReflectionName))
                        {
                            var dProcess = graph.Processes.FirstOrDefault(p => p.Name == dependency.Type.ReflectionName);
                            if (dProcess == null)
                            {
                                dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.ReflectionName);
                            }
                            //var dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.FullName);

                            if (dProcess.Predecessors.All(p => p.Name != tProcess.Name))
                            {
                                tProcess.After(dProcess);
                            }
                        }
                    }
                }
            }

            if (graph.ProcessCount > 0)
            {
                ITypeInfo tInfo = null;

                try
                {
                    IEnumerable <IEnumerable <OrderedProcess> > sorted = graph.CalculateSort();

                    var list = new List <ITypeInfo>(this.Types.Count);
                    foreach (var processes in sorted)
                    {
                        foreach (var process in processes)
                        {
                            tInfo = this.Types.First(ti => ti.Type.ReflectionName == process.Name);

                            if (list.All(t => t.Type.ReflectionName != tInfo.Type.ReflectionName))
                            {
                                list.Add(tInfo);
                            }
                        }
                    }

                    this.Types.Clear();
                    this.Types.AddRange(list);
                }
                catch (System.Exception ex)
                {
                    this.LogWarning(string.Format("Topological sort failed {0} with error {1}", tInfo != null ? "at type " + tInfo.Type.ReflectionName : string.Empty, ex));
                }
            }
        }
コード例 #2
0
        public virtual void TopologicalSort()
        {
            var graph = new TopologicalSorting.DependencyGraph();

            foreach (var t in this.Types)
            {
                var finder = new DependencyFinderVisitor(this, t);
                t.TypeDeclaration.AcceptVisitor(finder);

                var tProcess = graph.Processes.FirstOrDefault(p => p.Name == t.Type.ReflectionName);
                if (tProcess == null)
                {
                    tProcess = new TopologicalSorting.OrderedProcess(graph, t.Type.ReflectionName);
                }

                if (finder.Dependencies.Count > 0)
                {
                    foreach (var dependency in finder.Dependencies)
                    {
                        if (tProcess.Predecessors.All(p => p.Name != dependency.Type.ReflectionName))
                        {
                            var dProcess = graph.Processes.FirstOrDefault(p => p.Name == dependency.Type.ReflectionName);
                            if (dProcess == null)
                            {
                                dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.ReflectionName);
                            }
                            //var dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.FullName);

                            if (dProcess.Predecessors.All(p => p.Name != tProcess.Name))
                            {
                                tProcess.After(dProcess);
                            }
                        }
                    }
                }
            }

            foreach (var t in this.Types)
            {
                for (int i = this.Types.Count - 1; i > -1; i--)
                {
                    var x = this.Types[i];

                    var tProcess = graph.Processes.FirstOrDefault(p => p.Name == t.Type.ReflectionName);
                    if (tProcess == null)
                    {
                        tProcess = new TopologicalSorting.OrderedProcess(graph, t.Type.ReflectionName);
                    }

                    if (this.IsInheritedFrom(t, x))
                    {
                        if (tProcess.Predecessors.All(p => p.Name != x.Type.ReflectionName))
                        {
                            var dProcess = graph.Processes.FirstOrDefault(p => p.Name == x.Type.ReflectionName);
                            if (dProcess == null)
                            {
                                dProcess = new TopologicalSorting.OrderedProcess(graph, x.Type.ReflectionName);
                            }
                            //var dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.FullName);

                            if (dProcess.Predecessors.All(p => p.Name != tProcess.Name))
                            {
                                tProcess.After(dProcess);
                            }
                        }
                    }
                }
            }

            if (graph.ProcessCount > 0)
            {
                ITypeInfo tInfo = null;

                try
                {
                    IEnumerable<IEnumerable<OrderedProcess>> sorted = graph.CalculateSort();

                    var list = new List<ITypeInfo>(this.Types.Count);
                    foreach (var processes in sorted)
                    {
                        foreach (var process in processes)
                        {
                            tInfo = this.Types.First(ti => ti.Type.ReflectionName == process.Name);

                            if (list.All(t => t.Type.ReflectionName != tInfo.Type.ReflectionName))
                            {
                                list.Add(tInfo);
                            }
                        }
                    }

                    this.Types.Clear();
                    this.Types.AddRange(list);
                }
                catch (System.Exception ex)
                {
                    this.LogWarning(string.Format("Topological sort failed {0} with error {1}", tInfo != null ? "at type " + tInfo.Type.ReflectionName : string.Empty, ex));
                }
            }
        }
コード例 #3
0
        public virtual void TopologicalSort()
        {
            this.Log.Trace("Topological sorting...");

            var graph = new TopologicalSorting.DependencyGraph();

            this.Log.Trace("\tTopological sorting first iteration...");

            var hitCounters = new long[7];

            foreach (var t in this.Types)
            {
                hitCounters[0]++;
                var parents = this.GetParents(t.Type);

                for (int i = parents.Count - 1; i > -1; i--)
                {
                    hitCounters[1]++;
                    var x = parents[i];

                    var t1       = t;
                    var tProcess = graph.Processes.FirstOrDefault(p => p.Name == t1.Type.ReflectionName);
                    if (tProcess == null)
                    {
                        hitCounters[2]++;
                        tProcess = new TopologicalSorting.OrderedProcess(graph, t.Type.ReflectionName);
                    }

                    hitCounters[3]++;

                    if (tProcess.Predecessors.All(p => p.Name != x.Type.ReflectionName))
                    {
                        hitCounters[4]++;

                        var dProcess = graph.Processes.FirstOrDefault(p => p.Name == x.Type.ReflectionName);
                        if (dProcess == null)
                        {
                            hitCounters[5]++;
                            dProcess = new TopologicalSorting.OrderedProcess(graph, x.Type.ReflectionName);
                        }
                        //var dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.FullName);

                        if (dProcess.Predecessors.All(p => p.Name != tProcess.Name))
                        {
                            hitCounters[6]++;
                            tProcess.After(dProcess);
                        }
                    }
                }
            }

            for (int i = 0; i < hitCounters.Length; i++)
            {
                this.Log.Trace("\t\tHitCounter" + i + " = " + hitCounters[i]);
            }

            this.Log.Trace("\tTopological sorting first iteration done");

            this.Log.Trace("\tTopological sorting second iteration...");

            System.Array.Clear(hitCounters, 0, hitCounters.Length);

            foreach (var t in this.Types)
            {
                hitCounters[0]++;

                var finder = new DependencyFinderVisitor(this, t);
                t.TypeDeclaration.AcceptVisitor(finder);

                var tProcess = graph.Processes.FirstOrDefault(p => p.Name == t.Type.ReflectionName);
                if (tProcess == null)
                {
                    hitCounters[1]++;
                    tProcess = new TopologicalSorting.OrderedProcess(graph, t.Type.ReflectionName);
                }

                if (finder.Dependencies.Count > 0)
                {
                    hitCounters[2]++;

                    foreach (var dependency in finder.Dependencies)
                    {
                        hitCounters[3]++;

                        if (tProcess.Predecessors.All(p => p.Name != dependency.Type.ReflectionName))
                        {
                            hitCounters[4]++;

                            var dProcess = graph.Processes.FirstOrDefault(p => p.Name == dependency.Type.ReflectionName);
                            if (dProcess == null)
                            {
                                hitCounters[5]++;
                                dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.ReflectionName);
                            }
                            //var dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.FullName);

                            if (dProcess.Predecessors.All(p => p.Name != tProcess.Name))
                            {
                                hitCounters[6]++;
                                tProcess.After(dProcess);
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < hitCounters.Length; i++)
            {
                this.Log.Trace("\t\tHitCounter" + i + " = " + hitCounters[i]);
            }

            this.Log.Trace("\t\tgraph.ProcessCount = " + graph.ProcessCount);

            this.Log.Trace("\tTopological sorting second iteration done");

            if (graph.ProcessCount > 0)
            {
                ITypeInfo tInfo = null;

                try
                {
                    this.Log.Trace("\tTopological sorting third iteration...");

                    System.Array.Clear(hitCounters, 0, hitCounters.Length);

                    this.Log.Trace("\t\tCalculate sorting...");
                    IEnumerable <IEnumerable <OrderedProcess> > sorted = graph.CalculateSort();
                    this.Log.Trace("\t\tCalculate sorting done");

                    var list = new List <ITypeInfo>(this.Types.Count);
                    foreach (var processes in sorted)
                    {
                        hitCounters[0]++;

                        foreach (var process in processes)
                        {
                            hitCounters[1]++;

                            tInfo = this.Types.First(ti => ti.Type.ReflectionName == process.Name);

                            if (list.All(t => t.Type.ReflectionName != tInfo.Type.ReflectionName))
                            {
                                hitCounters[2]++;
                                list.Add(tInfo);
                            }
                        }
                    }

                    this.Types.Clear();
                    this.Types.AddRange(list);

                    for (int i = 0; i < hitCounters.Length; i++)
                    {
                        this.Log.Trace("\t\tHitCounter" + i + " = " + hitCounters[i]);
                    }

                    this.Log.Trace("\tTopological sorting third iteration done");
                }
                catch (System.Exception ex)
                {
                    this.LogWarning(string.Format("Topological sort failed {0} with error {1}", tInfo != null ? "at type " + tInfo.Type.ReflectionName : string.Empty, ex));
                }
            }

            this.Log.Trace("Topological sorting done");
        }
コード例 #4
0
        public virtual void TopologicalSort()
        {
            this.Log.Trace("Topological sorting...");

            var graph = new TopologicalSorting.DependencyGraph();

            this.Log.Trace("\tTopological sorting first iteration...");

            var hitCounters = new long[7];

            foreach (var t in this.Types)
            {
                hitCounters[0]++;
                var parents = this.GetParents(t.Type);

                for (int i = parents.Count - 1; i > -1; i--)
                {
                    hitCounters[1]++;
                    var x = parents[i];

                    var t1 = t;
                    var tProcess = graph.Processes.FirstOrDefault(p => p.Name == t1.Type.ReflectionName);
                    if (tProcess == null)
                    {
                        hitCounters[2]++;
                        tProcess = new TopologicalSorting.OrderedProcess(graph, t.Type.ReflectionName);
                    }

                    hitCounters[3]++;

                    if (tProcess.Predecessors.All(p => p.Name != x.Type.ReflectionName))
                    {
                        hitCounters[4]++;

                        var dProcess = graph.Processes.FirstOrDefault(p => p.Name == x.Type.ReflectionName);
                        if (dProcess == null)
                        {
                            hitCounters[5]++;
                            dProcess = new TopologicalSorting.OrderedProcess(graph, x.Type.ReflectionName);
                        }
                        //var dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.FullName);

                        if (dProcess.Predecessors.All(p => p.Name != tProcess.Name))
                        {
                            hitCounters[6]++;
                            tProcess.After(dProcess);
                        }
                    }
                }
            }

            for (int i = 0; i < hitCounters.Length; i++)
            {
                this.Log.Trace("\t\tHitCounter" + i + " = " + hitCounters[i]);
            }

            this.Log.Trace("\tTopological sorting first iteration done");

            this.Log.Trace("\tTopological sorting second iteration...");

            System.Array.Clear(hitCounters, 0, hitCounters.Length);

            foreach (var t in this.Types)
            {
                hitCounters[0]++;

                var finder = new DependencyFinderVisitor(this, t);
                t.TypeDeclaration.AcceptVisitor(finder);

                var tProcess = graph.Processes.FirstOrDefault(p => p.Name == t.Type.ReflectionName);
                if (tProcess == null)
                {
                    hitCounters[1]++;
                    tProcess = new TopologicalSorting.OrderedProcess(graph, t.Type.ReflectionName);
                }

                if (finder.Dependencies.Count > 0)
                {
                    hitCounters[2]++;

                    foreach (var dependency in finder.Dependencies)
                    {
                        hitCounters[3]++;

                        if (tProcess.Predecessors.All(p => p.Name != dependency.Type.ReflectionName))
                        {
                            hitCounters[4]++;

                            var dProcess = graph.Processes.FirstOrDefault(p => p.Name == dependency.Type.ReflectionName);
                            if (dProcess == null)
                            {
                                hitCounters[5]++;
                                dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.ReflectionName);
                            }
                            //var dProcess = new TopologicalSorting.OrderedProcess(graph, dependency.Type.FullName);

                            if (dProcess.Predecessors.All(p => p.Name != tProcess.Name))
                            {
                                hitCounters[6]++;
                                tProcess.After(dProcess);
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < hitCounters.Length; i++)
            {
                this.Log.Trace("\t\tHitCounter" + i + " = " + hitCounters[i]);
            }

            this.Log.Trace("\t\tgraph.ProcessCount = " + graph.ProcessCount);

            this.Log.Trace("\tTopological sorting second iteration done");

            if (graph.ProcessCount > 0)
            {
                ITypeInfo tInfo = null;

                try
                {
                    this.Log.Trace("\tTopological sorting third iteration...");

                    System.Array.Clear(hitCounters, 0, hitCounters.Length);

                    this.Log.Trace("\t\tCalculate sorting...");
                    IEnumerable<IEnumerable<OrderedProcess>> sorted = graph.CalculateSort();
                    this.Log.Trace("\t\tCalculate sorting done");

                    var list = new List<ITypeInfo>(this.Types.Count);
                    foreach (var processes in sorted)
                    {
                        hitCounters[0]++;

                        foreach (var process in processes)
                        {
                            hitCounters[1]++;

                            tInfo = this.Types.First(ti => ti.Type.ReflectionName == process.Name);

                            if (list.All(t => t.Type.ReflectionName != tInfo.Type.ReflectionName))
                            {
                                hitCounters[2]++;
                                list.Add(tInfo);
                            }
                        }
                    }

                    this.Types.Clear();
                    this.Types.AddRange(list);

                    for (int i = 0; i < hitCounters.Length; i++)
                    {
                        this.Log.Trace("\t\tHitCounter" + i + " = " + hitCounters[i]);
                    }

                    this.Log.Trace("\tTopological sorting third iteration done");
                }
                catch (System.Exception ex)
                {
                    this.LogWarning(string.Format("Topological sort failed {0} with error {1}", tInfo != null ? "at type " + tInfo.Type.ReflectionName : string.Empty, ex));
                }
            }

            this.Log.Trace("Topological sorting done");
        }