Beispiel #1
0
        /// <summary>
        /// This checks what the default rendering engine is set in config but then also ensures that there isn't already
        /// a template that exists in the opposite rendering engine's template folder, then returns the appropriate
        /// rendering engine to use.
        /// </summary>
        /// <param name="t"></param>
        /// <param name="design">If a template body is specified we'll check if it contains master page markup, if it does we'll auto assume its webforms </param>
        /// <returns></returns>
        /// <remarks>
        /// The reason this is required is because for example, if you have a master page file already existing under ~/masterpages/Blah.aspx
        /// and then you go to create a template in the tree called Blah and the default rendering engine is MVC, it will create a Blah.cshtml
        /// empty template in ~/Views. This means every page that is using Blah will go to MVC and render an empty page.
        /// This is mostly related to installing packages since packages install file templates to the file system and then create the
        /// templates in business logic. Without this, it could cause the wrong rendering engine to be used for a package.
        /// </remarks>
        private static RenderingEngine DetermineRenderingEngine(Template t, string design = null)
        {
            var engine = Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine;

            if (!design.IsNullOrWhiteSpace() && MasterPageHelper.IsMasterPageSyntax(design))
            {
                //there is a design but its definitely a webforms design
                return(RenderingEngine.WebForms);
            }

            switch (engine)
            {
            case RenderingEngine.Mvc:
                //check if there's a view in ~/masterpages
                if (MasterPageHelper.MasterPageExists(t) && !ViewHelper.ViewExists(t))
                {
                    //change this to webforms since there's already a file there for this template alias
                    engine = RenderingEngine.WebForms;
                }
                break;

            case RenderingEngine.WebForms:
                //check if there's a view in ~/views
                if (ViewHelper.ViewExists(t) && !MasterPageHelper.MasterPageExists(t))
                {
                    //change this to mvc since there's already a file there for this template alias
                    engine = RenderingEngine.Mvc;
                }
                break;
            }
            return(engine);
        }
Beispiel #2
0
        protected override void setupNode()
        {
            base.setupNode();

            IRecordsReader dr      = SqlHelper.ExecuteReader("Select alias,design,master from cmsTemplate where nodeId = " + this.Id);
            bool           hasRows = dr.Read();

            if (hasRows)
            {
                _alias  = dr.GetString("alias");
                _design = dr.GetString("design");
                //set the master template to zero if it's null
                _mastertemplate = dr.IsNull("master") ? 0 : dr.GetInt("master");
            }
            dr.Close();

            if (Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc && ViewHelper.ViewExists(this))
            {
                _design = ViewHelper.GetFileContents(this);
            }
            else
            {
                _design = MasterPageHelper.GetFileContents(this);
            }
        }
Beispiel #3
0
        private static Template MakeNew(string name, BusinessLogic.User u, Template master, string design)
        {
            // CMSNode MakeNew(int parentId, Guid objectType, int userId, int level, string text, Guid uniqueID)
            CMSNode n = CMSNode.MakeNew(-1, _objectType, u.Id, 1, name, Guid.NewGuid());

            //ensure unique alias
            name = helpers.Casing.SafeAlias(name);
            if (GetByAlias(name) != null)
            {
                name = EnsureUniqueAlias(name, 1);
            }
            name = name.Replace("/", ".").Replace("\\", "");

            if (name.Length > 100)
            {
                name = name.Substring(0, 95) + "...";
            }


            SqlHelper.ExecuteNonQuery("INSERT INTO cmsTemplate (NodeId, Alias, design, master) VALUES (@nodeId, @alias, @design, @master)",
                                      SqlHelper.CreateParameter("@nodeId", n.Id),
                                      SqlHelper.CreateParameter("@alias", name),
                                      SqlHelper.CreateParameter("@design", ' '),
                                      SqlHelper.CreateParameter("@master", DBNull.Value));

            Template     t = new Template(n.Id);
            NewEventArgs e = new NewEventArgs();

            t.OnNew(e);

            if (master != null)
            {
                t.MasterTemplate = master.Id;
            }

            switch (DetermineRenderingEngine(t, design))
            {
            case RenderingEngine.Mvc:
                ViewHelper.CreateViewFile(t, true);
                break;

            case RenderingEngine.WebForms:
                MasterPageHelper.CreateMasterPage(t, true);
                break;
            }

            //if a design is supplied ensure it is updated.
            if (!design.IsNullOrWhiteSpace())
            {
                t.ImportDesign(design);
            }

            return(t);
        }
Beispiel #4
0
 public List <string> contentPlaceholderIds()
 {
     return(MasterPageHelper.GetContentPlaceholderIds(TemplateEntity).ToList());
 }