void RenderSample(RenderContext context, Project p, Sample s, bool isSingle) { ViewDataDictionary viewData = new ViewDataDictionary(); viewData["Project"] = p; viewData["Sample"] = s; string sampleControllerPath = Path.Combine(context.Path, "Controllers"); string sampleControllerName = (isSingle ? "Home" : s.Path) + "Controller"; string sampleViewPath = context.Path; if (p.ViewEngine == ViewEngine.Mvc || p.ViewEngine == ViewEngine.Razor) sampleViewPath = Path.Combine(sampleViewPath, "Views"); // TODO: handle single samples if (!isSingle) { sampleViewPath = Path.Combine(sampleViewPath, s.Path); } else if (p.ViewEngine == ViewEngine.Mvc || p.ViewEngine == ViewEngine.Razor) { sampleViewPath = Path.Combine(sampleViewPath, "Home"); } if (p.Language == CodeLanguage.Cs && p.ViewEngine == ViewEngine.WebForms) { RenderFile(Path.Combine(sampleViewPath, "Default.aspx"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Index.cshtml", "~/views/" + context.Name + "/Generic/Index.cshtml" }, viewData); RenderFile(Path.Combine(sampleViewPath, "Default.aspx.cs"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Codebehind.cshtml", "~/views/" + context.Name + "/Generic/Codebehind.cshtml" }, viewData); RenderFile(Path.Combine(sampleViewPath, "Default.aspx.designer.cs"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Designer.cshtml", "~/views/" + context.Name + "/Generic/Designer.cshtml" }, viewData); } else if (p.Language == CodeLanguage.Cs && p.ViewEngine == ViewEngine.Mvc) { RenderFile(Path.Combine(sampleViewPath, "Index.aspx"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Index.cshtml", "~/views/" + context.Name + "/Generic/Index.cshtml" }, viewData); RenderFile(Path.Combine(sampleViewPath, "UploadResult.aspx"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/UploadResult.cshtml", "~/views/" + context.Name + "/Generic/UploadResult.cshtml" }, viewData, false); RenderFile(Path.Combine(sampleControllerPath, sampleControllerName + ".cs"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Codebehind.cshtml", "~/views/" + context.Name + "/Generic/Codebehind.cshtml" }, viewData); } else if (p.Language == CodeLanguage.Cs && p.ViewEngine == ViewEngine.Razor) { RenderFile(Path.Combine(sampleViewPath, "Index.cshtml"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Index.cshtml", "~/views/" + context.Name + "/Generic/Index.cshtml" }, viewData); RenderFile(Path.Combine(sampleViewPath, "UploadResult.cshtml"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/UploadResult.cshtml", "~/views/" + context.Name + "/Generic/UploadResult.cshtml" }, viewData, false); RenderFile(Path.Combine(sampleControllerPath, sampleControllerName + ".cs"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Codebehind.cshtml", "~/views/" + context.Name + "/Generic/Codebehind.cshtml" }, viewData); } else if (p.Language == CodeLanguage.Vb && p.ViewEngine == ViewEngine.WebForms) { RenderFile(Path.Combine(sampleViewPath, "Default.aspx"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Index.cshtml", "~/views/" + context.Name + "/Generic/Index.cshtml" }, viewData); RenderFile(Path.Combine(sampleViewPath, "Default.aspx.vb"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Codebehind.cshtml", "~/views/" + context.Name + "/Generic/Codebehind.cshtml" }, viewData); RenderFile(Path.Combine(sampleViewPath, "Default.aspx.designer.vb"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Designer.cshtml", "~/views/" + context.Name + "/Generic/Designer.cshtml" }, viewData); } else if (p.Language == CodeLanguage.Vb && p.ViewEngine == ViewEngine.Mvc) { RenderFile(Path.Combine(sampleViewPath, "Index.aspx"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Index.cshtml", "~/views/" + context.Name + "/Generic/Index.cshtml" }, viewData); RenderFile(Path.Combine(sampleViewPath, "UploadResult.aspx"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/UploadResult.cshtml", "~/views/" + context.Name + "/Generic/UploadResult.cshtml" }, viewData, false); RenderFile(Path.Combine(sampleControllerPath, sampleControllerName + ".vb"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Codebehind.cshtml", "~/views/" + context.Name + "/Generic/Codebehind.cshtml" }, viewData); } else if (p.Language == CodeLanguage.Vb && p.ViewEngine == ViewEngine.Razor) { RenderFile(Path.Combine(sampleViewPath, "Index.vbhtml"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Index.cshtml", "~/views/" + context.Name + "/Generic/Index.cshtml" }, viewData); RenderFile(Path.Combine(sampleViewPath, "UploadResult.vbhtml"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/UploadResult.cshtml", "~/views/" + context.Name + "/Generic/UploadResult.cshtml" }, viewData, false); RenderFile(Path.Combine(sampleControllerPath, sampleControllerName + ".vb"), new string[] { "~/views/" + context.Name + "/" + s.Path + "/Codebehind.cshtml", "~/views/" + context.Name + "/Generic/Codebehind.cshtml" }, viewData); } }
private void RenderProject(RenderContext context, Project p) { string rootPath = context.Path; if (!rootPath.EndsWith("\\")) rootPath += "\\"; ViewDataDictionary viewData = new ViewDataDictionary(); viewData["Project"] = p; IEnumerable<string> codeFiles = Directory.EnumerateFiles(rootPath, "*." + p.Language, SearchOption.AllDirectories); IEnumerable<string> contentFiles = Directory.EnumerateFiles(rootPath, "*.*", SearchOption.AllDirectories).Where(x => !x.EndsWith("proj", StringComparison.InvariantCultureIgnoreCase)).Except(codeFiles); viewData["CodeFiles"] = codeFiles.Select(x => x.Substring(rootPath.Length)); viewData["ContentFiles"] = contentFiles.Select(x => x.Substring(rootPath.Length)); for (int i = 0; i < p.Versions.Length; i++) { viewData["Version"] = p.Versions[i]; RenderFile(Path.Combine(rootPath, p.GetProjectFileName(i)), "~/views/" + context.Name + "/Project.cshtml", viewData); } }
private void RenderLayout(RenderContext context, Project p, List<Sample> samples) { string sourceTemplate = "~/views/" + context.Name + "/Layout.cshtml"; if (System.IO.File.Exists(Server.MapPath(sourceTemplate))) { ViewDataDictionary viewData = new ViewDataDictionary(); viewData["Project"] = p; viewData["Samples"] = samples; if (p.Language == CodeLanguage.Cs && p.ViewEngine == ViewEngine.WebForms) { RenderFile(Path.Combine(context.Path, "Shared", "Site.master"), sourceTemplate, viewData); } else if (p.Language == CodeLanguage.Cs && p.ViewEngine == ViewEngine.Mvc) { RenderFile(Path.Combine(context.Path, "Views\\Shared", "Site.master"), sourceTemplate, viewData); } else if (p.Language == CodeLanguage.Cs && p.ViewEngine == ViewEngine.Razor) { RenderFile(Path.Combine(context.Path, "Views\\Shared", "_Layout.cshtml"), sourceTemplate, viewData); } else if (p.Language == CodeLanguage.Vb && p.ViewEngine == ViewEngine.WebForms) { RenderFile(Path.Combine(context.Path, "Shared", "Site.master"), sourceTemplate, viewData); } else if (p.Language == CodeLanguage.Vb && p.ViewEngine == ViewEngine.Mvc) { RenderFile(Path.Combine(context.Path, "Views\\Shared", "Site.master"), sourceTemplate, viewData); } else if (p.Language == CodeLanguage.Vb && p.ViewEngine == ViewEngine.Razor) { RenderFile(Path.Combine(context.Path, "Views\\Shared", "_Layout.vbhtml"), sourceTemplate, viewData); } } }
private void RenderWebConfig(RenderContext context, Project p) { ViewDataDictionary viewData = new ViewDataDictionary(); viewData["Project"] = p; string fileName = Path.Combine(context.Path, "Web.config"); RenderFile(fileName, "~/views/" + context.Name + "/WebConfig.cshtml", viewData); }
private void CopyScaffold(List<string> scaffoldFolders, string projectPath, Project p) { Func<string, bool> fileFilter; if (p.Language == CodeLanguage.Cs) fileFilter = (x) => x.IndexOf(".svn") == -1 && !x.EndsWith(".vb", StringComparison.InvariantCultureIgnoreCase); else fileFilter = (x) => x.IndexOf(".svn") == -1 && !x.EndsWith(".cs", StringComparison.InvariantCultureIgnoreCase); foreach (string path in scaffoldFolders) { string scaffoldSource = Server.MapPath(path); if (Directory.Exists(scaffoldSource)) CopyFolder(scaffoldSource, projectPath, fileFilter); } }
private void TemplateScaffold(string projectPath, Project p) { if (Directory.Exists(projectPath)) { Dictionary<string, string> templateArgs = new Dictionary<string, string> { { "Namespace", p.Name }, { "Language", (p.Language == CodeLanguage.Cs ? "C#" : "VB") }, { "LanguageExtension", p.Language.ToString().ToLower() }, { "LineTerminator", (p.Language == CodeLanguage.Cs ? ";" : "") } }; foreach (string file in Directory.EnumerateFiles(projectPath, "*.*", SearchOption.AllDirectories).Where(x => x.EndsWith("." + p.Language.ToString(), StringComparison.InvariantCultureIgnoreCase) || x.EndsWith(".aspx", StringComparison.InvariantCultureIgnoreCase) || x.EndsWith(".asax", StringComparison.InvariantCultureIgnoreCase) || x.EndsWith(".ashx", StringComparison.InvariantCultureIgnoreCase))) { StringBuilder sb = new StringBuilder(System.IO.File.ReadAllText(file)); foreach (string key in templateArgs.Keys) sb.Replace("$" + key, templateArgs[key]); System.IO.File.WriteAllText(file, sb.ToString()); } } }
private void RenderSolutionProject(StreamWriter w, Project p, Solution s, string rootPath) { w.Write("Project(\""); w.Write(p.TypeGuid.ToString("B")); w.Write("\") = \""); w.Write(p.Name); w.Write("\", \""); w.Write(Path.Combine(p.Name, p.GetProjectFileName(s.Version))); w.Write("\", \""); w.Write(p.ProjectGuid.ToString("B")); w.WriteLine("\""); w.WriteLine("ProjectSection(WebsiteProperties) = preProject"); w.WriteLine(@"Debug.AspNetCompiler.Debug = ""True"""); w.WriteLine(@"Release.AspNetCompiler.Release = ""False"""); w.WriteLine("EndProjectSection"); w.WriteLine("EndProject"); }
private void RenderSolutionProjectConfiguration(StreamWriter w, Project p) { w.WriteLine(p.ProjectGuid.ToString("B") + ".Debug|Any CPU.ActiveCfg = Debug|Any CPU"); w.WriteLine(p.ProjectGuid.ToString("B") + ".Debug|Any CPU.Build.0 = Debug|Any CPU"); w.WriteLine(p.ProjectGuid.ToString("B") + ".Release|Any CPU.ActiveCfg = Release|Any CPU"); w.WriteLine(p.ProjectGuid.ToString("B") + ".Release|Any CPU.Build.0 = Release|Any CPU"); }