private static bool IsEqualWorkspace(IWorkspaceTemplate workspace1, IWorkspaceTemplate workspace2) { if (workspace1.Mappings.Count != workspace2.Mappings.Count) { return(false); } bool result = true; foreach (IWorkspaceMapping workspaceMapping1 in workspace1.Mappings) { result = workspace2.Mappings.Find(workspaceMapping2 => { return((workspaceMapping2.Depth == workspaceMapping1.Depth) && (workspaceMapping2.LocalItem == workspaceMapping1.LocalItem) && (workspaceMapping2.MappingType == workspaceMapping1.MappingType) && (workspaceMapping2.ServerItem == workspaceMapping1.ServerItem)); }) != null; if (!result) { break; } } return(result); }
private bool CheckWorkspaces() { IBuildDefinition builddef = this.bs.GetBuildDefinition(this.teamProject, this.buildDefinition); IWorkspaceTemplate workspaceTemplate = builddef.Workspace; bool containsChanges = false; foreach (IWorkspaceMapping mapping in workspaceTemplate.Mappings) { if (mapping.MappingType == WorkspaceMappingType.Map) { if (this.exclusions != null && this.exclusions.Contains(mapping.ServerItem)) { continue; } ItemSet itemSet = this.vcs.GetItems(mapping.ServerItem, RecursionType.Full); foreach (Item item in itemSet.Items) { if (!workspaceTemplate.Mappings.Exists(m => item.ServerItem.Contains(m.ServerItem) && m.MappingType == WorkspaceMappingType.Cloak && m.ServerItem.Contains(mapping.ServerItem))) { if (item.CheckinDate >= this.since) { containsChanges = true; foreach (string exclusion in this.exclusions) { if (item.ServerItem.Contains(exclusion)) { containsChanges = false; } } } } } } } return(containsChanges); }
/// <summary> Process this. </summary> /// /// <remarks> Ken, 10/3/2020. </remarks> public void Process() { var config = this.GeneratorConfiguration; var assemblyLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var localTemplatesPath = Path.Combine(assemblyLocation, "Templates"); var directory = new DirectoryInfo(localTemplatesPath); WriteLine("\r\n**** CurrentPass: {0} {1}\r\n", PrintMode.Any, config.CurrentPass, "*".Repeat(25)); foreach (var file in directory.GetFiles("*.sln")) { var rawFileRelativePath = file.Name.ReverseSlashes(); var tokenizedRelativePath = VSTemplate.ReplaceParameterText(rawFileRelativePath, GetTemplateParameters()); var fileName = Path.Combine(projectFolderRoot, tokenizedRelativePath); WriteLine("{0}{1}", PrintMode.All, this.CurrentTabText, $"Creating solution { Path.GetFileNameWithoutExtension(fileName) }"); this.Indent(); } foreach (var file in directory.GetFiles()) { if (file.Extension == ".sln") { var rawFileRelativePath = file.Name.ReverseSlashes(); var tokenizedRelativePath = VSTemplate.ReplaceParameterText(rawFileRelativePath, GetTemplateParameters()); var fileName = Path.Combine(projectFolderRoot, tokenizedRelativePath); var outputFile = new FileInfo(fileName); WriteLine("{0}{1}", PrintMode.All, this.CurrentTabText, $"Creating solution file { Path.GetFileNameWithoutExtension(fileName) }"); using (var stream = System.IO.File.OpenRead(file.FullName)) { var reader = new StreamReader(stream); var content = reader.ReadToEnd(); content = VSTemplate.ReplaceParameterText(content, GetTemplateParameters()); if (config.CurrentPass == GeneratorPass.Files) { if (outputFile.Exists) { outputFile.MakeWritable(); } System.IO.File.WriteAllText(outputFile.FullName, content); } } } else if (file.Extension == ".zip") { var rawProjectName = Path.GetFileNameWithoutExtension(file.Name); var rawFileRelativePath = file.Name.ReverseSlashes(); var templateParameters = this.GeneratorConfiguration.GetTemplateParameters(rawProjectName); var tokenizedRelativePath = VSTemplate.ReplaceParameterText(rawFileRelativePath, GetTemplateParameters()); var fileName = Path.Combine(projectFolderRoot, tokenizedRelativePath); var outputFile = new FileInfo(fileName); string rootFolder; string projectName; WriteLine("{0}{1}", PrintMode.All, this.CurrentTabText, $"Creating project { Path.GetFileNameWithoutExtension(fileName) }"); if (templateParameters.Count > 0) { var tokenizedProjectName = VSTemplate.ReplaceParameterText(rawProjectName, GetTemplateParameters()); projectName = tokenizedProjectName; rootFolder = Path.Combine(projectFolderRoot, tokenizedProjectName); } else { projectName = rawProjectName; rootFolder = Path.Combine(projectFolderRoot, rawProjectName); } if (!System.IO.Directory.Exists(rootFolder)) { if (config.CurrentPass == GeneratorPass.Files) { System.IO.Directory.CreateDirectory(rootFolder); } } using (var package = ZipPackage.Open(file.FullName, FileMode.Open)) { var templatePart = package.GetParts().Single(p => Path.GetExtension(p.Uri.OriginalString) == ".vstemplate"); VSProjectTemplate template = null; VSTemplateProject project = null; using (var stream = templatePart.GetStream()) { var reader = new StreamReader(stream); var contents = reader.ReadToEnd(); template = (VSProjectTemplate)VSConfigProvider.ParseTemplate(new StringBuilder(contents)); project = (VSTemplateProject)template.Projects.Single(); } foreach (var part in package.GetParts()) { VSTemplateProjectItem projectItem = null; IWorkspaceTemplate workspaceTemplate = null; IWorkspaceFileTypeHandler fileTypeHandler; rawFileRelativePath = part.Uri.OriginalString.ReverseSlashes(); templateParameters = this.GeneratorConfiguration.GetTemplateParameters(rawFileRelativePath); if (template != null) { if (rawFileRelativePath.AsCaseless() == project.RelativePath) { workspaceTemplate = project; } else { projectItem = (VSTemplateProjectItem)project.ProjectItems.SingleOrDefault(i => i.RelativePath.AsCaseless() == rawFileRelativePath); if (projectItem != null && projectItem.SubType != null) { var subTypes = projectItem.SubType.Split(",", StringSplitOptions.RemoveEmptyEntries); if (subTypes.Where(t => t.StartsWith("GENERATOR_TOKEN_")).Any(s => !supportedTokens.Any(t => t == s))) { continue; } } workspaceTemplate = projectItem; } } if (templateParameters.Count > 0) { tokenizedRelativePath = template.ReplaceParameters(rawFileRelativePath, GetTemplateParameters(projectName)); fileName = Path.Combine(rootFolder, tokenizedRelativePath.RemoveStartIfMatches(@"\")); } else { fileName = Path.Combine(rootFolder, rawFileRelativePath.RemoveStartIfMatches(@"\")); } if (workspaceTemplate != null) { using (var stream = part.GetStream()) { var reader = new StreamReader(stream); var content = reader.ReadToEnd(); outputFile = new FileInfo(fileName); if (workspaceTemplate.ReplaceParameters) { content = template.ReplaceParameters(content, GetTemplateParameters(projectName)); } if (outputFile.Exists) { outputFile.MakeWritable(); } fileTypeHandler = config.GetWorkspaceFileTypeHandler(fileName); if (fileTypeHandler != null) { var tokenContentHandlers = new Dictionary <string, IWorkspaceTokenContentHandler>(); fileTypeHandler.PreProcess(projectType, appDescription, rawFileRelativePath, fileName, supportedTokens, content, config); if (fileTypeHandler.TokensToProcess != null) { foreach (var token in fileTypeHandler.TokensToProcess) { var tokenContentHandler = config.GetTokenContentHandler(token); if (tokenContentHandler != null) { tokenContentHandler.Process(projectType, appDescription, rawFileRelativePath, fileName, this.supportedTokens); tokenContentHandlers.Add(token, tokenContentHandler); } } } fileTypeHandler.Process(tokenContentHandlers, workspaceTemplate, projectType, appDescription, rawFileRelativePath, fileName, content, config); content = fileTypeHandler.OutputContent; } if (config.CurrentPass == GeneratorPass.Files) { if (!outputFile.Directory.Exists) { outputFile.Directory.Create(); } System.IO.File.WriteAllText(outputFile.FullName, content); } } } } } } } this.Dedent(); }
public bool Process(Dictionary <string, IWorkspaceTokenContentHandler> tokenContentHandlers, IWorkspaceTemplate workspaceTemplate, Guid projectType, string appName, string rawFileRelativePath, string outputFileName, string content, IGeneratorConfiguration generatorConfiguration) { var processing = true; var options = CSharpParseOptions.Default.WithPreprocessorSymbols(supportedTokens); IEnumerable <Diagnostic> diagnostics = null; this.OutputContent = content; while (processing) { var syntaxTree = CSharpSyntaxTree.ParseText(content, options); var root = syntaxTree.GetCompilationUnitRoot(); var walker = new DirectiveSyntaxWalker(supportedTokens); List <IfDirectiveBlock> generatorDirectiveBlocks; walker.Visit(root); generatorDirectiveBlocks = walker.GeneratorDirectiveBlocks; if (generatorDirectiveBlocks.Count > 0) { var generatorDirectiveBlock = generatorDirectiveBlocks.First(); var childNodes = generatorDirectiveBlock.ChildNodes.Reverse(); IfDirectiveNodeBase branchTakenNode = null; foreach (var childNode in childNodes.Where(n => !n.IsOfType <EndIfBlock>())) { if (childNode.BranchTaken.Value) { branchTakenNode = childNode; } else if (branchTakenNode != null) { var offsetLength = branchTakenNode.Node.FullSpan.Length; var length = childNode.Length - offsetLength; content = content.Remove(childNode.Start, length); childNodes.ShiftUp(childNode.Start, length); } else { content = content.Remove(childNode.Start, childNode.Length); childNodes.ShiftUp(childNode.Start, childNode.Length); } } if (branchTakenNode != null) { var startSpan = new TextSpan(branchTakenNode.Node.FullSpan.Start + branchTakenNode.ShiftAmount, branchTakenNode.Node.FullSpan.Length); var endSpan = new TextSpan(branchTakenNode.NextNode.Node.FullSpan.Start + branchTakenNode.ShiftAmount, branchTakenNode.NextNode.Node.FullSpan.Length); switch (branchTakenNode) { case IfBlock ifBlock: if (tokenContentHandlers.ContainsKey(ifBlock.Condition)) { var tokenContentHandler = tokenContentHandlers[ifBlock.Condition]; var insertContent = tokenContentHandler.Content; content = content.Remove(ifBlock.Start, ifBlock.Length); content = content.Insert(ifBlock.Start, insertContent); } else { content = content.Remove(endSpan.Start, endSpan.Length); content = content.Remove(startSpan.Start, startSpan.Length); } break; case ElifBlock elifBlock: DebugUtils.Break(); // untested if (tokenContentHandlers.ContainsKey(elifBlock.Condition)) { var tokenContentHandler = tokenContentHandlers[elifBlock.Condition]; var insertContent = tokenContentHandler.Content; content = content.Remove(elifBlock.Start, elifBlock.Length); content = content.Insert(elifBlock.Start, insertContent); } else { content = content.Remove(endSpan.Start, endSpan.Length); content = content.Remove(startSpan.Start, startSpan.Length); } break; case ElseBlock elseBlock: content = content.Remove(endSpan.Start, endSpan.Length); content = content.Remove(startSpan.Start, startSpan.Length); break; } } } else { processing = false; } diagnostics = syntaxTree.GetDiagnostics(); } if (diagnostics.Count() > 0) { DebugUtils.Break(); } this.OutputContent = content; return(true); }