コード例 #1
0
        private void CommunityHome()
        {
            var migrationName = MethodBase.GetCurrentMethod().Name;

            try
            {
                var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt");
                if (File.Exists(path))
                    return;

                var macroService = UmbracoContext.Current.Application.Services.MacroService;
                var macroAlias = "CommunityHome";
                if (macroService.GetByAlias(macroAlias) == null)
                {
                    // Run migration

                    var macro = new Macro
                    {
                        Name = "[Community] Home",
                        Alias = macroAlias,
                        ScriptingFile = "~/Views/MacroPartials/Community/Home.cshtml",
                        UseInEditor = true
                    };
                    macro.Save();
                }

                string[] lines = { "" };
                File.WriteAllLines(path, lines);
            }
            catch (Exception ex)
            {
                LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
            }
        }
コード例 #2
0
        public override bool PerformSave()
        {
            var template = Alias.Substring(0, Alias.IndexOf("|||")).Trim();
            var fileName = Alias.Substring(Alias.IndexOf("|||") + 3, Alias.Length - Alias.IndexOf("|||") - 3).Replace(" ", "");

            if (!fileName.Contains("."))
            {
                fileName = Alias + ".py";
            }

            var scriptContent = "";

            if (!string.IsNullOrEmpty(template))
            {
                var templateFile = System.IO.File.OpenText(IOHelper.MapPath(SystemDirectories.Umbraco + "/scripting/templates/" + template));
                scriptContent = templateFile.ReadToEnd();
                templateFile.Close();
            }

            var abFileName = IOHelper.MapPath(SystemDirectories.MacroScripts + "/" + fileName);

            if (!System.IO.File.Exists(abFileName))
            {
                if (fileName.Contains("/"))                 //if there's a / create the folder structure for it
                {
                    var folders  = fileName.Split("/".ToCharArray());
                    var basePath = IOHelper.MapPath(SystemDirectories.MacroScripts);
                    for (var i = 0; i < folders.Length - 1; i++)
                    {
                        basePath = System.IO.Path.Combine(basePath, folders[i]);
                        System.IO.Directory.CreateDirectory(basePath);
                    }
                }

                var scriptWriter = System.IO.File.CreateText(abFileName);
                scriptWriter.Write(scriptContent);
                scriptWriter.Flush();
                scriptWriter.Close();

                if (ParentID == 1)
                {
                    var name = fileName
                               .Substring(0, (fileName.LastIndexOf('.') + 1)).Trim('.')
                               .SplitPascalCasing().ToFirstUpperInvariant();
                    cms.businesslogic.macro.Macro m = cms.businesslogic.macro.Macro.MakeNew(name);
                    m.ScriptingFile = fileName;
                    m.Save();
                }
            }

            _returnUrl = string.Format(SystemDirectories.Umbraco + "/developer/python/editPython.aspx?file={0}", fileName);
            return(true);
        }
コード例 #3
0
ファイル: Macro.cs プロジェクト: elrute/Triphulcas
        public static Macro Import(XmlNode n)
        {

            Macro m = null;
            string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("alias"));
            try
            {
                //check to see if the macro alreay exists in the system
                //it's better if it does and we keep using it, alias *should* be unique remember
                m = new Macro(alias);
                Macro.GetByAlias(alias);
            }
            catch (IndexOutOfRangeException)
            {
                m = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("name")));
            }

            try
            {
                m.Alias = alias;
                m.Assembly = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
                m.Type = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
                m.Xslt = xmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
                m.RefreshRate = int.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));

                if (n.SelectSingleNode("scriptingFile") != null)
                    m.ScriptingFile = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptingFile"));

                try
                {
                    m.UseInEditor = bool.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
                }
                catch (Exception macroExp)
                {
                    BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "Error creating macro property: " + macroExp.ToString());
                }

                // macro properties
                foreach (XmlNode mp in n.SelectNodes("properties/property"))
                {
                    try
                    {
                        string propertyAlias = mp.Attributes.GetNamedItem("alias").Value;
                        var property = m.Properties.SingleOrDefault(p => p.Alias == propertyAlias);
                        if (property != null)
                        {
                            property.Public = bool.Parse(mp.Attributes.GetNamedItem("show").Value);
                            property.Name = mp.Attributes.GetNamedItem("name").Value;
                            property.Type = new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value);

                            property.Save();
                        }
                        else
                        {
                            MacroProperty.MakeNew(
                                m,
                                bool.Parse(mp.Attributes.GetNamedItem("show").Value),
                                propertyAlias,
                                mp.Attributes.GetNamedItem("name").Value,
                                new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
                            );
                        }
                    }
                    catch (Exception macroPropertyExp)
                    {
                        BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "Error creating macro property: " + macroPropertyExp.ToString());
                    }
                }

                m.Save();
            }
            catch { return null; }

            return m;
        }
コード例 #4
0
ファイル: editMacro.aspx.cs プロジェクト: kjetilb/Umbraco-CMS
		protected void Page_Load(object sender, EventArgs e)
		{
			m_macro = new Macro(Convert.ToInt32(Request.QueryString["macroID"]));

			if (!IsPostBack)
			{

				ClientTools
					.SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree<loadMacros>().Tree.Alias)
					.SyncTree("-1,init," + m_macro.Id.ToString(), false);

				string tempMacroAssembly = m_macro.Assembly ?? "";
				string tempMacroType = m_macro.Type ?? "";

				PopulateFieldsOnLoad(m_macro, tempMacroAssembly, tempMacroType);

				// Check for assemblyBrowser
				if (tempMacroType.IndexOf(".ascx") > 0)
					assemblyBrowserUserControl.Controls.Add(
						new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('" + IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/developer/macros/assemblyBrowser.aspx?fileName=" + macroUserControl.Text +
										   "&macroID=" + m_macro.Id.ToString() +
										   "', 'Browse Properties', true, 475,500); return false;\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));
				else if (tempMacroType != string.Empty && tempMacroAssembly != string.Empty)
					assemblyBrowser.Controls.Add(
						new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('" + IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/developer/macros/assemblyBrowser.aspx?fileName=" + macroAssembly.Text +
										   "&macroID=" + m_macro.Id.ToString() + "&type=" + macroType.Text +
										   "', 'Browse Properties', true, 475,500); return false\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));

				// Load elements from macro
				macroPropertyBind();

				// Load xslt files from default dir
				PopulateXsltFiles();

				// Load python files from default dir
				PopulatePythonFiles();

				// Load usercontrols
				PopulateUserControls(IOHelper.MapPath(SystemDirectories.UserControls));
				userControlList.Items.Insert(0, new ListItem("Browse usercontrols on server...", string.Empty));

			}
			else
			{
				int macroID = Convert.ToInt32(Request.QueryString["macroID"]);

				string tempMacroAssembly = macroAssembly.Text;
				string tempMacroType = macroType.Text;
				string tempCachePeriod = cachePeriod.Text;
				if (tempCachePeriod == string.Empty)
					tempCachePeriod = "0";
				if (tempMacroAssembly == string.Empty && macroUserControl.Text != string.Empty)
					tempMacroType = macroUserControl.Text;

				SetMacroValuesFromPostBack(m_macro, Convert.ToInt32(tempCachePeriod), tempMacroAssembly, tempMacroType);
				
				m_macro.Save();				
				
				// Save elements
				foreach (RepeaterItem item in macroProperties.Items)
				{
					HtmlInputHidden macroPropertyID = (HtmlInputHidden)item.FindControl("macroPropertyID");
					TextBox macroElementName = (TextBox)item.FindControl("macroPropertyName");
					TextBox macroElementAlias = (TextBox)item.FindControl("macroPropertyAlias");
					CheckBox macroElementShow = (CheckBox)item.FindControl("macroPropertyHidden");
					DropDownList macroElementType = (DropDownList)item.FindControl("macroPropertyType");

					MacroProperty mp = new MacroProperty(int.Parse(macroPropertyID.Value));
					mp.Type = new MacroPropertyType(int.Parse(macroElementType.SelectedValue));
					mp.Alias = macroElementAlias.Text;
					mp.Name = macroElementName.Text;
					mp.Save();

				}
				// Flush macro from cache!
				if (UmbracoSettings.UseDistributedCalls)
					dispatcher.Refresh(
						new Guid("7B1E683C-5F34-43dd-803D-9699EA1E98CA"),
						macroID);
				else
					macro.GetMacro(macroID).removeFromCache();

                ClientTools.ShowSpeechBubble(speechBubbleIcon.save, "Macro saved", "");


				// Check for assemblyBrowser
				if (tempMacroType.IndexOf(".ascx") > 0)
					assemblyBrowserUserControl.Controls.Add(
						new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('developer/macros/assemblyBrowser.aspx?fileName=" + macroUserControl.Text +
							"&macroID=" + Request.QueryString["macroID"] +
								"', 'Browse Properties', true, 500, 475); return false\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));
				else if (tempMacroType != string.Empty && tempMacroAssembly != string.Empty)
					assemblyBrowser.Controls.Add(
						new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('developer/macros/assemblyBrowser.aspx?fileName=" + macroAssembly.Text +
							"&macroID=" + Request.QueryString["macroID"] + "&type=" + macroType.Text +
								"', 'Browse Properties', true, 500, 475); return false\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));
			}
		}
コード例 #5
0
ファイル: Macro.cs プロジェクト: jraghu24/Rraghu
        public static Macro Import(XmlNode n)
        {
            Macro  m     = null;
            string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("alias"));

            try
            {
                //check to see if the macro alreay exists in the system
                //it's better if it does and we keep using it, alias *should* be unique remember
                m = new Macro(alias);
                Macro.GetByAlias(alias);
            }
            catch (IndexOutOfRangeException)
            {
                m = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("name")));
            }

            try
            {
                m.Alias       = alias;
                m.Assembly    = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
                m.Type        = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
                m.Xslt        = xmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
                m.RefreshRate = int.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));

                // we need to validate if the usercontrol is missing the tilde prefix requirement introduced in v6
                if (String.IsNullOrEmpty(m.Assembly) && !String.IsNullOrEmpty(m.Type) && !m.Type.StartsWith("~"))
                {
                    m.Type = "~/" + m.Type;
                }

                if (n.SelectSingleNode("scriptingFile") != null)
                {
                    m.ScriptingFile = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptingFile"));
                }

                try
                {
                    m.UseInEditor = bool.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
                }
                catch (Exception macroExp)
                {
                    LogHelper.Error <Macro>("Error creating macro property", macroExp);
                }

                // macro properties
                foreach (XmlNode mp in n.SelectNodes("properties/property"))
                {
                    try
                    {
                        string propertyAlias = mp.Attributes.GetNamedItem("alias").Value;
                        var    property      = m.Properties.SingleOrDefault(p => p.Alias == propertyAlias);
                        if (property != null)
                        {
                            property.Public = bool.Parse(mp.Attributes.GetNamedItem("show").Value);
                            property.Name   = mp.Attributes.GetNamedItem("name").Value;
                            property.Type   = new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value);

                            property.Save();
                        }
                        else
                        {
                            MacroProperty.MakeNew(
                                m,
                                bool.Parse(mp.Attributes.GetNamedItem("show").Value),
                                propertyAlias,
                                mp.Attributes.GetNamedItem("name").Value,
                                new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
                                );
                        }
                    }
                    catch (Exception macroPropertyExp)
                    {
                        LogHelper.Error <Macro>("Error creating macro property", macroPropertyExp);
                    }
                }

                m.Save();
            }
            catch { return(null); }

            return(m);
        }
コード例 #6
0
ファイル: Macro.cs プロジェクト: saciervo/Umbraco-CMS
        public static Macro Import(XmlNode n)
        {

            Macro m = null;
            string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("alias"));
            try
            {
                //check to see if the macro alreay exists in the system
                //it's better if it does and we keep using it, alias *should* be unique remember
                m = new Macro(alias);
                Macro.GetByAlias(alias);
            }
            catch (IndexOutOfRangeException)
            {
                m = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("name")));
            }

            try
            {
                m.Alias = alias;
                m.Assembly = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
                m.Type = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
                m.Xslt = xmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
                m.RefreshRate = int.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));

                // we need to validate if the usercontrol is missing the tilde prefix requirement introduced in v6
                if (String.IsNullOrEmpty(m.Assembly) && !String.IsNullOrEmpty(m.Type) && !m.Type.StartsWith("~"))
                    m.Type = "~/" + m.Type;

                if (n.SelectSingleNode("scriptingFile") != null)
                    m.ScriptingFile = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptingFile"));

                try
                {
                    m.UseInEditor = bool.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
                }
                catch (Exception macroExp)
                {
					LogHelper.Error<Macro>("Error creating macro property", macroExp);
                }

                // macro properties
                foreach (XmlNode mp in n.SelectNodes("properties/property"))
                {
                    try
                    {
                        string propertyAlias = mp.Attributes.GetNamedItem("alias").Value;
                        var property = m.Properties.SingleOrDefault(p => p.Alias == propertyAlias);
                        if (property != null)
                        {
                            property.Public = bool.Parse(mp.Attributes.GetNamedItem("show").Value);
                            property.Name = mp.Attributes.GetNamedItem("name").Value;
                            property.Type = new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value);

                            property.Save();
                        }
                        else
                        {
                            MacroProperty.MakeNew(
                                m,
                                bool.Parse(mp.Attributes.GetNamedItem("show").Value),
                                propertyAlias,
                                mp.Attributes.GetNamedItem("name").Value,
                                new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
                            );
                        }
                    }
                    catch (Exception macroPropertyExp)
                    {
						LogHelper.Error<Macro>("Error creating macro property", macroPropertyExp);
                    }
                }

                m.Save();
            }
            catch { return null; }

            return m;
        }
コード例 #7
0
ファイル: editMacro.aspx.cs プロジェクト: jracabado/justEdit-
        protected void Page_Load(object sender, EventArgs e)
        {
            m_macro = new Macro(Convert.ToInt32(Request.QueryString["macroID"]));

            if (!IsPostBack)
            {

                ClientTools
                    .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree<loadMacros>().Tree.Alias)
                    .SyncTree(m_macro.Id.ToString(), false);

                macroName.Text = m_macro.Name;
                macroAlias.Text = m_macro.Alias;
                string tempMacroAssembly = m_macro.Assembly == null ? "" : m_macro.Assembly;
                string tempMacroType = m_macro.Type == null ? "" : m_macro.Type;
                macroXslt.Text = m_macro.Xslt;
                macroPython.Text = m_macro.ScriptingFile;
                cachePeriod.Text = m_macro.RefreshRate.ToString();

                macroRenderContent.Checked = m_macro.RenderContent;
                macroEditor.Checked = m_macro.UseInEditor;
                cacheByPage.Checked = m_macro.CacheByPage;
                cachePersonalized.Checked = m_macro.CachePersonalized;

                // Populate either user control or custom control
                if (tempMacroType != string.Empty && tempMacroAssembly != string.Empty)
                {
                    macroAssembly.Text = tempMacroAssembly;
                    macroType.Text = tempMacroType;
                }
                else
                {
                    macroUserControl.Text = tempMacroType;
                }

                // Check for assemblyBrowser
                if (tempMacroType.IndexOf(".ascx") > 0)
                    assemblyBrowserUserControl.Controls.Add(
                        new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('" + umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/developer/macros/assemblyBrowser.aspx?fileName=" + macroUserControl.Text +
                                           "&macroID=" + m_macro.Id.ToString() +
                                           "', 'Browse Properties', true, 475,500); return false;\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));
                else if (tempMacroType != string.Empty && tempMacroAssembly != string.Empty)
                    assemblyBrowser.Controls.Add(
                        new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('" + umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/developer/macros/assemblyBrowser.aspx?fileName=" + macroAssembly.Text +
                                           "&macroID=" + m_macro.Id.ToString() + "&type=" + macroType.Text +
                                           "', 'Browse Properties', true, 475,500); return false\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));

                // Load elements from macro
                macroPropertyBind();

                // Load xslt files from default dir
                populateXsltFiles();

                // Load python files from default dir
                populatePythonFiles();

                // Load usercontrols
                populateUserControls(IOHelper.MapPath(SystemDirectories.Usercontrols) );
                userControlList.Items.Insert(0, new ListItem("Browse usercontrols on server...", string.Empty));
                userControlList.Attributes.Add("onChange",
                    "document.getElementById('" + macroUserControl.ClientID + "').value = this[this.selectedIndex].value;");

            }
            else
            {
                int macroID = Convert.ToInt32(Request.QueryString["macroID"]);
                string tempMacroAssembly = macroAssembly.Text;
                string tempMacroType = macroType.Text;
                string tempCachePeriod = cachePeriod.Text;

                if (tempCachePeriod == string.Empty)
                    tempCachePeriod = "0";

                if (tempMacroAssembly == string.Empty && macroUserControl.Text != string.Empty)
                    tempMacroType = macroUserControl.Text;

                // Save macro
                m_macro.UseInEditor = macroEditor.Checked;
                m_macro.RenderContent = macroRenderContent.Checked;
                m_macro.CacheByPage = cacheByPage.Checked;
                m_macro.CachePersonalized = cachePersonalized.Checked;
                m_macro.RefreshRate = Convert.ToInt32(tempCachePeriod);
                m_macro.Alias = macroAlias.Text;
                m_macro.Name = macroName.Text;
                m_macro.Assembly = tempMacroAssembly;
                m_macro.Type = tempMacroType;
                m_macro.Xslt = macroXslt.Text;
                m_macro.ScriptingFile = macroPython.Text;
                m_macro.Save();

                // Save elements
                foreach (RepeaterItem item in macroProperties.Items)
                {
                    HtmlInputHidden macroPropertyID = (HtmlInputHidden)item.FindControl("macroPropertyID");
                    TextBox macroElementName = (TextBox)item.FindControl("macroPropertyName");
                    TextBox macroElementAlias = (TextBox)item.FindControl("macroPropertyAlias");
                    CheckBox macroElementShow = (CheckBox)item.FindControl("macroPropertyHidden");
                    DropDownList macroElementType = (DropDownList)item.FindControl("macroPropertyType");

                    MacroProperty mp = new MacroProperty(int.Parse(macroPropertyID.Value));
                    mp.Public = macroElementShow.Checked;
                    mp.Type = new MacroPropertyType(int.Parse(macroElementType.SelectedValue));
                    mp.Alias = macroElementAlias.Text;
                    mp.Name = macroElementName.Text;
                    mp.Save();

                }
                // Flush macro from cache!
                if (UmbracoSettings.UseDistributedCalls)
                    dispatcher.Refresh(
                        new Guid("7B1E683C-5F34-43dd-803D-9699EA1E98CA"),
                        macroID);
                else
                    new macro(macroID).removeFromCache();

                // Check for assemblyBrowser
                if (tempMacroType.IndexOf(".ascx") > 0)
                    assemblyBrowserUserControl.Controls.Add(
                        new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('developer/macros/assemblyBrowser.aspx?fileName=" + macroUserControl.Text +
                            "&macroID=" + Request.QueryString["macroID"] +
                                "', 'Browse Properties', true, 500, 475); return false\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));
                else if (tempMacroType != string.Empty && tempMacroAssembly != string.Empty)
                    assemblyBrowser.Controls.Add(
                        new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('developer/macros/assemblyBrowser.aspx?fileName=" + macroAssembly.Text +
                            "&macroID=" + Request.QueryString["macroID"] + "&type=" + macroType.Text +
                                "', 'Browse Properties', true, 500, 475); return false\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));
            }
        }
コード例 #8
0
ファイル: Macro.cs プロジェクト: SKDon/Triphulcas
        public static Macro Import(XmlNode n)
        {
            Macro  m     = null;
            string alias = xmlHelper.GetNodeValue(n.SelectSingleNode("alias"));

            try
            {
                //check to see if the macro alreay exists in the system
                //it's better if it does and we keep using it, alias *should* be unique remember
                m = new Macro(alias);
                Macro.GetByAlias(alias);
            }
            catch (IndexOutOfRangeException)
            {
                m = MakeNew(xmlHelper.GetNodeValue(n.SelectSingleNode("name")));
            }

            try
            {
                m.Alias       = alias;
                m.Assembly    = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
                m.Type        = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
                m.Xslt        = xmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
                m.RefreshRate = int.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));

                if (n.SelectSingleNode("scriptingFile") != null)
                {
                    m.ScriptingFile = xmlHelper.GetNodeValue(n.SelectSingleNode("scriptingFile"));
                }

                try
                {
                    m.UseInEditor = bool.Parse(xmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
                }
                catch (Exception macroExp)
                {
                    BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "Error creating macro property: " + macroExp.ToString());
                }

                // macro properties
                foreach (XmlNode mp in n.SelectNodes("properties/property"))
                {
                    try
                    {
                        string propertyAlias = mp.Attributes.GetNamedItem("alias").Value;
                        var    property      = m.Properties.SingleOrDefault(p => p.Alias == propertyAlias);
                        if (property != null)
                        {
                            property.Public = bool.Parse(mp.Attributes.GetNamedItem("show").Value);
                            property.Name   = mp.Attributes.GetNamedItem("name").Value;
                            property.Type   = new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value);

                            property.Save();
                        }
                        else
                        {
                            MacroProperty.MakeNew(
                                m,
                                bool.Parse(mp.Attributes.GetNamedItem("show").Value),
                                propertyAlias,
                                mp.Attributes.GetNamedItem("name").Value,
                                new MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
                                );
                        }
                    }
                    catch (Exception macroPropertyExp)
                    {
                        BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "Error creating macro property: " + macroPropertyExp.ToString());
                    }
                }

                m.Save();
            }
            catch { return(null); }

            return(m);
        }
コード例 #9
0
        public override bool PerformSave()
        {
            IOHelper.EnsurePathExists(SystemDirectories.Xslt);
            IOHelper.EnsureFileExists(Path.Combine(IOHelper.MapPath(SystemDirectories.Xslt), "web.config"), Files.BlockingWebConfig);

            var template = Alias.Substring(0, Alias.IndexOf("|||"));
            var fileName = Alias.Substring(Alias.IndexOf("|||") + 3, Alias.Length - Alias.IndexOf("|||") - 3).Replace(" ", "");

            if (fileName.ToLowerInvariant().EndsWith(".xslt") == false)
            {
                fileName += ".xslt";
            }
            var xsltTemplateSource = IOHelper.MapPath(SystemDirectories.Umbraco + "/xslt/templates/" + template);
            var xsltNewFilename    = IOHelper.MapPath(SystemDirectories.Xslt + "/" + fileName);

            if (File.Exists(xsltNewFilename) == false)
            {
                if (fileName.Contains("/"))                 //if there's a / create the folder structure for it
                {
                    var folders      = fileName.Split("/".ToCharArray());
                    var xsltBasePath = IOHelper.MapPath(SystemDirectories.Xslt);
                    for (var i = 0; i < folders.Length - 1; i++)
                    {
                        xsltBasePath = System.IO.Path.Combine(xsltBasePath, folders[i]);
                        System.IO.Directory.CreateDirectory(xsltBasePath);
                    }
                }

                // update with xslt references
                var xslt = "";
                using (var xsltFile = System.IO.File.OpenText(xsltTemplateSource))
                {
                    xslt = xsltFile.ReadToEnd();
                    xsltFile.Close();
                }

                // prepare support for XSLT extensions
                xslt = macro.AddXsltExtensionsToHeader(xslt);
                var xsltWriter = System.IO.File.CreateText(xsltNewFilename);
                xsltWriter.Write(xslt);
                xsltWriter.Flush();
                xsltWriter.Close();

                // Create macro?
                if (ParentID == 1)
                {
                    var name = Alias.Substring(Alias.IndexOf("|||") + 3, Alias.Length - Alias.IndexOf("|||") - 3);
                    if (name.ToLowerInvariant().EndsWith(".xslt"))
                    {
                        name = name.Substring(0, name.Length - 5);
                    }

                    name = name.SplitPascalCasing().ToFirstUpperInvariant();
                    cms.businesslogic.macro.Macro m =
                        cms.businesslogic.macro.Macro.MakeNew(name);
                    m.Xslt = fileName;
                    m.Save();
                }
            }

            _returnUrl = string.Format(SystemDirectories.Umbraco + "/developer/xslt/editXslt.aspx?file={0}", fileName);

            return(true);
        }
コード例 #10
0
        private void MemberActivationMigration()
        {
            var migrationName = MethodBase.GetCurrentMethod().Name;

            try
            {
                var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt");
                if (File.Exists(path))
                    return;

                var macroService = UmbracoContext.Current.Application.Services.MacroService;
                var macroAlias = "MembersActivate";
                if (macroService.GetByAlias(macroAlias) == null)
                {
                    // Run migration

                    var macro = new Macro
                    {
                        Name = "[Members] Activate",
                        Alias = macroAlias,
                        ScriptingFile = "~/Views/MacroPartials/Members/Activate.cshtml",
                        UseInEditor = true
                    };
                    macro.Save();
                }

                var contentService = UmbracoContext.Current.Application.Services.ContentService;
                var rootNode = contentService.GetRootContent().OrderBy(x => x.SortOrder).First(x => x.ContentType.Alias == "Community");

                var memberNode = rootNode.Children().FirstOrDefault(x => x.Name == "Member");

                var pendingActivationPageName = "Pending activation";
                if (memberNode != null && memberNode.Children().Any(x => x.Name == pendingActivationPageName) == false)
                {
                    var pendingActivationPage = contentService.CreateContent(pendingActivationPageName, memberNode.Id, "Textpage");
                    pendingActivationPage.SetValue("bodyText", "<p>Thanks for signing up! <br />We\'ve sent you an email containing an activation link.</p><p>To be able to continue you need to click the link in that email. If you didn\'t get any mail from us, make sure to check your spam/junkmail folder for mail from [email protected].</p>");
                    contentService.SaveAndPublishWithStatus(pendingActivationPage);
                }

                var activatePageName = "Activate";
                if (memberNode != null && memberNode.Children().Any(x => x.Name == activatePageName) == false)
                {
                    var activatePage = contentService.CreateContent(activatePageName, memberNode.Id, "Textpage");
                    activatePage.SetValue("bodyText", string.Format("<?UMBRACO_MACRO macroAlias=\"{0}\" />", macroAlias));
                    contentService.SaveAndPublishWithStatus(activatePage);
                }

                string[] lines = {""};
                File.WriteAllLines(path, lines);
            }
            catch (Exception ex)
            {
                LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
            }
        }
コード例 #11
0
        private void SpamOverview()
        {
            var migrationName = MethodBase.GetCurrentMethod().Name;

            try
            {
                var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt");
                if (File.Exists(path))
                    return;

                var macroService = UmbracoContext.Current.Application.Services.MacroService;
                var macroAlias = "AntiSpam";
                if (macroService.GetByAlias(macroAlias) == null)
                {
                    // Run migration

                    var macro = new Macro
                    {
                        Name = "[Spam] Overview",
                        Alias = macroAlias,
                        ScriptingFile = "~/Views/MacroPartials/Spam/Overview.cshtml",
                        UseInEditor = true
                    };
                    macro.Save();
                }

                var contentService = UmbracoContext.Current.Application.Services.ContentService;
                var rootNode = contentService.GetRootContent().OrderBy(x => x.SortOrder).First(x => x.ContentType.Alias == "Community");

                var antiSpamPageName = "AntiSpam";
                if(rootNode.Children().Any(x => x.Name == antiSpamPageName) == false)
                {
                    var content = contentService.CreateContent(antiSpamPageName, rootNode.Id, "Textpage");
                    content.SetValue("bodyText", string.Format("<?UMBRACO_MACRO macroAlias=\"{0}\" />", macroAlias));
                    contentService.SaveAndPublishWithStatus(content);
                }

                string[] lines = { "" };
                File.WriteAllLines(path, lines);
            }
            catch (Exception ex)
            {
                LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
            }
        }