private void CreateFilesFromTemplates(string moduleName, Guid? projectGuid) { string modulePath = HostingEnvironment.MapPath("~/Modules/" + moduleName + "/"); string propertiesPath = modulePath + "Properties"; var content = new HashSet<string>(); var folders = new HashSet<string>(); foreach (var folder in _moduleDirectories) { Directory.CreateDirectory(modulePath + folder); if (!String.IsNullOrEmpty(folder)) { folders.Add(modulePath + folder); } } File.WriteAllText(modulePath + "Web.config", File.ReadAllText(_codeGenTemplatePath + "ModuleRootWebConfig.txt")); content.Add(modulePath + "Web.config"); File.WriteAllText(modulePath + "Scripts\\Web.config", File.ReadAllText(_codeGenTemplatePath + "StaticFilesWebConfig.txt")); content.Add(modulePath + "Scripts\\Web.config"); File.WriteAllText(modulePath + "Styles\\Web.config", File.ReadAllText(_codeGenTemplatePath + "StaticFilesWebConfig.txt")); content.Add(modulePath + "Styles\\Web.config"); var assemblyInfoTemplate = new ModuleAssemblyInfo(); assemblyInfoTemplate.Session = new Dictionary<string, object>(); assemblyInfoTemplate.Session["ModuleName"] = moduleName; assemblyInfoTemplate.Session["ModuleTypeLibGuid"] = Guid.NewGuid(); assemblyInfoTemplate.Initialize(); string templateText = assemblyInfoTemplate.TransformText(); File.WriteAllText(propertiesPath + "\\AssemblyInfo.cs", templateText); content.Add(propertiesPath + "\\AssemblyInfo.cs"); var moduleMainfestTemplate = new ModuleManifest(); moduleMainfestTemplate.Session = new Dictionary<string, object>(); moduleMainfestTemplate.Session["ModuleName"] = moduleName; moduleMainfestTemplate.Initialize(); templateText = moduleMainfestTemplate.TransformText(); File.WriteAllText(modulePath + "Module.txt", templateText, System.Text.Encoding.UTF8); content.Add(modulePath + "Module.txt"); var itemGroup = CreateProjectItemGroup(modulePath, content, folders); File.WriteAllText(modulePath + moduleName + ".csproj", CreateCsProject(moduleName, projectGuid, itemGroup)); }
public void CreateModuleTests(string moduleName) { var projectName = moduleName + ".Tests"; Context.Output.WriteLine(T("Creating module tests project {0}", projectName)); var testsPath = HostingEnvironment.MapPath("~/Modules/" + moduleName + "/" + projectName + "/"); if (Directory.Exists(testsPath)) { Context.Output.WriteLine(T("Creating module tests project {0} failed: a project of the same name already exists", projectName)); return; } var propertiesPath = testsPath + "Properties"; var content = new HashSet<string>(); var folders = new HashSet<string>(); foreach (var folder in _moduleTestsDirectories) { Directory.CreateDirectory(testsPath + folder); if (!String.IsNullOrEmpty(folder)) { folders.Add(testsPath + folder); } } var projectGuid = Guid.NewGuid(); var assemblyInfoTemplate = new ModuleAssemblyInfo(); assemblyInfoTemplate.Session = new Dictionary<string, object>(); assemblyInfoTemplate.Session["ModuleName"] = moduleName; assemblyInfoTemplate.Session["ModuleTypeLibGuid"] = projectGuid; assemblyInfoTemplate.Initialize(); string templateText = assemblyInfoTemplate.TransformText(); File.WriteAllText(propertiesPath + "\\AssemblyInfo.cs", templateText); content.Add(propertiesPath + "\\AssemblyInfo.cs"); var itemGroup = CreateProjectItemGroup(testsPath, content, folders); var csprojTemplate = new ModuleTestsCsProj() {Session = new Dictionary<string, object>()}; csprojTemplate.Session["ProjectName"] = projectName; csprojTemplate.Session["TestsProjectGuid"] = projectGuid; csprojTemplate.Session["FileIncludes"] = itemGroup; csprojTemplate.Session["CoeveryReferences"] = GetCoeveryReferences(); csprojTemplate.Initialize(); var csprojText = csprojTemplate.TransformText(); File.WriteAllText(testsPath + projectName + ".csproj", csprojText); // The string searches in solution/project files can be made aware of comment lines. if (IncludeInSolution) { AddToSolution(Context.Output, projectName, projectGuid, "Modules\\" + moduleName, SolutionDirectoryTests); } Context.Output.WriteLine(T("Module tests project {0} created successfully", projectName)); }