private static bool ShouldExclude(string filename, ExcludeFolder[] excludeFolders) { bool exclude = false; foreach (ExcludeFolder excludeFolder in excludeFolders) { if (filename.Split(Path.DirectorySeparatorChar).Contains(excludeFolder.name)) { excludeFolder.used = true; exclude = true; } } if (exclude) { return true; } return false; }
private static Diff[] GetDiffs(string[] files, ExcludeFolder[] excludeFolders) { List<Diff> diffs = new List<Diff>(); foreach (string filename in files) { string FolderName = Path.GetFileName(Path.GetDirectoryName(filename)); string ProjectName = Path.GetFileNameWithoutExtension(filename); XDocument xdoc; string AssemblyName, RootNamespace; try { xdoc = XDocument.Load(filename); AssemblyName = xdoc .Descendants(xdoc.Root.Name.Namespace + "AssemblyName") .FirstOrDefault()?.Value ?? string.Empty; RootNamespace = xdoc .Descendants(xdoc.Root.Name.Namespace + "RootNamespace") .FirstOrDefault()?.Value ?? string.Empty; } catch (XmlException ex) { if (ShouldExclude(filename, excludeFolders)) { continue; } WriteColor("Project file: " + filename + ". " + ex.Message, ConsoleColor.Red); Diff diff = new Diff(); diff.FolderName = FolderName; diff.ProjectName = ProjectName; diff.AssemblyName = string.Empty; diff.RootNamespace = string.Empty; diff.Level = Level.Error; diffs.Add(diff); continue; } string[] names = new string[] { FolderName, ProjectName, AssemblyName, RootNamespace }; if (names.Any(n => n.Length > FolderName.Length && !n.EndsWith(FolderName)) || names.Any(n => n.Length >= ProjectName.Length && !n.EndsWith(ProjectName)) || names.Any(n => n.Length >= AssemblyName.Length && !n.EndsWith(AssemblyName)) || names.Any(n => n.Length >= RootNamespace.Length && !n.EndsWith(RootNamespace))) { if (ShouldExclude(filename, excludeFolders)) { continue; } Diff diff = new Diff(); diff.FolderName = FolderName; diff.ProjectName = ProjectName; diff.AssemblyName = AssemblyName; diff.RootNamespace = RootNamespace; diff.Level = Level.Error; diffs.Add(diff); } else if (FolderName != ProjectName || FolderName != AssemblyName || FolderName != RootNamespace) { if (ShouldExclude(filename, excludeFolders)) { continue; } Diff diff = new Diff(); diff.FolderName = FolderName; diff.ProjectName = ProjectName; diff.AssemblyName = AssemblyName; diff.RootNamespace = RootNamespace; diff.Level = Level.Warning; diffs.Add(diff); } } return diffs.ToArray(); }
private static int GetExcessiveExcludesCount(ExcludeFolder[] excludeFolders) { int count = excludeFolders.Count(e => !e.used); if (count > 0) { Console.WriteLine("Excessive exclude folders specified, please remove all excessive exclude folders from command line:"); foreach (ExcludeFolder excludeFolder in excludeFolders) { if (!excludeFolder.used) { WriteColor(excludeFolder.name, ConsoleColor.Red); } } return count; } return 0; }