Пример #1
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);
        }
        public static Template Import(XmlNode n, User u)
        {
            string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("Alias"));

            Template t = Template.GetByAlias(alias);

            if (t == null)
            {
                t = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("Name")), u);
            }

            t.Alias = alias;

            t.ImportDesign(xmlHelper.GetNodeValue(n.SelectSingleNode("Design")));

            return(t);
        }
Пример #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);
					break;
				case RenderingEngine.WebForms:
					MasterPageHelper.CreateMasterPage(t);
					break;
			}

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

            return t;
        }