private static void Main(string[] args) { Options = new Options(); if (!CommandLine.Parser.Default.ParseArguments(args, Options)) { PrintUsage(false); return; } if (!File.Exists(Options.InputProjectFile)) { Console.WriteLine("Input project file could not be found."); PrintUsage(true); return; } Options.InputProjectFile = Path.GetFullPath(Options.InputProjectFile); Options.OutputProjectFile = string.IsNullOrEmpty(Options.OutputProjectFile) ? Options.InputProjectFile : Path.GetFullPath(Options.OutputProjectFile); if (File.Exists(Options.OutputProjectFile) && Options.OutputProjectFile != Options.InputProjectFile) { File.Delete(Options.OutputProjectFile); } Project = new TdsProject(); ProjectLoader.Process(Options, Project); ProjectCleaner.Process(Options, Project); ProjectSorter.Process(Options, Project); ProjectWriter.Process(Options, Project); Console.ReadKey(true); }
public static void Process(Options options, TdsProject project) { project.Document = XDocument.Load(options.InputProjectFile); project.BaseDirectory = Path.GetDirectoryName(options.InputProjectFile); project.BaseItemDirectory = Path.Combine(project.BaseDirectory, "sitecore"); Log.Info("ProjectLoader", "{0} items in project.", project.Items.Count); }
/// <summary> /// Removes files on the disk which no longer have corresponding <c>Item</c> /// elements in the project file. /// </summary> /// <param name="project">Project reference</param> private static void RemoveUnusedFiles(TdsProject project) { foreach (var file in Directory.GetFiles(project.BaseItemDirectory, "*.item", SearchOption.AllDirectories)) { if (!project.Items.Any(item => item.FilePath.Equals(file, StringComparison.OrdinalIgnoreCase))) { project.FilesToBeDeleted.Add(file); Log.Info("ProjectCleaner", "Deleted unreferenced item file: '{0}'", file.Replace(project.BaseItemDirectory, string.Empty)); } } }
/// <summary> /// Removes <c>Item</c> elements in the project that point to items which /// no longer exist on the disk. /// </summary> /// <param name="project">Project reference</param> private static void RemoveBrokenReferences(TdsProject project) { var items = project.Items.ToArray(); foreach (var item in items) { if (!File.Exists(item.FilePath)) { project.Items.Remove(item); item.ItemNode.Remove(); Log.Info("ProjectCleaner", "Removed broken reference from project: '{0}'", item.ProjectPath); } } }
/// <summary> /// Converts all the Icon elements so that they use a standardised format. /// </summary> /// <param name="project">Project reference</param> private static void NormalizeIcons(TdsProject project) { long counter = 0; foreach (var iconElement in project.Items.Select(item => item.ItemNode.Element(TdsProject.Namespaces.MsBuild + "Icon"))) { if (iconElement.Value.StartsWith("/temp/IconCache/")) { counter++; iconElement.Value = iconElement.Value.Replace("/temp/IconCache/", "/~/icon/") + ".aspx"; } } Log.Info("ProjectCleaner", "Normalised {0:N0} icon entries.", counter); }
public static void Process(Options options, TdsProject project) { if (options.RemoveBrokenItemReferences) { RemoveBrokenReferences(project); } if (options.RemoveUnusedItemFiles) { RemoveUnusedFiles(project); } RemoveEmptyDirectories(project.BaseDirectory, new DirectoryInfo(project.BaseItemDirectory)); NormalizeIcons(project); }
public static void Process(Options options, TdsProject project) { Log.Info("ProjectWriter", "{0} items in project.", project.Items.Count); if (!options.TestRun) { project.Document.Save(options.OutputProjectFile); foreach (var file in project.FilesToBeDeleted) { File.Delete(file); } foreach (var directory in project.DirectoriesToBeDeleted) { Directory.Delete(directory); } } }
public TdsItem(TdsProject project, XElement itemNode) { ItemNode = itemNode; ProjectPath = ItemNode.Attribute("Include").Value; FilePath = Path.Combine(project.BaseDirectory, TdsUtil.DecodePath(ProjectPath)); }
public static void Process(Options options, TdsProject project) { project.ItemRoot.ReplaceWith(Reorder(project.ItemRoot)); }