public void CopyFilesToProject_Execute_ModifiedFile() { var tempFile = Path.GetFullPath(@".\temp\Source.cs"); var path = Path.GetFullPath(@".\temp\Project"); var destPath = Path.GetFullPath(@".\DestinationPath\Project"); var finalFile = Path.GetFullPath(@".\DestinationPath\Source.cs"); Directory.CreateDirectory(path); Directory.CreateDirectory(destPath); File.Copy(Path.Combine(Environment.CurrentDirectory, $"TestData\\Merge\\Source_postaction.cs"), tempFile, true); GenContext.Current = new FakeContextProvider() { DestinationPath = destPath, GenerationOutputPath = path, }; var config = new TempGenerationResult(); config.ModifiedFiles.Add("Source.cs"); var mergePostAction = new CopyFilesToProjectPostAction(config); mergePostAction.Execute(); Assert.True(File.Exists(Path.Combine(Directory.GetParent(destPath).FullName, "Source.cs"))); Directory.Delete(Directory.GetParent(path).FullName, true); Directory.Delete(Directory.GetParent(destPath).FullName, true); Assert.False(GenContext.Current.FilesToOpen.Contains(finalFile)); }
private void ExecuteOutputGenerationPostActions(TempGenerationResult result) { var postActions = PostactionFactory.FindOutputGenerationPostActions(result); foreach (var postAction in postActions) { postAction.Execute(); } }
public override IEnumerable <PostAction> FindOutputGenerationPostActions(TempGenerationResult result) { var postActions = new List <PostAction>(); postActions.Add(new CreateSummaryPostAction(result)); postActions.Add(new OpenFilesPostAction()); return(postActions); }
public override IEnumerable <PostAction> FindSyncGenerationPostActions(TempGenerationResult result) { var postActions = new List <PostAction>(); postActions.Add(new CopyFilesToProjectPostAction(result)); postActions.Add(new AddContextItemsToProjectPostAction()); postActions.Add(new CreateSummaryPostAction(result)); postActions.Add(new OpenFilesPostAction()); return(postActions); }
private TempGenerationResult CompareTempGenerationWithProject() { var result = new TempGenerationResult(); var files = Directory .EnumerateFiles(GenContext.Current.OutputPath, "*", SearchOption.AllDirectories) .Where(f => !Regex.IsMatch(f, MergeConfiguration.PostactionRegex) && !Regex.IsMatch(f, MergeConfiguration.FailedPostactionRegex)) .ToList(); foreach (var file in files) { var destFilePath = file.Replace(GenContext.Current.OutputPath, GenContext.Current.DestinationParentPath); var fileName = file.Replace(GenContext.Current.OutputPath + Path.DirectorySeparatorChar, string.Empty); var projectFileName = Path.GetFullPath(Path.Combine(GenContext.Current.DestinationParentPath, fileName)); if (File.Exists(projectFileName)) { if (GenContext.Current.MergeFilesFromProject.ContainsKey(fileName)) { if (FilesAreEqual(file, destFilePath)) { if (!GenContext.Current.FailedMergePostActions.Any(g => g.FileName == fileName)) { GenContext.Current.MergeFilesFromProject.Remove(fileName); result.UnchangedFiles.Add(fileName); } } else { result.ModifiedFiles.Add(fileName); } } else { if (FilesAreEqual(file, destFilePath)) { result.UnchangedFiles.Add(fileName); } else { result.ConflictingFiles.Add(fileName); } } } else { result.NewFiles.Add(fileName); } } return(result); }
private void ExecuteSyncGenerationPostActions(TempGenerationResult result) { var postActions = PostactionFactory.FindSyncGenerationPostActions(result); foreach (var postAction in postActions) { postAction.Execute(); } // New files aren't listed as project file modifications so any modifications should be new package references, etc. if (result.ModifiedFiles.Any(f => Path.GetExtension(f).EndsWith("proj", StringComparison.OrdinalIgnoreCase))) { // Forcing a package restore so don't get warnings in the designer once addition is complete GenContext.ToolBox.Shell.RestorePackages(); } }
private void BackupProjectFiles(TempGenerationResult result) { var projectGuid = GenContext.ToolBox.Shell.GetActiveProjectGuid(); if (string.IsNullOrEmpty(projectGuid)) { return; } var backupFolder = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), Configuration.Current.BackupFolderPath, projectGuid); var fileName = Path.Combine(backupFolder, "backup.json"); if (Directory.Exists(backupFolder)) { Fs.SafeDeleteDirectory(backupFolder); } Fs.EnsureFolder(backupFolder); File.WriteAllText(fileName, JsonConvert.SerializeObject(result), Encoding.UTF8); var modifiedFiles = result.ConflictingFiles.Concat(result.ModifiedFiles); foreach (var file in modifiedFiles) { var originalFile = Path.Combine(GenContext.Current.DestinationPath, file); var backupFile = Path.Combine(backupFolder, file); var destDirectory = Path.GetDirectoryName(backupFile); Fs.SafeCopyFile(originalFile, destDirectory, true); } }
public virtual IEnumerable <PostAction> FindOutputGenerationPostActions(TempGenerationResult result) { return(new List <PostAction>()); }
public void CreateSummary_Execute_SyncGeneration() { CultureInfo.CurrentUICulture = new CultureInfo("en-US"); var outputPath = Path.GetFullPath(@".\temp\Project"); var destPath = Path.GetFullPath(@".\DestinationPath"); var expectedFile = Path.GetFullPath(@".\TestData\GenerationSummary_expected.md"); GenContext.Current = new TestContextProvider() { DestinationPath = destPath, GenerationOutputPath = outputPath, }; Directory.CreateDirectory(outputPath); var config = new TempGenerationResult(); config.SyncGeneration = true; // New File config.NewFiles.Add("NewFile.cs"); // Modified config.ModifiedFiles.Add("ModifiedFile_Success.cs"); GenContext.Current.MergeFilesFromProject.Add("ModifiedFile_Success.cs", new List <MergeInfo>() { new MergeInfo() { Format = "CSHARP", PostActionCode = "**MERGECODEPLACEHOLDER**" } }); config.ModifiedFiles.Add("ModifiedFile_Error.cs"); GenContext.Current.MergeFilesFromProject.Add("ModifiedFile_Error.cs", new List <MergeInfo>() { new MergeInfo() { Format = "CSHARP", PostActionCode = "**MERGECODEPLACEHOLDER**" } }); GenContext.Current.FailedMergePostActions.Add(new FailedMergePostActionInfo("ModifiedFile_Error.cs", Path.Combine(outputPath, "ModifiedFile_Error.cs"), "ModifiedFile_failedpostaction.cs", Path.Combine(outputPath, "ModifiedFile_failedpostaction.cs"), "TestDescription", MergeFailureType.FileNotFound)); // UnModified config.UnchangedFiles.Add("UnchangedFile.cs"); // Conflicting config.ConflictingFiles.Add("ConflictFile.cs"); var mergePostAction = new CreateSummaryPostAction(config); mergePostAction.Execute(); var filePath = Path.Combine(Directory.GetParent(outputPath).FullName, "GenerationSummary.md"); Assert.True(File.Exists(filePath)); var expected = File.ReadAllText(expectedFile) .Replace("{{projectPath}}", Directory.GetParent(destPath).FullName.Replace(@"\", "/")) .Replace("{{tempPath}}", Directory.GetParent(outputPath).FullName) .Replace("\r\n", string.Empty) .Replace("\n", string.Empty); Assert.Equal(expected, File.ReadAllText(filePath).Replace("\r\n", string.Empty).Replace("\n", string.Empty)); Directory.Delete(Directory.GetParent(outputPath).FullName, true); }