protected virtual void GetVirtualSolutionFolderTemplateObjects(ITemplateObject root, IList <VirtualSolutionFolder> virtualSolutionFolders, string parentPath) { foreach (var virtualSolutionFolder in virtualSolutionFolders) { var virtualFolderObject = new TemplateObject { Type = TemplateObjectType.Folder, DestinationFullPath = Path.Combine(parentPath, virtualSolutionFolder.Name) }; foreach (var filePath in virtualSolutionFolder.Files) { virtualFolderObject.ChildObjects.Add(new TemplateObject { ChildObjects = null, Type = TemplateObjectType.File, OriginalFullPath = filePath, DestinationFullPath = ReplaceTokensService.Replace(BuildDestinationPathService.Build(filePath)) }); } if (virtualSolutionFolder.SubFolders == null || !virtualSolutionFolders.Any()) { continue; } GetVirtualSolutionFolderTemplateObjects(virtualFolderObject, virtualSolutionFolder.SubFolders, virtualFolderObject.DestinationFullPath); root.ChildObjects.Add(virtualFolderObject); } }
protected virtual void Attach(ITemplateObject templateObject, string parentFolderName = null) { if (templateObject.SkipAttach) { return; } if (string.IsNullOrEmpty(parentFolderName)) { ProjectsRepository.AddFromFile(templateObject.DestinationFullPath); return; } var parentFolder = SolutionFolderRepository.GetByName(parentFolderName); if (parentFolder == null) { throw new ArgumentException($"Scaffolding failed. Cannot find parent solution folder for file {templateObject.DestinationFullPath}."); } if (templateObject.Type == TemplateObjectType.Project) { ProjectsRepository.AddProjectFromFile(templateObject.DestinationFullPath, parentFolder); return; } ProjectsRepository.AddFromFile(templateObject.DestinationFullPath, parentFolder); }
private void AttachTemplateObjects(ITemplateObject rootTemplateObject, IList <string> solutionLocation) { if (rootTemplateObject.ChildObjects.All(c => c.Type != TemplateObjectType.Project)) { solutionLocation.Add(rootTemplateObject.Name); } foreach (var templateObject in rootTemplateObject.ChildObjects.Where(to => !to.IsIgnored && !to.SkipAttach)) { if (templateObject.Type == TemplateObjectType.Folder) { if (templateObject.ChildObjects == null || !templateObject.ChildObjects.Any()) { EnsureSolutionFolder(templateObject, solutionLocation); continue; } if (templateObject.ChildObjects.All(t => t.Type != TemplateObjectType.Project)) { EnsureSolutionFolder(templateObject, solutionLocation); } AttachTemplateObjects(templateObject, solutionLocation.ToList()); } if (templateObject.Type == TemplateObjectType.File || templateObject.Type == TemplateObjectType.Project) { AttachFile(templateObject, solutionLocation); } } }
private void AttachTemplateObject(ITemplateObject templateObject, string currentSolutionFolder) { if (templateObject.Type == TemplateObjectType.Folder && templateObject.ChildObjects.All(c => c.Type != TemplateObjectType.Project)) { currentSolutionFolder = AttachSolutionFolder(templateObject, currentSolutionFolder); } if (templateObject.ChildObjects == null) { return; } foreach (var childObject in templateObject.ChildObjects.Where(to => !to.IsIgnored)) { if (childObject.Type == TemplateObjectType.File || childObject.Type == TemplateObjectType.Project) { Attach(childObject, currentSolutionFolder); } if (childObject.Type == TemplateObjectType.Folder) { AttachTemplateObject(childObject, currentSolutionFolder); } } }
protected virtual void EnsureSolutionFolder(ITemplateObject templateObject, IList <string> solutionLocation) { if (solutionLocation.Count == 1) { SolutionFolderRepository.Create(templateObject.Name); return; } var parentFolder = SolutionFolderRepository.GetByName(solutionLocation[solutionLocation.Count - 1]); if (parentFolder == null) { throw new ArgumentException($"Scaffolding failed. Cannot find parent solution folder called {solutionLocation[solutionLocation.Count - 1]} for {templateObject.Name}."); } SolutionFolderRepository.Create(templateObject.Name, parentFolder); }
protected virtual string AttachSolutionFolder(ITemplateObject templateObject, string parentFolderName = null) { if (templateObject.SkipAttach) { return(parentFolderName); } if (string.IsNullOrEmpty(parentFolderName)) { return(SolutionFolderRepository.Create(templateObject.Name)); } var parentFolder = SolutionFolderRepository.GetByName(parentFolderName); if (parentFolder == null) { throw new ArgumentException($"Scaffolding failed. Cannot find parent solution folder called {parentFolderName} for {templateObject.Name}."); } return(SolutionFolderRepository.Create(templateObject.Name, parentFolder)); }
/// <summary> /// Resolves lambda s3 code location. /// </summary> /// <param name="cloudFormationResource">The cloud formation resource.</param> /// <param name="attributes">The attributes.</param> /// <param name="mapping">The mapping.</param> /// <param name="inputs">The list of input variables and data sources.</param> /// <param name="codeDefinition">The code definition.</param> private static void ResolveLambdaS3Code( ITemplateObject cloudFormationResource, JObject attributes, ResourceMapping mapping, IList <InputVariable> inputs, IDictionary <string, object> codeDefinition) { // Must contain S3Key and S3Bucket, and optionally S3ObjectVersion if (!(codeDefinition.ContainsKey("S3Bucket") && codeDefinition.ContainsKey("S3Key"))) { return; } UpdatePropertyValue( "s3_bucket", cloudFormationResource.Template, attributes, mapping, inputs, codeDefinition["S3Bucket"]); UpdatePropertyValue( "s3_key", cloudFormationResource.Template, attributes, mapping, inputs, codeDefinition["S3Key"]); if (codeDefinition.ContainsKey("S3ObjectVersion")) { UpdatePropertyValue( "s3_object_version", cloudFormationResource.Template, attributes, mapping, inputs, codeDefinition["S3ObjectVersion"]); } }
protected virtual void AttachFile(ITemplateObject templateObject, IList <string> solutionLocation) { if (!solutionLocation.Any()) { throw new ArgumentException("Miss solution root object"); } if (solutionLocation.Count == 1) { ProjectsRepository.AddFromFile(templateObject.DestinationFullPath); return; } var parentFolder = SolutionFolderRepository.GetByName(solutionLocation[solutionLocation.Count - 1]); if (parentFolder == null) { throw new ArgumentException($"Scaffolding failed. Cannot find parent solution folder for file {templateObject.DestinationFullPath}."); } if (templateObject.Type == TemplateObjectType.Project) { ProjectsRepository.AddProjectFromFile(templateObject.DestinationFullPath, parentFolder); return; } ProjectsRepository.AddFromFile(templateObject.DestinationFullPath, parentFolder); }
protected virtual bool SkipAttach(ITemplateObject templateObject) { return(templateObject.Type != TemplateObjectType.Project && (SkipPath(templateObject.OriginalFullPath) || templateObject.ChildObjects != null && templateObject.ChildObjects.Any(c => c.Type == TemplateObjectType.Project))); }
public TemplateMessage(string altText, ITemplateObject template) { AltText = altText; Template = template; }
/// <summary> /// Resolves the lambda ZipFile code. /// </summary> /// <param name="writer">The writer.</param> /// <param name="runtime">The runtime.</param> /// <param name="cloudFormationResource">The cloud formation resource.</param> /// <param name="attributes">The attributes.</param> /// <param name="mapping">The mapping.</param> /// <param name="inputs">The list of input variables and data sources.</param> private static void ResolveLambdaZipCode( TextWriter writer, string runtime, ITemplateObject cloudFormationResource, JObject attributes, ResourceMapping mapping, IList <InputVariable> inputs) { var traits = LambdaTraits.FromRuntime(runtime); var dirName = Path.Combine("lambda", cloudFormationResource.Name); var fileName = Path.Combine(dirName, $"index{traits.ScriptFileExtension}"); var zipName = Path.Combine(dirName, $"{cloudFormationResource.Name}_deployment_package.zip"); // Create zipper resource var zipperResource = $"{cloudFormationResource.Name}_deployment_package"; var archiveDataSource = new DataSourceInput( "archive_file", zipperResource, new Dictionary <string, string> { { "type", "zip" }, { "source_file", fileName.Replace("\\", "/") }, { "output_path", zipName.Replace("\\", "/") } }); inputs.Add(archiveDataSource); // Fix up state file. // Find handler function var script = File.ReadAllText(fileName); var m = traits.HandlerRegex.Match(script); if (m.Success) { UpdatePropertyValue( "handler", cloudFormationResource.Template, attributes, mapping, inputs, $"index.{m.Groups["handler"].Value}"); } UpdatePropertyValue( "filename", cloudFormationResource.Template, attributes, mapping, inputs, new DataSourceReference( "archive_file", $"{cloudFormationResource.Name}_deployment_package", "output_path", false)); UpdatePropertyValue( "source_code_hash", cloudFormationResource.Template, attributes, mapping, inputs, new DataSourceReference( "archive_file", $"{cloudFormationResource.Name}_deployment_package", "output_base64sha256", false)); }
protected virtual string CopyFile(ITemplateObject templateObject) { File.Copy(templateObject.OriginalFullPath, templateObject.DestinationFullPath, true); templateObject.IsCreated = true; return(templateObject.DestinationFullPath); }
protected virtual bool CreateDirectory(ITemplateObject templateObject) { var directory = Directory.CreateDirectory(templateObject.DestinationFullPath); return(templateObject.IsCreated = directory.Exists); }