public void TestGenerateAllFiles_Folder_Sub_File() { IFile staticFile = mocks.DynamicMock <IFile>(); IScript scriptFile = mocks.DynamicMock <IScript>(); IFolder subFolder = mocks.DynamicMock <IFolder>(); ProviderInfo providerMock = mocks.DynamicMock <ProviderInfo>(); using (mocks.Record()) { SetupFolder(subFolder, new IFolder[0], new[] { scriptFile }, new[] { staticFile }, "folder"); SetupFolder(folder, new[] { subFolder }, new IScript[0], new IFile[0], ""); SetupProject(); SetupStaticFile(staticFile); SetupScriptFile(scriptFile); SetupProvider(providerMock); SetupController(); SetupLoader(scriptFile); Expect.Call(() => projectInfo.AddGeneratedFile(new GeneratedFile( "Class.cs", "C:\\Temp\\folder\\Class.cs", "folder\\Class.cs", "Class", "Iterator"))); Expect.Call(() => projectInfo.AddGeneratedFile(new GeneratedFile( "file.jpg", "C:\\Temp\\folder\\file.jpg", "folder\\file.jpg", "", "Iterator"))); } GenerationHelper helper = new GenerationHelper(progressHelper, loader, projectInfo, fileController); ProjectFileTree tree = new ProjectFileTree(); helper.GenerateAllFiles("", folder, tree, scriptObject, "C:\\Temp"); Assert.That(tree.AllNodes.Count, Is.EqualTo(3)); ProjectFileTreeNode subfolder = tree.ChildNodes[0]; Assert.That(subfolder.Status, Is.EqualTo(ProjectFileStatusEnum.Folder)); Assert.That(subfolder.Text, Is.EqualTo("folder")); Assert.That(subfolder.ChildNodes.Count, Is.EqualTo(2)); ProjectFileTreeNode childNode = subfolder.ChildNodes[0]; Assert.That(childNode.Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile)); Assert.That(childNode.Text, Is.EqualTo("Class.cs")); Assert.That(childNode.ChildNodes, Is.Empty); Assert.That(childNode.AssociatedFile.RelativeFilePath, Is.EqualTo(Path.Combine("folder", "Class.cs"))); TextFileInformation tfi = (TextFileInformation)childNode.AssociatedFile; Assert.That(tfi.NewGenFile.FilePath, Is.EqualTo(Path.Combine(controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGenerator), childNode.AssociatedFile.RelativeFilePath)), "New Gen file was not assigned to"); childNode = subfolder.ChildNodes[1]; Assert.That(childNode.Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile)); Assert.That(childNode.Text, Is.EqualTo("file.jpg")); Assert.That(childNode.ChildNodes, Is.Empty); Assert.That(childNode.AssociatedFile.RelativeFilePath, Is.EqualTo(Path.Combine("folder", "file.jpg"))); BinaryFileInformation bfi = (BinaryFileInformation)childNode.AssociatedFile; Assert.That(bfi.NewGenFile.FilePath, Is.EqualTo(Path.Combine(controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGenerator), childNode.AssociatedFile.RelativeFilePath)), "New Gen file was not assigned to"); mocks.VerifyAll(); }
public void TestGetConflictBefore_And_After() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 10\r\nline 2\r\nline32\r\nline 4\r\nline54\r\nline6"); tfi.UserFile = new TextFile("line 0\r\nline 12\r\nline 2\r\nline35\r\nline 4\r\nline56\r\nline6"); tfi.PrevGenFile = new TextFile("line 0\r\nline 1\r\nline 2\r\nline3\r\nline 4\r\nline5\r\nline6"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Has.Count(10)); Assert.That(output.LeftLines, Has.Count(10)); VisualDiffOutput.ConflictRange conflict; Assert.That(output.IsLineInConflict(1), Is.True); Assert.That(output.IsLineInConflict(1, out conflict), Is.True); Assert.That(conflict, Is.Not.Null); Assert.That(conflict.StartLineIndex, Is.EqualTo(1)); Assert.That(conflict.EndLineIndex, Is.EqualTo(3)); Assert.That(output.GetConflictAfter(1).StartLineIndex, Is.EqualTo(4)); Assert.That(output.GetConflictBefore(1).StartLineIndex, Is.EqualTo(7)); Assert.That(output.GetConflictAfter(4).StartLineIndex, Is.EqualTo(7)); Assert.That(output.GetConflictBefore(4).StartLineIndex, Is.EqualTo(1)); }
public void TestDeleteLineWithConflicts() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 12\r\nline 2"); tfi.UserFile = new TextFile("line 0\r\nline 13\r\nline 2"); tfi.PrevGenFile = new TextFile("line 0\r\nline 1\r\nline 2"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Has.Count(4)); Assert.That(output.LeftLines, Has.Count(4)); output.RemoveLine(0); Assert.That(output.RightLines, Has.Count(3)); Assert.That(output.LeftLines, Has.Count(3)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line 13")); Assert.That(output.RightLines[0].Text, Is.EqualTo("")); Assert.That(output.RightLines[0].IsVirtual, Is.EqualTo(true)); Assert.That(output.ConflictRanges[0].StartLineIndex, Is.EqualTo(0)); Assert.That(output.ConflictRanges[0].EndLineIndex, Is.EqualTo(2)); }
/// <summary> /// Constructs the form using the given map info as the source of constructs to match, /// and the given file information as a source of constructs to use as matches /// </summary> /// <param name="fileInfo"></param> /// <param name="node"></param> public FormSelectMatch(TextFileInformation fileInfo, CodeRootMapNode node) { InitializeComponent(); FormSelectMatchHeading.Text = ""; ArchAngel.Interfaces.Events.ShadeMainForm(); fileInformation = fileInfo; currentNode = node; if(fileInformation.CodeRootMap == null) { throw new ArgumentException("Cannot match constructs if the diff has not or cannot be performed."); } if (node.ContainsBaseConstruct == false) { throw new ArgumentException( "Cannot match constructs when there are no constucts set in the MapInfoType given. " + "Please set at least one of these constructs before starting the Select Match Form."); } missingObjects = node.DetermineMissingConstructs(); FillOptionsForConstructs(); FillComboBoxes(); SetDefaultSelectedConstruct(); }
public void TestTemplateChange_Delete_At_End() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = tfi.UserFile = new TextFile("line1\nline2"); tfi.NewGenFile = new TextFile("line1"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Is.Not.Empty); Assert.That(output.LeftLines, Is.Not.Empty); Assert.That(output.LeftLines, Has.Count(2)); Assert.That(output.RightLines, Has.Count(2)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line1")); Assert.That(output.LeftLines[1].Text, Is.EqualTo("line2")); Assert.That(output.RightLines[0].Text, Is.EqualTo("line1")); Assert.That(output.RightLines[1].Text, Is.EqualTo("")); Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.RightLines[0].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[1].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.RightLines[1].IsVirtual, Is.True); }
/// <summary> /// Construct a new ucCodeMergeEditor and fill it with information from the given fileInformation. /// </summary> /// <param name="fileInformation">The FileInformation object containing the code files to visually diff and merge. Must have been diffed already, and contain a valid CodeRoot in its DiffFile.</param> public ucCodeMergeEditor(TextFileInformation fileInformation) : this() { if (fileInformation == null) { throw new ArgumentNullException("fileInformation"); } if (fileInformation.IntelliMerge != IntelliMergeType.CSharp || fileInformation.CurrentDiffResult.DiffPerformedSuccessfully == false) { throw new ArgumentException("Can only use this user control with C# files that have been diffed already and have a valid CodeRoot."); } ucTextMergeEditor.TextSyntaxLanguage = Utility.GetSyntaxLanguageForFileInformation(fileInformation); ucTextMergeEditor.MergedFileSavedEvent += ucTextMergeEditor1_MergedFileSavedEvent; this.fileInformation = fileInformation; if (fileInformation.CurrentDiffResult.DiffType == TypeOfDiff.Warning) { SetWarningText(fileInformation.CurrentDiffResult.DiffWarningDescription); } PopulateGrid(); }
public void TestGenerateAllFiles_Script_File() { IScript script = mocks.DynamicMock <IScript>(); ProviderInfo providerMock = mocks.DynamicMock <ProviderInfo>(); using (mocks.Record()) { SetupFolder(folder, new IFolder[0], new[] { script }, new IFile[0], ""); SetupProject(); SetupScriptFile(script); SetupProvider(providerMock); SetupController(); SetupLoader(script); Expect.Call(() => projectInfo.AddGeneratedFile(new GeneratedFile( "Class.cs", "C:\\Temp\\Class.cs", "Class.cs", "Class", "Iterator"))); } GenerationHelper helper = new GenerationHelper(progressHelper, loader, projectInfo, new FileController()); ProjectFileTree tree = new ProjectFileTree(); helper.GenerateAllFiles("", folder, tree, scriptObject, "C:\\Temp"); Assert.That(tree.AllNodes.Count, Is.EqualTo(1)); Assert.That(tree.AllNodes[0].Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile)); Assert.That(tree.AllNodes[0].Text, Is.EqualTo("Class.cs")); Assert.That(tree.ChildNodes[0].AssociatedFile.RelativeFilePath, Is.EqualTo("Class.cs")); TextFileInformation tfi = (TextFileInformation)tree.ChildNodes[0].AssociatedFile; Assert.That(tfi.NewGenFile.FilePath, Is.EqualTo(Path.Combine(controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGenerator), "Class.cs")), "New Gen file was not assigned to"); mocks.VerifyAll(); }
public ucTextMergeEditor(TextFileInformation fileInformation) : this() { this.fileInformation = fileInformation; toolStripButtonEnableEditing.Checked = false; toolStripButtonEnableEditing_CheckedChanged(toolStripButtonEnableEditing, new EventArgs()); // Apply default options SyntaxLanguage language = Utility.GetSyntaxLanguageForFileInformation(fileInformation); editorOriginal.Document.Language = language; editorResolved.Document.Language = language; if (fileInformation.PrevGenFile.HasContents == false) { displayAlgorithm = new TwoWayDiffDisplayAlgorithm(this); WarningText = "The previous version of the file seems to be missing. This merge is a 2 way merge," + " so all changes must be examined to resolve the conflict."; } else { displayAlgorithm = new ThreeWayDiffDisplayAlgorithm(this); } Fill(); }
/// <summary> /// Constructs the form using the given map info as the source of constructs to match, /// and the given file information as a source of constructs to use as matches /// </summary> /// <param name="fileInfo"></param> /// <param name="node"></param> public FormSelectMatch(TextFileInformation fileInfo, CodeRootMapNode node) { InitializeComponent(); FormSelectMatchHeading.Text = ""; ArchAngel.Interfaces.Events.ShadeMainForm(); fileInformation = fileInfo; currentNode = node; if (fileInformation.CodeRootMap == null) { throw new ArgumentException("Cannot match constructs if the diff has not or cannot be performed."); } if (node.ContainsBaseConstruct == false) { throw new ArgumentException( "Cannot match constructs when there are no constucts set in the MapInfoType given. " + "Please set at least one of these constructs before starting the Select Match Form."); } missingObjects = node.DetermineMissingConstructs(); FillOptionsForConstructs(); FillComboBoxes(); SetDefaultSelectedConstruct(); }
protected DiffDisplayAlgorithm(ucTextMergeEditor editor) { mergeEditor = editor; editorOriginal = editor.EditorOriginal; editorResolved = editor.EditorResolved; fileInformation = editor.FileInformation; }
public void SetupAndPerformDiff(string user, string prevGen, string newGen) { tfi = new TextFileInformation(); tfi.UserFile = string.IsNullOrEmpty(user) ? TextFile.Blank : new TextFile(user); tfi.NewGenFile = string.IsNullOrEmpty(newGen) ? TextFile.Blank : new TextFile(newGen); tfi.PrevGenFile = string.IsNullOrEmpty(prevGen) ? TextFile.Blank : new TextFile(prevGen); tfi.PerformDiff(); }
protected void SetupAndPerformDiffWithMD5s(string user, string prevGen, string newGen) { tfi = new TextFileInformation(); tfi.UserFile = string.IsNullOrEmpty(user) ? TextFile.Blank : new TextFile(user); tfi.NewGenFile = string.IsNullOrEmpty(newGen) ? TextFile.Blank : new TextFile(newGen); tfi.PrevGenFile = string.IsNullOrEmpty(prevGen) ? TextFile.Blank : new TextFile(prevGen); tfi.SetPreviousVersionMD5s(Utility.GetCheckSumOfString(prevGen), Utility.GetCheckSumOfString(newGen), Utility.GetCheckSumOfString(user)); tfi.RelativeFilePath = "Class.cs"; tfi.PerformDiff(); }
/// <summary> /// Creates a new No Change editor, which displays the text in the NewGenFile of the file passed to it. /// </summary> /// <param name="textFileInfo">The text file to display.</param> /// <param name="warningText">The warning text to display with the file.</param> public ucNoChangeEditor(TextFileInformation textFileInfo, string warningText) : this(textFileInfo) { warningLabel.Text = warningText; if (warningText != null && warningText.Contains("User's") && warningText.Contains("deleted")) { warningLabel.Text = "It looks like you have deleted this file in your project directory. " + "The template is going to regenerate this file. If you don't want this to happen, " + "uncheck it in the file list. The ability to merge renamed files will be available in a future version of ArchAngel"; } }
public TwoWayVisualDiff(TextFileInformation fileInformation) { if (fileInformation == null) throw new ArgumentNullException("fileInformation"); if (fileInformation.UserFile.HasContents == false) throw new ArgumentException("User file has no contents"); if (fileInformation.NewGenFile.HasContents == false) throw new ArgumentException("Template file has no contents"); this.fileInformation = fileInformation; }
public void Files_Are_Missing_NewGen() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = TextFile.Blank; tfi.PrevGenFile = tfi.UserFile = new TextFile("line 1"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; new TwoWayVisualDiff(tfi); }
/// <summary> /// Creates a new No Change editor, which displays the text in the NewGenFile of the file passed to it. /// </summary> /// <param name="textFileInfo">The text file to display.</param> /// <param name="warningText">The warning text to display with the file.</param> public ucNoChangeEditor(TextFileInformation textFileInfo, string warningText) : this(textFileInfo) { warningLabel.Text = warningText; if(warningText != null && warningText.Contains("User's") && warningText.Contains("deleted")) { warningLabel.Text = "It looks like you have deleted this file in your project directory. " + "The template is going to regenerate this file. If you don't want this to happen, " + "uncheck it in the file list. The ability to merge renamed files will be available in a future version of ArchAngel"; } }
protected static TwoWayVisualDiff GetDiffUtility(string newgen, string user) { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = TextFile.Blank; tfi.UserFile = new TextFile(user); tfi.NewGenFile = new TextFile(newgen); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; return(new TwoWayVisualDiff(tfi)); }
public void Files_Are_Removed_NewGen() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = tfi.UserFile = tfi.NewGenFile = new TextFile("line 1"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; TwoWayVisualDiff diffUtility = new TwoWayVisualDiff(tfi); tfi.NewGenFile = TextFile.Blank; diffUtility.ProcessMergeOutput(); }
public void TestConflictOperations_NoConflicts() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 1\r\nline 2"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.IsLineInConflict(0), Is.False); Assert.That(output.GetConflictBefore(0), Is.Null); Assert.That(output.GetConflictAfter(0), Is.Null); }
public void Test_LoadPrevGenFile() { TextFileInformation tfi = new TextFileInformation(); tfi.RelativeFilePath = RelativePath; ProjectFileTree tree = new ProjectFileTree(); tree.AddChildNode(tfi, RelativePath); tree.LoadPrevGenFiles(controller); // loading a non existant file will result in tfi.PrevGenFile being set to TextFile.Blank Assert.That(tfi.PrevGenFile.FilePath, Is.Null); Assert.That(tfi.PrevGenFile.HasContents, Is.False); Assert.That(tfi.PrevGenFile.IsFileOnDisk, Is.False); }
public void TestToString() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 1\r\nline 2"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.ToString().Contains("Left Lines")); Assert.That(output.ToString().Contains("Right Lines")); Assert.That(output.ToString().IndexOf("line 0"), Is.Not.EqualTo(output.ToString().LastIndexOf("line 0"))); }
public void TestConflict_At_Start_Add_At_End() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = new TextFile( "line1\nline3"); tfi.UserFile = new TextFile("line00\nline1\nline2\nline3"); tfi.NewGenFile = new TextFile("line0\nline1\nline3\nline4"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Is.Not.Empty); Assert.That(output.LeftLines, Is.Not.Empty); Assert.That(output.LeftLines, Has.Count(6)); Assert.That(output.RightLines, Has.Count(6)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line00"), "Line 1 on left"); Assert.That(output.LeftLines[1].Text, Is.EqualTo("line0"), "Line 2 on left"); Assert.That(output.LeftLines[2].Text, Is.EqualTo("line1"), "Line 3 on left"); Assert.That(output.LeftLines[3].Text, Is.EqualTo(""), "Line 4 on left"); Assert.That(output.LeftLines[4].Text, Is.EqualTo("line3"), "Line 5 on left"); Assert.That(output.LeftLines[5].Text, Is.EqualTo(""), "Line 5 on left"); Assert.That(output.RightLines[0].Text, Is.EqualTo(""), "Line 1 on right"); Assert.That(output.RightLines[1].Text, Is.EqualTo(""), "Line 2 on right"); Assert.That(output.RightLines[2].Text, Is.EqualTo("line1"), "Line 3 on right"); Assert.That(output.RightLines[3].Text, Is.EqualTo("line2"), "Line 4 on right"); Assert.That(output.RightLines[4].Text, Is.EqualTo("line3"), "Line 5 on right"); Assert.That(output.RightLines[5].Text, Is.EqualTo("line4"), "Line 6 on right"); Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.LeftLines[2].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[3].IsVirtual, Is.True); Assert.That(output.LeftLines[4].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[5].IsVirtual, Is.True); Assert.That(output.RightLines[0].IsVirtual, Is.True); Assert.That(output.RightLines[1].IsVirtual, Is.True); Assert.That(output.RightLines[2].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[3].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.RightLines[4].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[5].Change, Is.EqualTo(ChangeType.Template)); }
public void TestConflict_At_Start_Add_At_End() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = new TextFile("line1\nline3"); tfi.UserFile = new TextFile("line00\nline1\nline2\nline3"); tfi.NewGenFile = new TextFile("line0\nline1\nline3\nline4"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Is.Not.Empty); Assert.That(output.LeftLines, Is.Not.Empty); Assert.That(output.LeftLines, Has.Count(6)); Assert.That(output.RightLines, Has.Count(6)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line00"), "Line 1 on left"); Assert.That(output.LeftLines[1].Text, Is.EqualTo("line0"), "Line 2 on left"); Assert.That(output.LeftLines[2].Text, Is.EqualTo("line1"), "Line 3 on left"); Assert.That(output.LeftLines[3].Text, Is.EqualTo(""), "Line 4 on left"); Assert.That(output.LeftLines[4].Text, Is.EqualTo("line3"), "Line 5 on left"); Assert.That(output.LeftLines[5].Text, Is.EqualTo(""), "Line 5 on left"); Assert.That(output.RightLines[0].Text, Is.EqualTo(""), "Line 1 on right"); Assert.That(output.RightLines[1].Text, Is.EqualTo(""), "Line 2 on right"); Assert.That(output.RightLines[2].Text, Is.EqualTo("line1"), "Line 3 on right"); Assert.That(output.RightLines[3].Text, Is.EqualTo("line2"), "Line 4 on right"); Assert.That(output.RightLines[4].Text, Is.EqualTo("line3"), "Line 5 on right"); Assert.That(output.RightLines[5].Text, Is.EqualTo("line4"), "Line 6 on right"); Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.LeftLines[2].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[3].IsVirtual, Is.True); Assert.That(output.LeftLines[4].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[5].IsVirtual, Is.True); Assert.That(output.RightLines[0].IsVirtual, Is.True); Assert.That(output.RightLines[1].IsVirtual, Is.True); Assert.That(output.RightLines[2].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[3].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.RightLines[4].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[5].Change, Is.EqualTo(ChangeType.Template)); }
public TwoWayVisualDiff(TextFileInformation fileInformation) { if (fileInformation == null) { throw new ArgumentNullException("fileInformation"); } if (fileInformation.UserFile.HasContents == false) { throw new ArgumentException("User file has no contents"); } if (fileInformation.NewGenFile.HasContents == false) { throw new ArgumentException("Template file has no contents"); } this.fileInformation = fileInformation; }
public void TestExactCopy() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("aklsdjflkjasdf"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.DiffType, Is.EqualTo(TypeOfDiff.ExactCopy)); Assert.That(output.RightLines, Has.Count(1)); Assert.That(output.LeftLines, Has.Count(1)); Assert.That(output.LeftLines[0].Text, Is.EqualTo(tfi.NewGenFile.GetContents())); Assert.That(output.RightLines[0].Text, Is.EqualTo(tfi.NewGenFile.GetContents())); }
public void Files_Are_Exact_Copy_PrevGen_Missing() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = TextFile.Blank; tfi.UserFile = tfi.NewGenFile = new TextFile("line 1"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; TwoWayVisualDiff diffUtility = new TwoWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.That(output, Is.Not.Null); Assert.That(output.LineCount, Is.EqualTo(1)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line 1")); Assert.That(output.RightLines[0].Text, Is.EqualTo("line 1")); }
public void UserAndTemplate_Two_Changes_In_Middle() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = new TextFile("line0\nline1\nline2\nline3"); tfi.UserFile = new TextFile("line0\nline11\nline12\nline2\nline3"); tfi.NewGenFile = new TextFile("line0\nline1\nline21\nline3"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.That(output.DiffType, Is.EqualTo(Slyce.IntelliMerge.TypeOfDiff.UserAndTemplateChange)); Assert.IsNotNull(output); Assert.That(output.RightLines, Is.Not.Empty); Assert.That(output.LeftLines, Is.Not.Empty); Assert.That(output.LeftLines, Has.Count(5)); Assert.That(output.RightLines, Has.Count(5)); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line0")); Assert.That(output.LeftLines[1].Text, Is.EqualTo("line1")); Assert.That(output.LeftLines[2].Text, Is.EqualTo("")); Assert.That(output.LeftLines[3].Text, Is.EqualTo("line2")); Assert.That(output.LeftLines[4].Text, Is.EqualTo("line3")); Assert.That(output.RightLines[0].Text, Is.EqualTo("line0")); Assert.That(output.RightLines[1].Text, Is.EqualTo("line11")); Assert.That(output.RightLines[2].Text, Is.EqualTo("line12")); Assert.That(output.RightLines[3].Text, Is.EqualTo("line21")); Assert.That(output.RightLines[4].Text, Is.EqualTo("line3")); Assert.That(output.LeftLines[0].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.LeftLines[1].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.LeftLines[2].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.LeftLines[2].IsVirtual, Is.EqualTo(true)); Assert.That(output.LeftLines[3].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.LeftLines[4].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[0].Change, Is.EqualTo(ChangeType.None)); Assert.That(output.RightLines[1].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.RightLines[2].Change, Is.EqualTo(ChangeType.User)); Assert.That(output.RightLines[3].Change, Is.EqualTo(ChangeType.Template)); Assert.That(output.RightLines[4].Change, Is.EqualTo(ChangeType.None)); }
private void DisplayNodeFiles(CodeRootMapNode node) { if (DesignMode) { return; } string userText = ""; string templateText = ""; string prevGenText = null; if (node.MergedObj != null && node.DiffTypeExcludingChildren == TypeOfDiff.ExactCopy) { userText = node.MergedObj.IsLeaf ? node.MergedObj.GetFullText() : node.MergedObj.GetOuterText(); userText = Common.Utility.StandardizeLineBreaks(userText, Common.Utility.LineBreaks.Unix); templateText = prevGenText = userText; } else { if (node.UserObj != null) { userText = GetObjectText(node.UserObj); } if (node.NewGenObj != null) { templateText = GetObjectText(node.NewGenObj); } if (node.PrevGenObj != null) { prevGenText = GetObjectText(node.PrevGenObj); } } TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = prevGenText != null ? new TextFile(prevGenText) : TextFile.Blank; tfi.NewGenFile = new TextFile(templateText); tfi.UserFile = new TextFile(userText); tfi.RelativeFilePath = FileInformation.RelativeFilePath; tfi.IntelliMerge = IntelliMergeType.PlainText; ucTextMergeEditor.FileInformation = tfi; }
public CodeTestForm() { InitializeComponent(); if (DesignMode == false) { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = new TextFile("namespace Test{\npublic class TestClass {\npublic int i;\npublic void FunctionName() {\ni = 0;\n}\n}\n}"); tfi.NewGenFile = new TextFile("namespace Test{\npublic class TestClass {\npublic int i;\npublic int j;\npublic void FunctionName() {\ni = 0;\nj = 0;\n}\n}\n}"); tfi.UserFile = new TextFile("namespace Test{\npublic class TestClass {\npublic int i;\npublic int j;\npublic void FunctionName() {\nk = 0;\ni = 0;\n}\n}\n}"); tfi.RelativeFilePath = "Test.cs"; tfi.IntelliMerge = IntelliMergeType.CSharp; tfi.PerformDiff(); ucCodeMergeEditor codeMergeEditor = new ucCodeMergeEditor(tfi); codeMergeEditor.Dock = DockStyle.Fill; this.Controls.Add(codeMergeEditor); } }
public void Folder_And_File() { AnalysisProgressHelperStub helperStub = new AnalysisProgressHelperStub(); ProjectFileTree tree = new ProjectFileTree(); TextFileInformation tfi = new TextFileInformation(); tfi.RelativeFilePath = "Class.cs"; tfi.PrevGenFile = tfi.NewGenFile = tfi.UserFile = new TextFile("public class SomeClass { }"); tree.AddChildNode("folder").AddChildNode(tfi, "Class.cs"); AnalysisHelper ah = new AnalysisHelper(); ah.StartAnalysis(helperStub, controller, tree); Assert.That(tfi.CurrentDiffResult.DiffType, Is.EqualTo(TypeOfDiff.ExactCopy)); Assert.That(helperStub.Count, Is.EqualTo(0)); Assert.That(helperStub.LastProgressObjectList.Count, Is.EqualTo(4)); AnalyseFilesProgress progress = (AnalyseFilesProgress)helperStub.LastProgressObjectList[2]; Assert.That(progress, Is.Not.Null); Assert.That(progress.NumberOfConflicts, Is.EqualTo(0)); Assert.That(progress.NumberOfResolved, Is.EqualTo(0)); Assert.That(progress.NumberOfExactCopies, Is.EqualTo(0)); Assert.That(progress.ChangedFilePath, Is.EqualTo("folder\\Class.cs")); Assert.That(progress.ChangedFileStatus, Is.EqualTo(ProjectFileStatusEnum.Busy)); progress = (AnalyseFilesProgress)helperStub.LastProgressObjectList[3]; Assert.That(progress, Is.Not.Null); Assert.That(progress.NumberOfConflicts, Is.EqualTo(0)); Assert.That(progress.NumberOfResolved, Is.EqualTo(0)); Assert.That(progress.NumberOfExactCopies, Is.EqualTo(1)); Assert.That(progress.ChangedFilePath, Is.EqualTo("folder\\Class.cs")); Assert.That(progress.ChangedFileStatus, Is.EqualTo(ProjectFileStatusEnum.AnalysedFile)); string nl = Environment.NewLine; Assert.That(tfi.CalculateMergedFile(), Is.True); Assert.That(tfi.MergedFile.HasContents, Is.True); Assert.That(tfi.MergedFile.GetContents(), Is.EqualTo(nl + "public class SomeClass" + nl + "{" + nl + nl + "}")); }
public void TestDeleteLine() { TextFileInformation tfi = new TextFileInformation(); tfi.NewGenFile = new TextFile("line 0\r\nline 1\r\nline 2"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; ThreeWayVisualDiff diffUtility = new ThreeWayVisualDiff(tfi); VisualDiffOutput output = diffUtility.ProcessMergeOutput(); Assert.IsNotNull(output); Assert.That(output.RightLines, Has.Count(3)); Assert.That(output.LeftLines, Has.Count(3)); output.RemoveLine(0); Assert.That(output.RightLines, Has.Count(2)); Assert.That(output.LeftLines, Has.Count(2)); Assert.That(output.RightLines[0].Text, Is.EqualTo("line 1")); Assert.That(output.LeftLines[0].Text, Is.EqualTo("line 1")); }
/// <summary> /// Construct a new ucCodeMergeEditor and fill it with information from the given fileInformation. /// </summary> /// <param name="fileInformation">The FileInformation object containing the code files to visually diff and merge. Must have been diffed already, and contain a valid CodeRoot in its DiffFile.</param> public ucCodeMergeEditor(TextFileInformation fileInformation) : this() { if (fileInformation == null) throw new ArgumentNullException("fileInformation"); if (fileInformation.IntelliMerge != IntelliMergeType.CSharp || fileInformation.CurrentDiffResult.DiffPerformedSuccessfully == false) { throw new ArgumentException("Can only use this user control with C# files that have been diffed already and have a valid CodeRoot."); } ucTextMergeEditor.TextSyntaxLanguage = Utility.GetSyntaxLanguageForFileInformation(fileInformation); ucTextMergeEditor.MergedFileSavedEvent += ucTextMergeEditor1_MergedFileSavedEvent; this.fileInformation = fileInformation; if (fileInformation.CurrentDiffResult.DiffType == TypeOfDiff.Warning) { SetWarningText(fileInformation.CurrentDiffResult.DiffWarningDescription); } PopulateGrid(); }
public ucTextMergeEditor(TextFileInformation fileInformation) : this() { this.fileInformation = fileInformation; toolStripButtonEnableEditing.Checked = false; toolStripButtonEnableEditing_CheckedChanged(toolStripButtonEnableEditing, new EventArgs()); // Apply default options SyntaxLanguage language = Utility.GetSyntaxLanguageForFileInformation(fileInformation); editorOriginal.Document.Language = language; editorResolved.Document.Language = language; if (fileInformation.PrevGenFile.HasContents == false) { displayAlgorithm = new TwoWayDiffDisplayAlgorithm(this); WarningText = "The previous version of the file seems to be missing. This merge is a 2 way merge," + " so all changes must be examined to resolve the conflict."; } else displayAlgorithm = new ThreeWayDiffDisplayAlgorithm(this); Fill(); }
protected static TwoWayVisualDiff GetDiffUtility(string newgen, string user) { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = TextFile.Blank; tfi.UserFile = new TextFile(user); tfi.NewGenFile = new TextFile(newgen); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; return new TwoWayVisualDiff(tfi); }
public void Files_Are_Removed_User() { TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = tfi.NewGenFile = tfi.UserFile = new TextFile("line 1"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; TwoWayVisualDiff diffUtility = new TwoWayVisualDiff(tfi); tfi.UserFile = TextFile.Blank; diffUtility.ProcessMergeOutput(); }
private bool ProcessScriptObject(ITaskProgressHelper <GenerateFilesProgress> progressHelper, object scriptObject, string folderName, IScript script, ProjectFileTreeNode parentNode) { bool success = true; string scriptName = UpdateScriptName(scriptObject, script); string fileName = Path.Combine(folderName, scriptName); if (scriptName.IndexOf("#") >= 0) { success = false; } if (success) { TextFileInformation fileInfo = new TextFileInformation(); fileInfo.RelativeFilePath = fileName; try { object[] parameters = new object[0]; if (project.FileSkippingIsImplemented) { try { // Reset the SkipCurrentFile variable _Loader.CallTemplateFunction("InternalFunctions.ResetSkipCurrentFile", ref parameters); } catch { project.FileSkippingIsImplemented = false; } } // Call the script file function to get the file text body parameters = new[] { scriptObject }; // Check whether we must skip the current file string str = (string)_Loader.CallTemplateFunction(script.ScriptName, ref parameters); if (progressHelper.IsCancellationPending()) { return(false); } parameters = new object[0]; bool skipCurrentFile = false; if (project.FileSkippingIsImplemented) { skipCurrentFile = (bool)_Loader.CallTemplateFunction("InternalFunctions.MustSkipCurrentFile", ref parameters); } if (!skipCurrentFile) { str = Utility.StandardizeLineBreaks(str, Utility.LineBreaks.Windows); string fullPath = Path.Combine( _Controller.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator), fileName); _Loader.WriteScriptToFile(str, fullPath); fileInfo.NewGenFile = new TextFile(fullPath, false); string versionNumberString = _Loader.GetAssemblyVersionNumber(); VersionNumber versionNumber; if (VersionNumber.TryParse(versionNumberString, out versionNumber)) { // Get the template language from the template function. string templateLanguageString = _Loader.GetTemplateFunctionLanguage(script.ScriptName); try { fileInfo.TemplateLanguage = SyntaxEditorHelper.LanguageEnumFromName(templateLanguageString); } catch (NotImplementedException) { fileInfo.TemplateLanguage = null; } } parentNode.AddChildNode(fileInfo, scriptName); AddFileCountToPreviousEventAndRefire(progressHelper, 1); } } catch (Slyce.Loader.Exceptions.TemplateFunctionException ex) { success = false; string message = "<span class='error'>" + ex.Message + "</span>"; if (ex.InnerException != null) { message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" + Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) + Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite; } RaiseTemplateFunctionCallErrorEvent(ex); // Do nothing, just skip the file because the error will get reported to the user. parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message); } catch (Exception ex) { string message = "<span class='error'>" + ex.Message + "</span>"; if (ex.InnerException != null) { message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" + Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) + Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite; } parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message); // Make sure any other type of exception gets thrown throw; } } return(success); }
private bool ProcessScriptObject(object scriptObject, string folderName, IScript script, ProjectFileTreeNode parentNode) { bool success = true; string scriptName = UpdateScriptName(scriptObject, script); string fileName = Path.Combine(folderName, scriptName); _Loader.SetGeneratedFileNameOnTemplate(Path.Combine(_Project.ProjectSettings.OutputPath, fileName)); if (scriptName.IndexOf("#") >= 0) { success = false; } if (success) { TextFileInformation fileInfo = new TextFileInformation(); fileInfo.RelativeFilePath = fileName; try { // Reset the SkipCurrentFile and CurrentFileName variable _Loader.CallTemplateFunction(TemplateHelper.ResetSkipCurrentFileFunctionName); _Loader.CallTemplateFunction(TemplateHelper.ResetCurrentFileNameFunctionName); // Call the script file function to get the file text body object[] parameters = new[] { scriptObject }; // Check whether we must skip the current file string templateOutput = (string)_Loader.CallTemplateFunction(script.ScriptName, ref parameters); if (_ProgressHelper.IsCancellationPending()) { return(false); } bool skipCurrentFile = (bool)_Loader.CallTemplateFunction(TemplateHelper.GetSkipCurrentFileFunctionName); if (!skipCurrentFile) { templateOutput = Utility.StandardizeLineBreaks(templateOutput, Utility.LineBreaks.Windows); string codeInsertionFilename = (string)_Loader.CallTemplateFunction(TemplateHelper.GetCurrentFileNameFunctionName); if (string.IsNullOrEmpty(codeInsertionFilename)) { string fullPath = Path.Combine(absoluteBasePath, fileName); _FileController.WriteAllText(fullPath, templateOutput); // The file has successfully been written - add it to the GeneratedFiles _Project.AddGeneratedFile(new GeneratedFile(script.FileName, fullPath, fileName, script.ScriptName, script.IteratorName)); // Set the NewGen text to point to that file. fileInfo.NewGenFile = new TextFile(fullPath, false); string versionNumberString = _Loader.GetAssemblyVersionNumber(); VersionNumber versionNumber; if (VersionNumber.TryParse(versionNumberString, out versionNumber)) { // Get the template language from the template function. string templateLanguageString = _Loader.GetTemplateFunctionLanguage(script.ScriptName); try { fileInfo.TemplateLanguage = SyntaxEditorHelper.LanguageEnumFromName(templateLanguageString); } catch (NotImplementedException) { fileInfo.TemplateLanguage = null; } } if (addToProjectFileTree) { parentNode.AddChildNode(fileInfo, scriptName); } } else { // Code insertions were performed. Need to update a node in the tree. // expand the path if (Path.IsPathRooted(codeInsertionFilename) == false) { codeInsertionFilename = RelativePaths.RelativeToAbsolutePath(absoluteBasePath, codeInsertionFilename); } codeInsertionFilename = _FileController.GetFullPath(codeInsertionFilename); // Get the relative path string relativeCodeInsertionFilename = RelativePaths.GetRelativePath(_Project.ProjectSettings.OutputPath, codeInsertionFilename); // If the file is not under the output path, then reset it to the full path if (relativeCodeInsertionFilename.StartsWith("..")) { relativeCodeInsertionFilename = codeInsertionFilename; // We need to add its folder as a root node of the tree if (!parentNode.IsTreeRoot) { parentNode = parentNode.ParentTree; } } fileInfo.RelativeFilePath = relativeCodeInsertionFilename; string relPathStart = "." + Path.DirectorySeparatorChar; if (fileInfo.RelativeFilePath.StartsWith(relPathStart)) { fileInfo.RelativeFilePath = fileInfo.RelativeFilePath.Substring(2); } if (addToProjectFileTree) { ProjectFileTree tree; if (!parentNode.IsTreeRoot) { tree = parentNode.ParentTree; } else { tree = (ProjectFileTree)parentNode; } var possibleNode = tree.GetNodeAtPath(codeInsertionFilename); if (possibleNode == null) { // Need to create this node. // Create the node and it's parent folders if need be var node = tree.CreateFileNodeForPath(relativeCodeInsertionFilename); node.AssociatedFile = fileInfo; } else { // Update the NewGen text, don't add it to the generated files list. fileInfo = possibleNode.AssociatedFile as TextFileInformation; if (fileInfo == null) { throw new NotSupportedException("Cannot code merge a binary file"); } } } else { // Write the file to disk _FileController.WriteAllText(codeInsertionFilename, templateOutput); } fileInfo.NewGenFile = new TextFile(templateOutput); } AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1); } } catch (TemplateFunctionException ex) { success = false; string message = "<span class='error'>" + ex.Message + "</span>"; if (ex.InnerException != null) { message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" + Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) + Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite; } RaiseTemplateFunctionCallErrorEvent(ex); // Do nothing, just skip the file because the error will get reported to the user. if (addToProjectFileTree) { parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message); } } catch (Exception ex) { string message = "<span class='error'>" + ex.Message + "</span>"; if (ex.InnerException != null) { message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" + Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) + Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite; } if (addToProjectFileTree) { parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message); } // Make sure any other type of exception gets thrown throw; } } return(success); }
private void ProcessFile(ArchAngel.Interfaces.Template.File file, string path, ProjectFileTreeNode parentNode, object parentFolderIteratorObject) { string filePath; string relativeFilePath = null; string body; string fileName; TextFileInformation fileInfo; bool skipFile = false; switch (file.Iterator) { case ArchAngel.Interfaces.Template.IteratorTypes.None: try { fileName = GetFileName(file.Id, null); } catch (Exception ex) { fileName = "ERROR"; filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; ProcessFileGenerationException(parentNode, file.Id, fileName, fileInfo, ex); NumFiles++; return; } filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; try { CopyUserFileToGenerationLocation(filePath, fileInfo); CurrentFilePathProperty.SetValue(null, filePath, null); body = Utility.StandardizeLineBreaks(GetFileBody(file.Id, null, out skipFile), Utility.LineBreaks.Windows); string newFilePath = (string)CurrentFilePathProperty.GetValue(null, null); if (newFilePath != filePath) { //filePath = newFilePath; //relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; } } catch (Exception ex) { ProcessFileGenerationException(parentNode, file.Id, fileName, fileInfo, ex); return; } if (!skipFile) { Slyce.Common.Utility.DeleteFileBrute(filePath); System.IO.File.WriteAllText(filePath, body); parentNode.AddChildNode(fileInfo, fileName); AllTextFilenames.Add(new FilenameInfo(fileName, file.Name, file.Iterator, FilenameInfo.FilenameTypes.GeneratedFile) { RelativePath = relativeFilePath }); NumFiles++; } break; case ArchAngel.Interfaces.Template.IteratorTypes.Entity: List<ArchAngel.Interfaces.Scripting.NHibernate.Model.IEntity> entities = new List<Interfaces.Scripting.NHibernate.Model.IEntity>(); if (parentFolderIteratorObject == null) entities = ScriptProject.Entities; else if (parentFolderIteratorObject is Interfaces.Scripting.NHibernate.Model.IEntity) { entities = new List<Interfaces.Scripting.NHibernate.Model.IEntity>(); entities.Add((ArchAngel.Interfaces.Scripting.NHibernate.Model.IEntity)parentFolderIteratorObject); } else throw new InvalidDataException(string.Format("File iterator is 'Entity' but parent folder is '{0}'. Iterator can therefore only be: 'Entity', 'None'.", parentFolderIteratorObject.GetType().Name)); foreach (var entity in entities) { try { fileName = GetFileName(file.Id, entity); } catch (Exception ex) { fileName = GetNodeDisplayText(file.Name, string.Format("[{0}]", entity.Name)); filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; ProcessFileGenerationException(parentNode, file.Id, fileName, fileInfo, ex); NumFiles++; continue; } filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; try { CopyUserFileToGenerationLocation(filePath, fileInfo); CurrentFilePathProperty.SetValue(null, filePath, null); body = Utility.StandardizeLineBreaks(GetFileBody(file.Id, entity, out skipFile), Utility.LineBreaks.Windows); string newFilePath = (string)CurrentFilePathProperty.GetValue(null, null); if (newFilePath != filePath) { //filePath = newFilePath; //relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; } } catch (Exception ex) { ProcessFileGenerationException(parentNode, file.Id, fileName, fileInfo, ex); continue; } if (!skipFile) { Slyce.Common.Utility.DeleteFileBrute(filePath); System.IO.File.WriteAllText(filePath, body); parentNode.AddChildNode(fileInfo, fileName); AllTextFilenames.Add(new FilenameInfo(fileName, file.Name, file.Iterator, FilenameInfo.FilenameTypes.GeneratedFile) { RelativePath = relativeFilePath }); NumFiles++; } } break; case ArchAngel.Interfaces.Template.IteratorTypes.Component: foreach (var component in ScriptProject.Components) { try { fileName = GetFileName(file.Id, component); } catch (Exception ex) { fileName = "ERROR"; filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; ProcessFileGenerationException(parentNode, file.Id, fileName, fileInfo, ex); NumFiles++; continue; } filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; try { CopyUserFileToGenerationLocation(filePath, fileInfo); CurrentFilePathProperty.SetValue(null, filePath, null); body = Utility.StandardizeLineBreaks(GetFileBody(file.Id, component, out skipFile), Utility.LineBreaks.Windows); string newFilePath = (string)CurrentFilePathProperty.GetValue(null, null); if (newFilePath != filePath) { //filePath = newFilePath; //relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; } } catch (Exception ex) { ProcessFileGenerationException(parentNode, file.Id, fileName, fileInfo, ex); continue; } if (!skipFile) { Slyce.Common.Utility.DeleteFileBrute(filePath); System.IO.File.WriteAllText(filePath, body); parentNode.AddChildNode(fileInfo, fileName); AllTextFilenames.Add(new FilenameInfo(fileName, file.Name, file.Iterator, FilenameInfo.FilenameTypes.GeneratedFile) { RelativePath = relativeFilePath }); NumFiles++; } } break; case ArchAngel.Interfaces.Template.IteratorTypes.Table: List<ArchAngel.Interfaces.Scripting.NHibernate.Model.ITable> tables = new List<Interfaces.Scripting.NHibernate.Model.ITable>(); if (parentFolderIteratorObject == null) tables = ScriptProject.Tables; else if (parentFolderIteratorObject is Interfaces.Scripting.NHibernate.Model.ITable) { tables = new List<Interfaces.Scripting.NHibernate.Model.ITable>(); tables.Add((ArchAngel.Interfaces.Scripting.NHibernate.Model.ITable)parentFolderIteratorObject); } else throw new InvalidDataException(string.Format("File iterator is 'Table' but parent folder is '{0}'. Iterator can therefore only be: 'Table', 'None'.", parentFolderIteratorObject.GetType().Name)); foreach (var table in tables) { try { fileName = GetFileName(file.Id, table); } catch (Exception ex) { fileName = "ERROR"; filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; ProcessFileGenerationException(parentNode, file.Id, fileName, fileInfo, ex); NumFiles++; continue; } filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; try { CopyUserFileToGenerationLocation(filePath, fileInfo); CurrentFilePathProperty.SetValue(null, filePath, null); body = Utility.StandardizeLineBreaks(GetFileBody(file.Id, table, out skipFile), Utility.LineBreaks.Windows); string newFilePath = (string)CurrentFilePathProperty.GetValue(null, null); if (newFilePath != filePath) { //filePath = newFilePath; //relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new TextFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new TextFile(filePath, false), Encoding = file.Encoding }; } } catch (Exception ex) { ProcessFileGenerationException(parentNode, file.Id, fileName, fileInfo, ex); continue; } if (!skipFile) { Slyce.Common.Utility.DeleteFileBrute(filePath); System.IO.File.WriteAllText(filePath, body); parentNode.AddChildNode(fileInfo, fileName); AllTextFilenames.Add(new FilenameInfo(fileName, file.Name, file.Iterator, FilenameInfo.FilenameTypes.GeneratedFile) { RelativePath = relativeFilePath }); NumFiles++; } } break; default: throw new NotImplementedException("This iterator not handled yet: " + file.Iterator.ToString()); } }
private void ProcessFileGenerationException(ProjectFileTreeNode parentNode, int fileId, string fileName, TextFileInformation fileInfo, Exception ex) { int line; string cleanStackTrace = GetCleanStackTrace(ex.InnerException.StackTrace, fileId, out line); string message = string.Format("<span class='filename'><b>Error Message:</b></span>{0}<span class='error'>{1}{0}{0}</span><span class='filename'><b>Stacktrace:</b></span>{0}<span class='error'>{2}</span>", "<br/> ", ex.InnerException.Message, cleanStackTrace); parentNode.AddChildNode(fileInfo, fileName).GenerationError = new GenerationError(fileName, message); NumFiles++; }
private void DisplayNodeFiles(CodeRootMapNode node) { if (DesignMode) return; string userText = ""; string templateText = ""; string prevGenText = null; if (node.MergedObj != null && node.DiffTypeExcludingChildren == TypeOfDiff.ExactCopy) { userText = node.MergedObj.IsLeaf ? node.MergedObj.GetFullText() : node.MergedObj.GetOuterText(); userText = Common.Utility.StandardizeLineBreaks(userText, Common.Utility.LineBreaks.Unix); templateText = prevGenText = userText; } else { if (node.UserObj != null) { userText = GetObjectText(node.UserObj); } if (node.NewGenObj != null) { templateText = GetObjectText(node.NewGenObj); } if (node.PrevGenObj != null) { prevGenText = GetObjectText(node.PrevGenObj); } } TextFileInformation tfi = new TextFileInformation(); tfi.PrevGenFile = prevGenText != null ? new TextFile(prevGenText) : TextFile.Blank; tfi.NewGenFile = new TextFile(templateText); tfi.UserFile = new TextFile(userText); tfi.RelativeFilePath = FileInformation.RelativeFilePath; tfi.IntelliMerge = IntelliMergeType.PlainText; ucTextMergeEditor.FileInformation = tfi; }
public MergedFileSavedEventArgs(TextFile mergedFile, TextFileInformation fileInfo) { this.mergedFile = mergedFile; fileInformation = fileInfo; }
public void TestInvalidSuperDiff_NoFiles() { TextFileInformation tfi = new TextFileInformation(); tfi.PerformSuperDiff(); }
public void Files_Are_Missing_User() { TextFileInformation tfi = new TextFileInformation(); tfi.UserFile = TextFile.Blank; tfi.PrevGenFile = tfi.NewGenFile = new TextFile("line 1"); tfi.IntelliMerge = IntelliMergeType.PlainText; tfi.RelativeFilePath = "text.txt"; new TwoWayVisualDiff(tfi); }
private static void CopyUserFileToGenerationLocation(string genFilePath, TextFileInformation fileInfo) { CopyUserFileToGenerationLocation(genFilePath, fileInfo.RelativeFilePath); }
private bool ProcessScriptObject(ITaskProgressHelper<GenerateFilesProgress> progressHelper, object scriptObject, string folderName, IScript script, ProjectFileTreeNode parentNode) { bool success = true; string scriptName = UpdateScriptName(scriptObject, script); string fileName = Path.Combine(folderName, scriptName); if (scriptName.IndexOf("#") >= 0) { success = false; } if (success) { TextFileInformation fileInfo = new TextFileInformation(); fileInfo.RelativeFilePath = fileName; try { object[] parameters = new object[0]; if (project.FileSkippingIsImplemented) { try { // Reset the SkipCurrentFile variable _Loader.CallTemplateFunction("InternalFunctions.ResetSkipCurrentFile", ref parameters); } catch { project.FileSkippingIsImplemented = false; } } // Call the script file function to get the file text body parameters = new[] { scriptObject }; // Check whether we must skip the current file string str = (string)_Loader.CallTemplateFunction(script.ScriptName, ref parameters); if (progressHelper.IsCancellationPending()) return false; parameters = new object[0]; bool skipCurrentFile = false; if (project.FileSkippingIsImplemented) { skipCurrentFile = (bool)_Loader.CallTemplateFunction("InternalFunctions.MustSkipCurrentFile", ref parameters); } if (!skipCurrentFile) { str = Utility.StandardizeLineBreaks(str, Utility.LineBreaks.Windows); string fullPath = Path.Combine( _Controller.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator), fileName); _Loader.WriteScriptToFile(str, fullPath); fileInfo.NewGenFile = new TextFile(fullPath, false); string versionNumberString = _Loader.GetAssemblyVersionNumber(); VersionNumber versionNumber; if (VersionNumber.TryParse(versionNumberString, out versionNumber)) { // Get the template language from the template function. string templateLanguageString = _Loader.GetTemplateFunctionLanguage(script.ScriptName); try { fileInfo.TemplateLanguage = SyntaxEditorHelper.LanguageEnumFromName(templateLanguageString); } catch (NotImplementedException) { fileInfo.TemplateLanguage = null; } } parentNode.AddChildNode(fileInfo, scriptName); AddFileCountToPreviousEventAndRefire(progressHelper, 1); } } catch (Slyce.Loader.Exceptions.TemplateFunctionException ex) { success = false; string message = "<span class='error'>" + ex.Message + "</span>"; if (ex.InnerException != null) { message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" + Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) + Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite; } RaiseTemplateFunctionCallErrorEvent(ex); // Do nothing, just skip the file because the error will get reported to the user. parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message); } catch (Exception ex) { string message = "<span class='error'>" + ex.Message + "</span>"; if (ex.InnerException != null) { message += ":<br/>" + Environment.NewLine + "<b>" + ex.InnerException.Message + "</b>" + Environment.NewLine + GetCleanTemplateFunctionErrorStackTrace(ex) + Environment.NewLine + "Target Site: " + ex.InnerException.TargetSite; } parentNode.AddChildNode(fileInfo, scriptName).GenerationError = new GenerationError(fileName, message); // Make sure any other type of exception gets thrown throw; } } return success; }