public static void AddFiles(this IProjectSystem project, IEnumerable <IPackageFile> files, IDictionary <string, IPackageFileTransformer> fileTransformers) { // BUG 636: We add the files with the longest path first so that vs picks up code behind files. // This shouldn't matter for any other scenario. foreach (IPackageFile file in files.OrderByDescending(p => p.Path)) { // Remove the redundant folder from the path string path = ResolvePath(project, file.Path); // Try to get the package file modifier for the extension string extension = Path.GetExtension(file.Path); IPackageFileTransformer transformer; if (fileTransformers.TryGetValue(extension, out transformer)) { // Remove the extension to get the target path path = RemoveExtension(path); if (project.IsSupportedFile(path)) { // If the transform was done then continue transformer.TransformFile(file, path, project); } } else if (project.IsSupportedFile(path)) { project.AddFileWithCheck(path, file.GetStream); } } }
public static void AddFiles(this IProjectSystem project, IEnumerable <IPackageFile> files, IDictionary <FileTransformExtensions, IPackageFileTransformer> fileTransformers) { List <IPackageFile> list = files.ToList <IPackageFile>(); IComparer <IPackageFile> comparer = project as IComparer <IPackageFile>; if (comparer != null) { list.Sort(comparer); } IBatchProcessor <string> processor = project as IBatchProcessor <string>; try { if (processor != null) { processor.BeginProcessing(from file in list select ResolvePath(fileTransformers, fte => fte.InstallExtension, file.EffectivePath), PackageAction.Install); } foreach (IPackageFile file in list) { IPackageFileTransformer transformer; if (file.IsEmptyFolder()) { continue; } string path = ResolveTargetPath(project, fileTransformers, fte => fte.InstallExtension, file.EffectivePath, out transformer); if (project.IsSupportedFile(path)) { string str2; if (transformer != null) { transformer.TransformFile(file, path, project); continue; } if (FindFileTransformer(fileTransformers, fte => fte.UninstallExtension, file.EffectivePath, out str2) == null) { TryAddFile(project, path, new Func <Stream>(file.GetStream)); } } } } finally { if (processor != null) { processor.EndProcessing(); } } }
public static void AddFiles(this IProjectSystem project, IEnumerable <IPackageFile> files, IDictionary <FileTransformExtensions, IPackageFileTransformer> fileTransformers) { // Convert files to a list List <IPackageFile> fileList = files.ToList(); // See if the project system knows how to sort the files var fileComparer = project as IComparer <IPackageFile>; if (fileComparer != null) { fileList.Sort(fileComparer); } var batchProcessor = project as IBatchProcessor <string>; try { if (batchProcessor != null) { var paths = fileList.Select(file => ResolvePath(fileTransformers, fte => fte.InstallExtension, file.EffectivePath)); batchProcessor.BeginProcessing(paths, PackageAction.Install); } foreach (IPackageFile file in fileList) { if (file.IsEmptyFolder()) { continue; } // Resolve the target path IPackageFileTransformer installTransformer; string path = ResolveTargetPath(project, fileTransformers, fte => fte.InstallExtension, file.EffectivePath, out installTransformer); if (project.IsSupportedFile(path)) { if (installTransformer != null) { installTransformer.TransformFile(file, path, project); } else { // Ignore uninstall transform file during installation string truncatedPath; IPackageFileTransformer uninstallTransformer = FindFileTransformer(fileTransformers, fte => fte.UninstallExtension, file.EffectivePath, out truncatedPath); if (uninstallTransformer != null) { continue; } TryAddFile(project, path, file.GetStream); } } } } finally { if (batchProcessor != null) { batchProcessor.EndProcessing(); } } }
public static void DeleteFiles(this IProjectSystem project, IEnumerable <IPackageFile> files, IEnumerable <IPackage> otherPackages, IDictionary <FileTransformExtensions, IPackageFileTransformer> fileTransformers) { IPackageFileTransformer transformer; // First get all directories that contain files var directoryLookup = files.ToLookup( p => Path.GetDirectoryName(ResolveTargetPath(project, fileTransformers, fte => fte.UninstallExtension, p.EffectivePath, out transformer))); // Get all directories that this package may have added var directories = from grouping in directoryLookup from directory in FileSystemExtensions.GetDirectories(grouping.Key) orderby directory.Length descending select directory; // Remove files from every directory foreach (var directory in directories) { var directoryFiles = directoryLookup.Contains(directory) ? directoryLookup[directory] : Enumerable.Empty <IPackageFile>(); if (!project.DirectoryExists(directory)) { continue; } var batchProcessor = project as IBatchProcessor <string>; try { if (batchProcessor != null) { var paths = directoryFiles.Select(file => ResolvePath(fileTransformers, fte => fte.UninstallExtension, file.EffectivePath)); batchProcessor.BeginProcessing(paths, PackageAction.Uninstall); } foreach (var file in directoryFiles) { if (file.IsEmptyFolder()) { continue; } // Resolve the path string path = ResolveTargetPath(project, fileTransformers, fte => fte.UninstallExtension, file.EffectivePath, out transformer); if (project.IsSupportedFile(path)) { if (transformer != null) { var matchingFiles = from p in otherPackages from otherFile in project.GetCompatibleItemsCore(p.GetContentFiles()) where otherFile.EffectivePath.Equals(file.EffectivePath, StringComparison.OrdinalIgnoreCase) select otherFile; try { transformer.RevertFile(file, path, matchingFiles, project); } catch (Exception e) { // Report a warning and move on project.Logger.Log(MessageLevel.Warning, e.Message); } } else { project.DeleteFileSafe(path, file.GetStream); } } } // If the directory is empty then delete it if (!project.GetFilesSafe(directory).Any() && !project.GetDirectoriesSafe(directory).Any()) { project.DeleteDirectorySafe(directory, recursive: false); } } finally { if (batchProcessor != null) { batchProcessor.EndProcessing(); } } } }
public static void AddFiles(this IProjectSystem project, IEnumerable <IPackageFile> files, IDictionary <string, IPackageFileTransformer> fileTransformers) { // Convert files to a list List <IPackageFile> fileList = files.ToList(); // See if the project system knows how to sort the files var fileComparer = project as IComparer <IPackageFile>; if (fileComparer != null) { fileList.Sort(fileComparer); } var batchProcessor = project as IBatchProcessor <string>; try { if (batchProcessor != null) { var paths = fileList.Select(file => ResolvePath(fileTransformers, file.EffectivePath)); batchProcessor.BeginProcessing(paths, PackageAction.Install); } foreach (IPackageFile file in fileList) { if (file.IsEmptyFolder()) { continue; } IPackageFileTransformer transformer; // Resolve the target path string path = ResolveTargetPath(project, fileTransformers, file.EffectivePath, out transformer); if (project.IsSupportedFile(path)) { // Try to get the package file modifier for the extension if (transformer != null) { // If the transform was done then continue transformer.TransformFile(file, path, project); } else { TryAddFile(project, file, path); } } } } finally { if (batchProcessor != null) { batchProcessor.EndProcessing(); } } }
public static void DeleteFiles(this IProjectSystem project, IEnumerable <IPackageFile> files, IEnumerable <IPackage> otherPackages, IDictionary <string, IPackageFileTransformer> fileTransformers) { // First get all directories that contain files var directoryLookup = files.ToLookup(p => Path.GetDirectoryName(ResolvePath(project, p.Path))); // Get all directories that this package may have added var directories = from grouping in directoryLookup from directory in FileSystemExtensions.GetDirectories(grouping.Key) orderby directory.Length descending select directory; // Remove files from every directory foreach (var directory in directories) { var directoryFiles = directoryLookup.Contains(directory) ? directoryLookup[directory] : Enumerable.Empty <IPackageFile>(); if (!project.DirectoryExists(directory)) { continue; } foreach (var file in directoryFiles) { // Remove the content folder from the path string path = ResolvePath(project, file.Path); // Try to get the package file modifier for the extension string extension = Path.GetExtension(file.Path); IPackageFileTransformer transformer; if (fileTransformers.TryGetValue(extension, out transformer)) { // Remove the extension to get the target path path = RemoveExtension(path); if (project.IsSupportedFile(path)) { var matchingFiles = from p in otherPackages from otherFile in p.GetContentFiles() where otherFile.Path.Equals(file.Path, StringComparison.OrdinalIgnoreCase) select otherFile; try { transformer.RevertFile(file, path, matchingFiles, project); } catch (Exception e) { // Report a warning and move on project.Logger.Log(MessageLevel.Warning, e.Message); } } } else if (project.IsSupportedFile(path)) { project.DeleteFileSafe(path, file.GetStream); } } // If the directory is empty then delete it if (!project.GetFilesSafe(directory).Any() && !project.GetDirectoriesSafe(directory).Any()) { project.DeleteDirectorySafe(directory, recursive: false); } } }
public static void DeleteFiles(this IProjectSystem project, IEnumerable <IPackageFile> files, IEnumerable <IPackage> otherPackages, IDictionary <FileTransformExtensions, IPackageFileTransformer> fileTransformers) { IPackageFileTransformer transformer; ILookup <string, IPackageFile> lookup = Enumerable.ToLookup <IPackageFile, string>(files, p => Path.GetDirectoryName(ResolveTargetPath(project, fileTransformers, fte => fte.UninstallExtension, p.EffectivePath, out transformer))); foreach (string str in from grouping in lookup from directory in FileSystemExtensions.GetDirectories(grouping.Key) orderby directory.Length descending select directory) { IEnumerable <IPackageFile> enumerable = lookup.Contains(str) ? lookup[str] : Enumerable.Empty <IPackageFile>(); if (project.DirectoryExists(str)) { IBatchProcessor <string> processor = project as IBatchProcessor <string>; try { if (processor != null) { Func <IPackageFile, string> < > 9__6; Func <IPackageFile, string> func5 = < > 9__6; if (< > 9__6 == null) { Func <IPackageFile, string> local5 = < > 9__6; func5 = < > 9__6 = file => ResolvePath(fileTransformers, fte => fte.UninstallExtension, file.EffectivePath); } processor.BeginProcessing(Enumerable.Select <IPackageFile, string>(enumerable, func5), PackageAction.Uninstall); } foreach (IPackageFile file in enumerable) { if (!file.IsEmptyFolder()) { string path = ResolveTargetPath(project, fileTransformers, fte => fte.UninstallExtension, file.EffectivePath, out transformer); if (project.IsSupportedFile(path)) { Func <IPackage, IEnumerable <IPackageFile> > < > 9__9; if (transformer == null) { project.DeleteFileSafe(path, new Func <Stream>(file.GetStream)); continue; } Func <IPackage, IEnumerable <IPackageFile> > func4 = < > 9__9; if (< > 9__9 == null) { Func <IPackage, IEnumerable <IPackageFile> > local7 = < > 9__9; func4 = < > 9__9 = p => project.GetCompatibleItemsCore <IPackageFile>(p.GetContentFiles()); } IEnumerable <IPackageFile> matchingFiles = from <> h__TransparentIdentifier0 in Enumerable.SelectMany(otherPackages, func4, (p, otherFile) => new { p = p, otherFile = otherFile }) where < > h__TransparentIdentifier0.otherFile.EffectivePath.Equals(file.EffectivePath, StringComparison.OrdinalIgnoreCase) select <> h__TransparentIdentifier0.otherFile; try { transformer.RevertFile(file, path, matchingFiles, project); } catch (Exception exception) { project.Logger.Log(MessageLevel.Warning, exception.Message, new object[0]); } } } } if (!project.GetFilesSafe(str).Any <string>() && !project.GetDirectoriesSafe(str).Any <string>()) { project.DeleteDirectorySafe(str, false); } } finally { if (processor != null) { processor.EndProcessing(); } } } } }