Beispiel #1
0
        void Generate(string name, Registry registry)
        {
            //string rootPath = "c:\\test";
            string trunkPath = Path.GetDirectoryName(Path.GetDirectoryName(Server.MapPath("~/")));
            string deployRootPath = Path.Combine(trunkPath, "DeployRoot", name);
            string rootPath = Path.Combine(trunkPath, name);

            CleanRoot(rootPath);

            if (Directory.Exists(deployRootPath))
                CopyFolder(deployRootPath, rootPath, (x) => x.IndexOf(".svn") == -1);

            foreach (Project p in registry.Projects)
            {
                string projectPath = Path.Combine(rootPath, p.Name);

                RenderContext context = new RenderContext(projectPath, name);

                List<string> scaffoldFolders = new List<string>();

                scaffoldFolders.Add("~/Scaffold/" + name + "/Common");

                if (p.ViewEngine == ViewEngine.WebForms)
                {
                    scaffoldFolders.Add("~/Scaffold/" + name + "/WebForms");
                }
                else if (p.MvcVersion > MvcVersion.None)
                {
                    scaffoldFolders.Add("~/Scaffold/" + name + "/MvcCommon");
                    scaffoldFolders.Add("~/Scaffold/" + name + "/" + p.MvcVersion.ToString());
                }

                List<Sample> supportedSampleList = registry.Samples.Where(x => !(p.IsAspNetAjax && x.HasNoAspNetAjaxSupport)).ToList();

                CopyScaffold(scaffoldFolders, projectPath, p);

                TemplateScaffold(projectPath, p);

                RenderLayout(context, p, supportedSampleList);
                RenderWebConfig(context, p);

                foreach (Sample s in supportedSampleList)
                {
                    RenderSample(context, p, s, supportedSampleList.Count == 1);
                }

                RenderProject(context, p);
            }

            foreach (Solution s in registry.Solutions)
            {
                RenderSolution(rootPath, s);
            }
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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);
                }
            }
        }
Beispiel #5
0
        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);
        }