public void Output(DependencyGraph graph, ArchitectureGraph architecture, List<OutputEntry> warnings)
 {
     var result = new StringBuilder();
     AppendProjects(result, graph);
     AppendDependencies(result, graph);
     File.WriteAllText(file, result.ToString());
 }
        public void Output(DependencyGraph graph, ArchitectureGraph architecture, List<OutputEntry> warnings)
        {
            var xdoc = new XDocument();
            var xroot = new XElement("DependencyChecker-Depedencies");
            xdoc.Add(xroot);

            XMLHelper.ToXML(xroot, graph);

            File.WriteAllText(file, xdoc.ToString());
        }
        public void Output(DependencyGraph aGraph, ArchitectureGraph aArchitecture, List<OutputEntry> aWarnings)
        {
            graph = aGraph;
            architecture = aArchitecture;
            warnings = aWarnings;

            wrongDependencies = new HashSet<Dependency>(warnings.OfType<DependencyRuleMatch>()
                .Where(w => !w.Allowed)
                .SelectMany(w => w.Dependencies));

            var result = GenerateDot();

            File.WriteAllText(file, result);
        }
        public void Output(ArchitectureGraph architecture, List<OutputEntry> warnings)
        {
            architecture.Vertices.ForEach((proj, i) => ids.Add(proj, i + 1));

            var result = new DotStringBuilder("Architecture");

            architecture.Vertices.ForEach(v => result.AppendNode(v, v, "shape", "box"));

            result.AppendSpace();

            var deps = new HashSet<GroupDependency>(architecture.Edges);
            var inversible = new HashSet<GroupDependency>(deps.Where(d => deps.Contains(new GroupDependency(d.Target, d.Source))));

            architecture.Edges.ForEach(d => result.AppendEdge(d.Source, d.Target, "style", GetStyle(d), "color", GetColor(d, inversible)));

            File.WriteAllText(file, result.ToString());
        }
        public void Output(ArchitectureGraph architecture, List<OutputEntry> warnings)
        {
            var xdoc = new XDocument();
            var xroot = new XElement("DependencyChecker-Architecture");
            xdoc.Add(xroot);

            foreach (var group in architecture.Vertices.OrderBy(v => v, StringComparer.CurrentCultureIgnoreCase))
                xroot.Add(new XElement("Group", new XAttribute("Name", group)));

            foreach (var dep in architecture.Edges.SortBy(GroupDependency.NaturalOrdering))
                xroot.Add(new XElement("Dependency", //
                    new XAttribute("Source", dep.Source), //
                    new XAttribute("Target", dep.Target), //
                    new XAttribute("Type", dep.Type.ToString())));

            File.WriteAllText(file, xdoc.ToString());
        }
        public void Output(ArchitectureGraph architecture, List<OutputEntry> warnings)
        {
            var result = new StringBuilder();

            result.Append("Groups:\n");
            architecture.Vertices.OrderBy(v => v, StringComparer.CurrentCultureIgnoreCase)
                .ForEach(v => result.Append("  - ")
                    .Append(v)
                    .Append("\n"));

            result.Append("\n");
            result.Append("Dependencies:\n");
            architecture.Edges.SortBy(GroupDependency.NaturalOrdering)
                .ForEach(v => result.Append("  - ")
                    .Append(v.Source)
                    .Append(" -> ")
                    .Append(v.Target)
                    .Append(v.Type == GroupDependency.Types.Conflicted ? " (this reference is both allowed and not allowed)" : "")
                    .Append(v.Type == GroupDependency.Types.Implicit ? " (this reference is not explicit allowed, but is also not not allowed)" : "")
                    .Append("\n"));

            File.WriteAllText(file, result.ToString());
        }
        public void Output(DependencyGraph graph, ArchitectureGraph architecture, List<OutputEntry> warnings)
        {
            var filtered = Filter(graph, warnings);

            next.Output(filtered, architecture, warnings);
        }
        public static ArchitectureGraph Load(Config config, DependencyGraph graph)
        {
            var rules = config.Rules.OfType<DepenendencyRule>()
                .Where(r => r.Severity == Severity.Error)
                .Cast<Rule>()
                .ToList();

            var libs = graph.Vertices.Where(v => v.GroupElement != null)
                .ToList();

            var allowed = new HashSet<GroupDependency>();
            var notAllowed = new HashSet<GroupDependency>();

            foreach (var p1 in libs)
            {
                foreach (var p2 in libs)
                {
                    if (p1.GroupElement.Name == p2.GroupElement.Name)
                        continue;

                    var dep = new GroupDependency(p1.GroupElement.Name, p2.GroupElement.Name);
                    if (allowed.Contains(dep) && notAllowed.Contains(dep))
                        continue;

                    var match = RulesMatcher.FindMatch(rules, Dependency.WithProject(p1, p2, new Location("a", 1))) as DependencyRuleMatch;
                    if (match != null)
                    {
                        if (match.Allowed)
                            allowed.Add(dep);
                        else
                            notAllowed.Add(dep);
                    }

                    match = RulesMatcher.FindMatch(rules, Dependency.WithLibrary(p1, p2, new Location("a", 1), null)) as DependencyRuleMatch;
                    if (match != null)
                    {
                        if (match.Allowed)
                            allowed.Add(dep);
                        else
                            notAllowed.Add(dep);
                    }
                }
            }

            var groups = libs.Select(p => p.GroupElement.Name)
                .Distinct()
                .ToList();

            var deps = new HashSet<GroupDependency>();
            foreach (var g1 in groups)
            {
                foreach (var g2 in groups)
                {
                    if (g1 == g2)
                        continue;

                    var dep = new GroupDependency(g1, g2);
                    var isAllowed = allowed.Contains(dep);
                    var isNotAllowed = notAllowed.Contains(dep);

                    if (isAllowed && isNotAllowed)
                        dep = new GroupDependency(g1, g2, GroupDependency.Types.Conflicted);
                    else if (!isAllowed && !isNotAllowed)
                        dep = new GroupDependency(g1, g2, GroupDependency.Types.Implicit);
                    else if (isNotAllowed)
                        dep = null;

                    if (dep != null)
                        deps.Add(dep);
                }
            }

            var groupGraph = new ArchitectureGraph();
            groupGraph.AddVertexRange(groups);
            groupGraph.AddEdgeRange(deps);
            return groupGraph;
        }