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 TestGenerateAllFiles_Static_File() { IFile file = mocks.DynamicMock <IFile>(); ProviderInfo providerMock = mocks.DynamicMock <ProviderInfo>(); using (mocks.Record()) { SetupFolder(folder, new IFolder[0], new IScript[0], new[] { file }, ""); SetupProject(); SetupLoader(); SetupStaticFile(file); SetupProvider(providerMock); SetupController(); Expect.Call(() => projectInfo.AddGeneratedFile(new GeneratedFile( "file.jpg", "C:\\Temp\\file.jpg", "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(1)); Assert.That(tree.AllNodes[0].Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile)); Assert.That(tree.AllNodes[0].Text, Is.EqualTo("file.jpg")); Assert.That(tree.ChildNodes[0].AssociatedFile.RelativeFilePath, Is.EqualTo("file.jpg")); BinaryFileInformation bfi = (BinaryFileInformation)tree.ChildNodes[0].AssociatedFile; Assert.That(bfi.NewGenFile.FilePath, Is.EqualTo(Path.Combine(controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGenerator), tree.ChildNodes[0].AssociatedFile.RelativeFilePath)), "New Gen file was not assigned to"); mocks.VerifyAll(); }
public void SetupAndPerformDiff(byte[] user, byte[] prevGen, byte[] newGen) { bfi = new BinaryFileInformation(); bfi.RelativeFilePath = filePath; bfi.UserFile = user == null ? BinaryFile.Blank : new BinaryFile(user); bfi.NewGenFile = newGen == null ? BinaryFile.Blank : new BinaryFile(newGen); bfi.PrevGenFile = prevGen == null ? BinaryFile.Blank : new BinaryFile(prevGen); bfi.IntelliMerge = IntelliMergeType.NotSet; Assert.That(bfi.PerformDiff(), Is.EqualTo(true), "Diff not performed correctly"); }
public void Reset(BinaryFileInformation fileInformation) { this.fileInformation = fileInformation; bool versionsSame = ((BinaryFile)fileInformation.UserFile).GetVersionInformation() == ((BinaryFile)fileInformation.NewGenFile).GetVersionInformation(); bool filesizeSame = ((BinaryFile)fileInformation.UserFile).GetFileSize() == ((BinaryFile)fileInformation.NewGenFile).GetFileSize(); bool md5Same = ((BinaryFile)fileInformation.UserFile).GetMD5() == ((BinaryFile)fileInformation.NewGenFile).GetMD5(); if (!fileInformation.UserFile.IsFileOnDisk) { labelHeader.Text = string.Format("New file - {0} [Binary file]", fileInformation.RelativeFilePath); labelHeader.BackgroundStyle.BackColor = Color.Green; labelHeader.BackgroundStyle.BackColor2 = Color.GreenYellow; } else if (versionsSame && filesizeSame && md5Same) { labelHeader.Text = string.Format("No changes - {0} [Binary file]", fileInformation.RelativeFilePath); labelHeader.BackgroundStyle.BackColor = Color.Green; labelHeader.BackgroundStyle.BackColor2 = Color.GreenYellow; } else { labelHeader.Text = string.Format("File is different - {0}", fileInformation.RelativeFilePath); labelHeader.BackgroundStyle.BackColor = Color.Brown; labelHeader.BackgroundStyle.BackColor2 = Color.OrangeRed; } SetVersionInfo(fileInformation.UserFile as BinaryFile, labelExistingFileVersion, versionsSame); SetFileSize(fileInformation.UserFile as BinaryFile, labelExistingFilesize, filesizeSame); SetMD5Info(fileInformation.UserFile as BinaryFile, labelExistingMD5, filesizeSame); SetVersionInfo(fileInformation.NewGenFile as BinaryFile, labelNewFileVersion, versionsSame); SetFileSize(fileInformation.NewGenFile as BinaryFile, labelNewFilesize, filesizeSame); SetMD5Info(fileInformation.NewGenFile as BinaryFile, labelNewMD5, filesizeSame); SetHeading(versionsSame && filesizeSame); int widthExistingMD5 = (int)Graphics.FromHwnd(labelExistingMD5.Handle).MeasureString(labelExistingMD5.Text, labelExistingMD5.Font).Width + 5; int widthExistingHeader = (int)Graphics.FromHwnd(labelExistingHeader.Handle).MeasureString(labelExistingHeader.Text, labelExistingHeader.Font).Width + 5; int widthNewMD5 = (int)Graphics.FromHwnd(labelNewMD5.Handle).MeasureString(labelNewMD5.Text, labelNewMD5.Font).Width + 5; int widthNewHeader = (int)Graphics.FromHwnd(labelNewHeader.Handle).MeasureString(labelNewHeader.Text, labelNewHeader.Font).Width + 5; panelExisting.Width = Math.Max(widthExistingMD5, widthExistingHeader); panelNew.Width = Math.Max(widthNewMD5, widthNewHeader); ; }
public void Reset(BinaryFileInformation fileInformation) { this.fileInformation = fileInformation; bool versionsSame = ((BinaryFile)fileInformation.UserFile).GetVersionInformation() == ((BinaryFile)fileInformation.NewGenFile).GetVersionInformation(); bool filesizeSame = ((BinaryFile)fileInformation.UserFile).GetFileSize() == ((BinaryFile)fileInformation.NewGenFile).GetFileSize(); bool md5Same = ((BinaryFile)fileInformation.UserFile).GetMD5() == ((BinaryFile)fileInformation.NewGenFile).GetMD5(); if (!fileInformation.UserFile.IsFileOnDisk) { labelHeader.Text = string.Format("New file - {0} [Binary file]", fileInformation.RelativeFilePath); labelHeader.BackgroundStyle.BackColor = Color.Green; labelHeader.BackgroundStyle.BackColor2 = Color.GreenYellow; } else if (versionsSame && filesizeSame && md5Same) { labelHeader.Text = string.Format("No changes - {0} [Binary file]", fileInformation.RelativeFilePath); labelHeader.BackgroundStyle.BackColor = Color.Green; labelHeader.BackgroundStyle.BackColor2 = Color.GreenYellow; } else { labelHeader.Text = string.Format("File is different - {0}", fileInformation.RelativeFilePath); labelHeader.BackgroundStyle.BackColor = Color.Brown; labelHeader.BackgroundStyle.BackColor2 = Color.OrangeRed; } SetVersionInfo(fileInformation.UserFile as BinaryFile, labelExistingFileVersion, versionsSame); SetFileSize(fileInformation.UserFile as BinaryFile, labelExistingFilesize, filesizeSame); SetMD5Info(fileInformation.UserFile as BinaryFile, labelExistingMD5, filesizeSame); SetVersionInfo(fileInformation.NewGenFile as BinaryFile, labelNewFileVersion, versionsSame); SetFileSize(fileInformation.NewGenFile as BinaryFile, labelNewFilesize, filesizeSame); SetMD5Info(fileInformation.NewGenFile as BinaryFile, labelNewMD5, filesizeSame); SetHeading(versionsSame && filesizeSame); int widthExistingMD5 = (int)Graphics.FromHwnd(labelExistingMD5.Handle).MeasureString(labelExistingMD5.Text, labelExistingMD5.Font).Width + 5; int widthExistingHeader = (int)Graphics.FromHwnd(labelExistingHeader.Handle).MeasureString(labelExistingHeader.Text, labelExistingHeader.Font).Width + 5; int widthNewMD5 = (int)Graphics.FromHwnd(labelNewMD5.Handle).MeasureString(labelNewMD5.Text, labelNewMD5.Font).Width + 5; int widthNewHeader = (int)Graphics.FromHwnd(labelNewHeader.Handle).MeasureString(labelNewHeader.Text, labelNewHeader.Font).Width + 5; panelExisting.Width = Math.Max(widthExistingMD5, widthExistingHeader); panelNew.Width = Math.Max(widthNewMD5, widthNewHeader);; }
public void SetupAndPerformDiff(byte[] user, byte[] prevGen, byte[] newGen) { bfi = new BinaryFileInformation(); bfi.RelativeFilePath = filePath; bfi.UserFile = user==null ? BinaryFile.Blank : new BinaryFile(user); bfi.NewGenFile = newGen==null ? BinaryFile.Blank : new BinaryFile(newGen); bfi.PrevGenFile = prevGen==null ? BinaryFile.Blank : new BinaryFile(prevGen); bfi.IntelliMerge = IntelliMergeType.NotSet; Assert.That(bfi.PerformDiff(),Is.EqualTo(true),"Diff not performed correctly"); }
public ucBinaryMergeEditor(BinaryFileInformation fileInformation) : this() { Reset(fileInformation); }
/// <summary> /// Creates the static files and writes them to the WorkbenchFileGenerator component directory. /// </summary> /// <param name="progressHelper"></param> /// <param name="folderName">The relative path of the folder this file will be placed in.</param> /// <param name="file"></param> /// <param name="parentNode"></param> /// <returns>The number of files created.</returns> private int CreateStaticFile(ITaskProgressHelper<GenerateFilesProgress> progressHelper, string folderName, IFile file, ProjectFileTreeNode parentNode) { int fileCount = 0; if (string.IsNullOrEmpty(file.IteratorName)) { fileCount++; string fileName = UpdateScriptName(null, file); string relativeFilePath = Path.Combine(folderName, fileName); string fullPath = Path.Combine(absoluteBasePath, relativeFilePath); _Loader.WriteResourceToFile(file.StaticFileName, fullPath); BinaryFile outFile = new BinaryFile(fullPath, false); BinaryFileInformation binFileInfo = new BinaryFileInformation(); binFileInfo.NewGenFile = outFile; binFileInfo.RelativeFilePath = relativeFilePath; parentNode.AddChildNode(binFileInfo, fileName); //Project.CurrentProject.AddGeneratedFile(new ProjectHelper.GeneratedFile(file.Name, fileName, fullPath, null, file.IteratorName)); AddFileCountToPreviousEventAndRefire(progressHelper, 1); return fileCount; } ProviderInfo provider; Type iteratorType = project.GetTypeFromProviders(file.IteratorName, out provider); if (iteratorType != null) { IEnumerable<IScriptBaseObject> iteratorObjects; if (CurrentRootObject == null) { iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName); } else if (iteratorType.IsInstanceOfType(CurrentRootObject)) { iteratorObjects = new[] { CurrentRootObject }; } else { iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName, CurrentRootObject); } if (iteratorObjects != null) { if (iteratorType.IsArray) { throw new NotImplementedException("Array iterator types not handled for static files yet. Please inform [email protected] about this error."); } foreach (IScriptBaseObject iteratorObject in iteratorObjects) { string fileName = UpdateScriptName(iteratorObject, file); string relativeFilePath = Path.Combine(folderName, fileName); string fullPath = Path.Combine(absoluteBasePath, relativeFilePath); _Loader.WriteResourceToFile(file.StaticFileName, fullPath); BinaryFile outFile = new BinaryFile(fullPath, false); BinaryFileInformation binFileInfo = new BinaryFileInformation(); binFileInfo.RelativeFilePath = relativeFilePath; binFileInfo.NewGenFile = outFile; parentNode.AddChildNode(binFileInfo, fileName); fileCount++; AddFileCountToPreviousEventAndRefire(progressHelper, 1); } } } else { throw new Exception(string.Format("The IteratorType could not be found: {0}. Are you missing an assembly?", file.IteratorName)); } return fileCount; }
/// <summary> /// Creates the static files and writes them to the WorkbenchFileGenerator component directory. /// </summary> /// <param name="progressHelper"></param> /// <param name="folderName">The relative path of the folder this file will be placed in.</param> /// <param name="file"></param> /// <param name="parentNode"></param> /// <returns>The number of files created.</returns> private int CreateStaticFile(ITaskProgressHelper <GenerateFilesProgress> progressHelper, string folderName, IFile file, ProjectFileTreeNode parentNode) { int fileCount = 0; if (string.IsNullOrEmpty(file.IteratorName)) { fileCount++; string fileName = UpdateScriptName(null, file); string relativeFilePath = Path.Combine(folderName, fileName); string fullPath = Path.Combine(absoluteBasePath, relativeFilePath); _Loader.WriteResourceToFile(file.StaticFileName, fullPath); BinaryFile outFile = new BinaryFile(fullPath, false); BinaryFileInformation binFileInfo = new BinaryFileInformation(); binFileInfo.NewGenFile = outFile; binFileInfo.RelativeFilePath = relativeFilePath; parentNode.AddChildNode(binFileInfo, fileName); //Project.CurrentProject.AddGeneratedFile(new ProjectHelper.GeneratedFile(file.Name, fileName, fullPath, null, file.IteratorName)); AddFileCountToPreviousEventAndRefire(progressHelper, 1); return(fileCount); } ProviderInfo provider; Type iteratorType = project.GetTypeFromProviders(file.IteratorName, out provider); if (iteratorType != null) { IEnumerable <IScriptBaseObject> iteratorObjects; if (CurrentRootObject == null) { iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName); } else if (iteratorType.IsInstanceOfType(CurrentRootObject)) { iteratorObjects = new[] { CurrentRootObject }; } else { iteratorObjects = provider.GetAllObjectsOfType(iteratorType.FullName, CurrentRootObject); } if (iteratorObjects != null) { if (iteratorType.IsArray) { throw new NotImplementedException("Array iterator types not handled for static files yet. Please inform [email protected] about this error."); } foreach (IScriptBaseObject iteratorObject in iteratorObjects) { string fileName = UpdateScriptName(iteratorObject, file); string relativeFilePath = Path.Combine(folderName, fileName); string fullPath = Path.Combine(absoluteBasePath, relativeFilePath); _Loader.WriteResourceToFile(file.StaticFileName, fullPath); BinaryFile outFile = new BinaryFile(fullPath, false); BinaryFileInformation binFileInfo = new BinaryFileInformation(); binFileInfo.RelativeFilePath = relativeFilePath; binFileInfo.NewGenFile = outFile; parentNode.AddChildNode(binFileInfo, fileName); fileCount++; AddFileCountToPreviousEventAndRefire(progressHelper, 1); } } } else { throw new Exception(string.Format("The IteratorType could not be found: {0}. Are you missing an assembly?", file.IteratorName)); } return(fileCount); }
private static void CopyUserFileToGenerationLocation(string genFilePath, BinaryFileInformation fileInfo) { CopyUserFileToGenerationLocation(genFilePath, fileInfo.RelativeFilePath); }
private void ProcessStaticFile(ArchAngel.Interfaces.Template.StaticFile staticFile, string path, ProjectFileTreeNode parentNode) { string filePath; string relativeFilePath; string fileName; BinaryFileInformation fileInfo; bool skipFile = false; switch (staticFile.Iterator) { case ArchAngel.Interfaces.Template.IteratorTypes.None: try { fileName = GetStaticFileName(staticFile.Id, null); } catch (Exception ex) { fileName = "ERROR"; filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; ProcessFileGenerationException(parentNode, staticFile.Id, fileName, fileInfo, ex); NumFiles++; return; } filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; try { CopyUserFileToGenerationLocation(filePath, fileInfo); CurrentFilePathProperty.SetValue(null, filePath, null); CallStaticFilePreWriteFunction(staticFile.Id, null, out skipFile); string newFilePath = (string)CurrentFilePathProperty.GetValue(null, null); if (newFilePath != filePath) { //filePath = newFilePath; relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; } } catch (Exception ex) { ProcessFileGenerationException(parentNode, staticFile.Id, fileName, fileInfo, ex); return; } if (!skipFile) { string fromFile = Utility.PathCombine(ArchAngel.Interfaces.SharedData.CurrentProject.TemplateProject.ResourceFilesFolder, staticFile.ResourceName); if (System.IO.File.Exists(filePath)) Slyce.Common.Utility.DeleteFileBrute(filePath); System.IO.File.Copy(fromFile, filePath); parentNode.AddChildNode(fileInfo, fileName); AllTextFilenames.Add(new FilenameInfo(fileName, staticFile.Name, staticFile.Iterator, FilenameInfo.FilenameTypes.StaticFile) { RelativePath = relativeFilePath }); NumFiles++; } break; case ArchAngel.Interfaces.Template.IteratorTypes.Entity: foreach (var entity in ScriptProject.Entities) { try { fileName = GetStaticFileName(staticFile.Id, entity); } catch (Exception ex) { fileName = GetNodeDisplayText(staticFile.Name, string.Format("[{0}]", entity.Name)); filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; ProcessFileGenerationException(parentNode, staticFile.Id, fileName, fileInfo, ex); NumFiles++; continue; } filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; try { CopyUserFileToGenerationLocation(filePath, fileInfo); CurrentFilePathProperty.SetValue(null, filePath, null); CallStaticFilePreWriteFunction(staticFile.Id, entity, out skipFile); string newFilePath = (string)CurrentFilePathProperty.GetValue(null, null); if (newFilePath != filePath) { //filePath = newFilePath; relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; } } catch (Exception ex) { ProcessFileGenerationException(parentNode, staticFile.Id, fileName, fileInfo, ex); continue; } if (!skipFile) { System.IO.File.Copy(staticFile.ResourceName, filePath); parentNode.AddChildNode(fileInfo, fileName); AllTextFilenames.Add(new FilenameInfo(fileName, staticFile.Name, staticFile.Iterator, FilenameInfo.FilenameTypes.GeneratedFile) { RelativePath = relativeFilePath }); NumFiles++; } } break; case ArchAngel.Interfaces.Template.IteratorTypes.Component: foreach (var component in ScriptProject.Components) { try { fileName = GetStaticFileName(staticFile.Id, component); } catch (Exception ex) { fileName = "ERROR"; filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; ProcessFileGenerationException(parentNode, staticFile.Id, fileName, fileInfo, ex); NumFiles++; continue; } filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; try { CopyUserFileToGenerationLocation(filePath, fileInfo); CurrentFilePathProperty.SetValue(null, filePath, null); CallStaticFilePreWriteFunction(staticFile.Id, component, out skipFile); string newFilePath = (string)CurrentFilePathProperty.GetValue(null, null); if (newFilePath != filePath) { //filePath = newFilePath; relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; } } catch (Exception ex) { ProcessFileGenerationException(parentNode, staticFile.Id, fileName, fileInfo, ex); continue; } if (!skipFile) { System.IO.File.Copy(staticFile.ResourceName, filePath); parentNode.AddChildNode(fileInfo, fileName); AllTextFilenames.Add(new FilenameInfo(fileName, staticFile.Name, staticFile.Iterator, FilenameInfo.FilenameTypes.GeneratedFile) { RelativePath = relativeFilePath }); NumFiles++; } } break; case ArchAngel.Interfaces.Template.IteratorTypes.Table: foreach (var table in ScriptProject.Tables) { try { fileName = GetStaticFileName(staticFile.Id, table); } catch (Exception ex) { fileName = "ERROR"; filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; ProcessFileGenerationException(parentNode, staticFile.Id, fileName, fileInfo, ex); NumFiles++; continue; } filePath = Utility.PathCombine(path, fileName); relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; try { CopyUserFileToGenerationLocation(filePath, fileInfo); CurrentFilePathProperty.SetValue(null, filePath, null); CallStaticFilePreWriteFunction(staticFile.Id, table, out skipFile); string newFilePath = (string)CurrentFilePathProperty.GetValue(null, null); if (newFilePath != filePath) { //filePath = newFilePath; relativeFilePath = filePath.Replace(TargetFolder, "").TrimStart(Path.DirectorySeparatorChar); fileInfo = new BinaryFileInformation() { RelativeFilePath = relativeFilePath, NewGenFile = new BinaryFile(filePath, false) }; } } catch (Exception ex) { ProcessFileGenerationException(parentNode, staticFile.Id, fileName, fileInfo, ex); continue; } if (!skipFile) { System.IO.File.Copy(staticFile.ResourceName, filePath); parentNode.AddChildNode(fileInfo, fileName); AllTextFilenames.Add(new FilenameInfo(fileName, staticFile.Name, staticFile.Iterator, FilenameInfo.FilenameTypes.GeneratedFile) { RelativePath = relativeFilePath }); NumFiles++; } } break; default: throw new NotImplementedException("This iterator not handled yet: " + staticFile.Iterator.ToString()); } }
private void ProcessFileGenerationException(ProjectFileTreeNode parentNode, int fileId, string fileName, BinaryFileInformation fileInfo, Exception ex) { var baseException = ex.GetBaseException(); string stackTrace = baseException.StackTrace; stackTrace = stackTrace.Substring(stackTrace.IndexOf(":line ") + ":line ".Length); int errLine = int.Parse(stackTrace); ArchAngel.Common.Generator.DebugPos debugPos = ArchAngel.Common.Generator.GetDebugPos(string.Format("StaticFile_{0}", fileId), errLine - 1, 1, string.Format("Error: {0}\nFileId: {1}.", baseException.Message, fileId)); string message = string.Format("<span class='error'>Line {0}: {1}</span>", errLine, baseException.Message); //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, fileName).GenerationError = new GenerationError(fileName, message); NumFiles++; }
/// <summary> /// Creates the static files and writes them to the Workbench_FileGenerator component directory. /// </summary> /// <param name="folderName">The relative path of the folder this file will be placed in.</param> /// <param name="file"></param> /// <param name="parentNode"></param> /// <returns>The number of files created.</returns> private int CreateStaticFile(string folderName, IFile file, ProjectFileTreeNode parentNode) { int fileCount = 0; if (string.IsNullOrEmpty(file.IteratorName)) { fileCount++; string fileName = UpdateScriptName(null, file); string relativeFilePath = Path.Combine(folderName, fileName); string fullPath = Path.Combine(absoluteBasePath, relativeFilePath); if (GetSkipCurrentFile(file, Path.Combine(_Project.ProjectSettings.OutputPath, relativeFilePath))) { return fileCount; } _FileController.WriteResourceToFile(_Loader.CurrentAssembly, file.StaticFileName, fullPath); _Project.AddGeneratedFile(new GeneratedFile(file.Name, fullPath, relativeFilePath, "", file.IteratorName)); if (addToProjectFileTree) { BinaryFile outFile = new BinaryFile(fullPath, false); BinaryFileInformation binFileInfo = new BinaryFileInformation(); binFileInfo.NewGenFile = outFile; binFileInfo.RelativeFilePath = relativeFilePath; parentNode.AddChildNode(binFileInfo, fileName); } AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1); return fileCount; } ProviderInfo provider; Type iteratorType = _Project.GetIteratorTypeFromProviders(file.IteratorName, out provider); IScriptBaseObject[] iteratorObjects = GetIteratorObjects(iteratorType, provider); if (iteratorObjects != null) { if (iteratorType.IsArray) { throw new NotImplementedException("Array iterator types not handled for static files yet. Please inform [email protected] about this error."); } foreach (IScriptBaseObject iteratorObject in iteratorObjects) { string fileName = UpdateScriptName(iteratorObject, file); string relativeFilePath = Path.Combine(folderName, fileName); string fullPath = Path.Combine(absoluteBasePath, relativeFilePath); if (GetSkipCurrentFile(file, Path.Combine(_Project.ProjectSettings.OutputPath, relativeFilePath))) { // Skip the file. continue; } _FileController.WriteResourceToFile(_Loader.CurrentAssembly, file.StaticFileName, fullPath); _Project.AddGeneratedFile(new GeneratedFile(file.Name, fullPath, relativeFilePath, "", file.IteratorName)); if (addToProjectFileTree) { BinaryFile outFile = new BinaryFile(fullPath, false); BinaryFileInformation binFileInfo = new BinaryFileInformation(); binFileInfo.RelativeFilePath = relativeFilePath; binFileInfo.NewGenFile = outFile; parentNode.AddChildNode(binFileInfo, fileName); } fileCount++; AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1); } } return fileCount; }
/// <summary> /// Creates the static files and writes them to the Workbench_FileGenerator component directory. /// </summary> /// <param name="folderName">The relative path of the folder this file will be placed in.</param> /// <param name="file"></param> /// <param name="parentNode"></param> /// <returns>The number of files created.</returns> private int CreateStaticFile(string folderName, IFile file, ProjectFileTreeNode parentNode) { int fileCount = 0; if (string.IsNullOrEmpty(file.IteratorName)) { fileCount++; string fileName = UpdateScriptName(null, file); string relativeFilePath = Path.Combine(folderName, fileName); string fullPath = Path.Combine(absoluteBasePath, relativeFilePath); if (GetSkipCurrentFile(file, Path.Combine(_Project.ProjectSettings.OutputPath, relativeFilePath))) { return(fileCount); } _FileController.WriteResourceToFile(_Loader.CurrentAssembly, file.StaticFileName, fullPath); _Project.AddGeneratedFile(new GeneratedFile(file.Name, fullPath, relativeFilePath, "", file.IteratorName)); if (addToProjectFileTree) { BinaryFile outFile = new BinaryFile(fullPath, false); BinaryFileInformation binFileInfo = new BinaryFileInformation(); binFileInfo.NewGenFile = outFile; binFileInfo.RelativeFilePath = relativeFilePath; parentNode.AddChildNode(binFileInfo, fileName); } AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1); return(fileCount); } ProviderInfo provider; Type iteratorType = _Project.GetIteratorTypeFromProviders(file.IteratorName, out provider); IScriptBaseObject[] iteratorObjects = GetIteratorObjects(iteratorType, provider); if (iteratorObjects != null) { if (iteratorType.IsArray) { throw new NotImplementedException("Array iterator types not handled for static files yet. Please inform [email protected] about this error."); } foreach (IScriptBaseObject iteratorObject in iteratorObjects) { string fileName = UpdateScriptName(iteratorObject, file); string relativeFilePath = Path.Combine(folderName, fileName); string fullPath = Path.Combine(absoluteBasePath, relativeFilePath); if (GetSkipCurrentFile(file, Path.Combine(_Project.ProjectSettings.OutputPath, relativeFilePath))) { // Skip the file. continue; } _FileController.WriteResourceToFile(_Loader.CurrentAssembly, file.StaticFileName, fullPath); _Project.AddGeneratedFile(new GeneratedFile(file.Name, fullPath, relativeFilePath, "", file.IteratorName)); if (addToProjectFileTree) { BinaryFile outFile = new BinaryFile(fullPath, false); BinaryFileInformation binFileInfo = new BinaryFileInformation(); binFileInfo.RelativeFilePath = relativeFilePath; binFileInfo.NewGenFile = outFile; parentNode.AddChildNode(binFileInfo, fileName); } fileCount++; AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1); } } return(fileCount); }