diff --git a/src/Umbraco.Core/Logging/LogHelper.cs b/src/Umbraco.Core/Logging/LogHelper.cs index bf424ef1d5..31de04c839 100644 --- a/src/Umbraco.Core/Logging/LogHelper.cs +++ b/src/Umbraco.Core/Logging/LogHelper.cs @@ -52,10 +52,16 @@ namespace Umbraco.Core.Logging /// public static void Error(string message, Exception exception) { - var logger = LoggerFor(); + Error(typeof (T), message, exception); + } + + public static void Error(Type callingType, string message, Exception exception) + { + var logger = LogManager.GetLogger(callingType); if (logger != null) logger.Error(PrefixThreadId(message), exception); } + #endregion #region Warn diff --git a/src/Umbraco.Web/umbraco.presentation/content.cs b/src/Umbraco.Web/umbraco.presentation/content.cs index ee5da1467f..d621443808 100644 --- a/src/Umbraco.Web/umbraco.presentation/content.cs +++ b/src/Umbraco.Web/umbraco.presentation/content.cs @@ -1085,7 +1085,7 @@ namespace umbraco try { - Log.Add(LogTypes.Debug, staticUser, -1, "Republishing starting"); + LogHelper.Debug("Republishing starting"); // Lets cache the DTD to save on the DB hit on the subsequent use string dtd = DocumentType.GenerateDtd(); @@ -1155,7 +1155,7 @@ order by umbracoNode.level, umbracoNode.sortOrder"; } } - Log.Add(LogTypes.Debug, staticUser, -1, "Xml Pages loaded"); + LogHelper.Debug("Xml Pages loaded"); try { @@ -1170,7 +1170,7 @@ order by umbracoNode.level, umbracoNode.sortOrder"; // Start building the content tree recursively from the root (-1) node GenerateXmlDocument(hierarchy, nodeIndex, -1, xmlDoc.DocumentElement); - Log.Add(LogTypes.Debug, staticUser, -1, "Done republishing Xml Index"); + LogHelper.Debug("Done republishing Xml Index"); return xmlDoc; } @@ -1294,7 +1294,7 @@ order by umbracoNode.level, umbracoNode.sortOrder"; Thread.CurrentThread.Name, stopWatch.Elapsed, Thread.CurrentThread.IsThreadPoolThread)); - Log.Add(LogTypes.Debug, staticUser, -1, string.Format("Xml saved in {0}", stopWatch.Elapsed)); + LogHelper.Debug(string.Format("Xml saved in {0}", stopWatch.Elapsed)); } catch (Exception ee) { @@ -1364,10 +1364,8 @@ order by umbracoNode.level, umbracoNode.sortOrder"; { if (xmlDoc == null) return null; - Log.Add(LogTypes.Debug, -1, "Cloning..."); // Save copy of content var xmlCopy = (XmlDocument)xmlDoc.CloneNode(true); - Log.Add(LogTypes.Debug, -1, "Cloning ended..."); return xmlCopy; } diff --git a/src/Umbraco.Web/umbraco.presentation/install/steps/Skinning/loadStarterKitDesigns.ascx.cs b/src/Umbraco.Web/umbraco.presentation/install/steps/Skinning/loadStarterKitDesigns.ascx.cs index c0f8ced902..4179fe7d23 100644 --- a/src/Umbraco.Web/umbraco.presentation/install/steps/Skinning/loadStarterKitDesigns.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/install/steps/Skinning/loadStarterKitDesigns.ascx.cs @@ -5,6 +5,7 @@ using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; namespace umbraco.presentation.install.steps.Skinning @@ -60,7 +61,7 @@ namespace umbraco.presentation.install.steps.Skinning } catch (Exception ex) { - Log.Add(LogTypes.Debug, -1, ex.ToString()); + LogHelper.Error("An error occurred initializing", ex); ShowConnectionError(); } diff --git a/src/Umbraco.Web/umbraco.presentation/requestHandler.cs b/src/Umbraco.Web/umbraco.presentation/requestHandler.cs index 24be00bd6e..cd7f498e0c 100644 --- a/src/Umbraco.Web/umbraco.presentation/requestHandler.cs +++ b/src/Umbraco.Web/umbraco.presentation/requestHandler.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Reflection; using System.Web; using System.Xml; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.member; using umbraco.cms.businesslogic.template; @@ -585,21 +586,24 @@ namespace umbraco { } public bool Execute(string url) { - try { - Log.Add(LogTypes.NotFound, User.GetUser(0), -1, - url + " (from '" + HttpContext.Current.Request.UrlReferrer + "')"); + try + { + Log.Add(LogTypes.NotFound, User.GetUser(0), -1, + url + " (from '" + HttpContext.Current.Request.UrlReferrer + "')"); - // Test if the error404 not child elements - string error404 = umbraco.library.GetCurrentNotFoundPageId(); + // Test if the error404 not child elements + string error404 = umbraco.library.GetCurrentNotFoundPageId(); - _redirectID = int.Parse(error404); - HttpContext.Current.Response.StatusCode = 404; - return true; - } catch (Exception err) { - Log.Add(LogTypes.Debug, User.GetUser(0), -1, err.ToString()); - return false; - } + _redirectID = int.Parse(error404); + HttpContext.Current.Response.StatusCode = 404; + return true; + } + catch (Exception err) + { + LogHelper.Error("An error occurred", err); + return false; + } } public int redirectID { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/ActionHandlers/umbEnsureUniqueName.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/ActionHandlers/umbEnsureUniqueName.cs index 5384c27226..4c57614846 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/ActionHandlers/umbEnsureUniqueName.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/ActionHandlers/umbEnsureUniqueName.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; - +using Umbraco.Core.Logging; using umbraco.cms.businesslogic.web; using umbraco.BusinessLogic.Actions; @@ -64,8 +64,8 @@ namespace umbraco.ActionHandlers if (currentName != documentObject.Text) { // add name change to the log - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, umbraco.BusinessLogic.User.GetUser(0), documentObject.Id, "Title changed from '" + documentObject.Text + "' to '" + currentName + "'"); - + LogHelper.Debug("Title changed from '" + documentObject.Text + "' to '" + currentName + "' for document id" + documentObject.Id); + documentObject.Text = currentName; return true; diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/ModuleSelector.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/ModuleSelector.ascx.cs index d187092d10..125cfa9b51 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/ModuleSelector.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/ModuleSelector.ascx.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.cms.businesslogic.packager; @@ -41,7 +42,7 @@ namespace umbraco.presentation.umbraco.LiveEditing.Modules.SkinModule } catch (Exception exception) { - Log.Add(LogTypes.Debug, -1, exception.ToString()); + LogHelper.Error("An error occurred", exception); } } else diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/SkinCustomizer.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/SkinCustomizer.ascx.cs index 26c8d91902..746b58e82a 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/SkinCustomizer.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/SkinModule/SkinCustomizer.ascx.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using Umbraco.Core.Logging; using umbraco.cms.businesslogic.skinning; using System.Xml; using System.Text; @@ -184,7 +185,7 @@ namespace umbraco.presentation.LiveEditing.Modules.SkinModule } catch (Exception exception) { - Log.Add(LogTypes.Debug, -1, exception.ToString()); + LogHelper.Error("An error occurred", exception); } } else diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs index a8ac6aecea..b3a05f1296 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/dictionaryTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -70,7 +71,7 @@ namespace umbraco public bool Delete() { - BusinessLogic.Log.Add(LogTypes.Debug, ParentID, _typeID.ToString() + " " + _parentID.ToString() + " deleting " + Alias); + LogHelper.Debug(_typeID.ToString() + " " + _parentID.ToString() + " deleting " + Alias); new cms.businesslogic.Dictionary.DictionaryItem(ParentID).delete(); return true; diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs index 4d2c5a3950..8c3c56d370 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/simple.ascx.cs @@ -55,7 +55,6 @@ namespace umbraco.cms.presentation.create.controls nodeId, rename.Text); - Log.Add(LogTypes.Debug, -1, "return:" + returnUrl); BasePage.Current.ClientTools .ChangeContentFrameUrl(returnUrl) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/templateTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/templateTasks.cs index 03887b2cce..fd0e839165 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/templateTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/templateTasks.cs @@ -44,7 +44,6 @@ namespace umbraco public bool Save() { int masterId = ParentID; - BusinessLogic.Log.Add(LogTypes.Debug, -1, "tp id:" + masterId.ToString()); var editor = "settings/editTemplate.aspx"; if(Umbraco.Core.Configuration.UmbracoSettings.DefaultRenderingEngine == RenderingEngine.Mvc) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs index 050f0aade2..5977cecb95 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -69,8 +70,7 @@ namespace umbraco } catch (Exception ex) { - Log.Add(LogTypes.Error, ParentID, String.Format("Failed to create the user. Error from provider: {0}", status.ToString())); - Log.Add(LogTypes.Debug, ParentID, ex.Message); + LogHelper.Error(String.Format("Failed to create the user. Error from provider: {0}", status.ToString()), ex); return false; } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/LoadNitros.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/LoadNitros.ascx.cs index b3955af5b8..513d387634 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/LoadNitros.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/LoadNitros.ascx.cs @@ -9,6 +9,7 @@ using System.Collections; using System.Web.UI; using System.Web.UI.WebControls.WebParts; using System.Collections.Generic; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; namespace umbraco.presentation.developer.packages { @@ -159,28 +160,33 @@ namespace umbraco.presentation.developer.packages { fb.Text = "No connection to repository. Modules could not be fetched from the repository as there was no connection to: '" + repo.RepositoryUrl + "'"; - if (repo.HasConnection()) { - try { + if (repo.HasConnection()) + { + try + { - if(UmbracoSettings.UseLegacyXmlSchema) - rep_nitros.DataSource = repo.Webservice.NitrosCategorizedByVersion(cms.businesslogic.packager.repositories.Version.Version4); - else - rep_nitros.DataSource = repo.Webservice.NitrosCategorizedByVersion(cms.businesslogic.packager.repositories.Version.Version41); - - rep_nitros.DataBind(); - } catch (Exception ex) { + if (UmbracoSettings.UseLegacyXmlSchema) + rep_nitros.DataSource = repo.Webservice.NitrosCategorizedByVersion(cms.businesslogic.packager.repositories.Version.Version4); + else + rep_nitros.DataSource = repo.Webservice.NitrosCategorizedByVersion(cms.businesslogic.packager.repositories.Version.Version41); - Log.Add(LogTypes.Debug, -1, ex.ToString()); + rep_nitros.DataBind(); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred", ex); - loadNitros.Controls.Clear(); - loadNitros.Controls.Add(fb); - //nitroList.Visible = false; - //lt_status.Text = "

Nitros could not be fetched from the repository. Please check your internet connection

You can always install Nitros later in the packages section

" + ex.ToString() + "

"; - } - } else { - loadNitros.Controls.Clear(); - loadNitros.Controls.Add(fb); - } + loadNitros.Controls.Clear(); + loadNitros.Controls.Add(fb); + //nitroList.Visible = false; + //lt_status.Text = "

Nitros could not be fetched from the repository. Please check your internet connection

You can always install Nitros later in the packages section

" + ex.ToString() + "

"; + } + } + else + { + loadNitros.Controls.Clear(); + loadNitros.Controls.Add(fb); + } } } } \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installedPackage.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installedPackage.aspx.cs index 4d1177433d..2177fe061e 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installedPackage.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/installedPackage.aspx.cs @@ -10,7 +10,7 @@ using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; - +using Umbraco.Core.Logging; using umbraco.cms.businesslogic.template; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.macro; @@ -523,26 +523,34 @@ namespace umbraco.presentation.developer.packages } else { - BusinessLogic.Log.Add(global::umbraco.BusinessLogic.LogTypes.Debug, -1, "executing undo actions"); + LogHelper.Debug("executing undo actions"); // uninstall actions - try { - System.Xml.XmlDocument actionsXml = new System.Xml.XmlDocument(); - actionsXml.LoadXml("" + pack.Data.Actions + ""); + try + { + var actionsXml = new System.Xml.XmlDocument(); + actionsXml.LoadXml("" + pack.Data.Actions + ""); - BusinessLogic.Log.Add(global::umbraco.BusinessLogic.LogTypes.Debug, -1, actionsXml.OuterXml); - foreach (XmlNode n in actionsXml.DocumentElement.SelectNodes("//Action")) { - try { - cms.businesslogic.packager.PackageAction.UndoPackageAction(pack.Data.Name, n.Attributes["alias"].Value, n); - } catch (Exception ex) { - BusinessLogic.Log.Add(global::umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString()); - } - } - } catch (Exception ex) { - BusinessLogic.Log.Add(global::umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString()); - } + LogHelper.Debug(actionsXml.OuterXml); - //moved remove of files here so custom package actions can still undo + foreach (XmlNode n in actionsXml.DocumentElement.SelectNodes("//Action")) + { + try + { + cms.businesslogic.packager.PackageAction.UndoPackageAction(pack.Data.Name, n.Attributes["alias"].Value, n); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred in UndoPackageAction", ex); + } + } + } + catch (Exception ex) + { + LogHelper.Error("An error occurred", ex); + } + + //moved remove of files here so custom package actions can still undo //Remove files foreach (ListItem li in files.Items) { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/TemplateSkinning.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/TemplateSkinning.aspx.cs index 18d5d81214..0cf9a875ed 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/TemplateSkinning.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/TemplateSkinning.aspx.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using Umbraco.Core.Logging; using umbraco.cms.businesslogic.skinning; using umbraco.cms.businesslogic.template; using umbraco.cms.businesslogic; @@ -79,7 +80,7 @@ namespace umbraco.presentation.umbraco.dialogs } catch (Exception ex) { - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Debug, -1, ex.ToString()); + LogHelper.Error("An error occurred", ex); //ShowConnectionError(); } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TagsAutoCompleteHandler.ashx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TagsAutoCompleteHandler.ashx.cs index 161dd1f898..3f48666680 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TagsAutoCompleteHandler.ashx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/TagsAutoCompleteHandler.ashx.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Web; using System.Web.Script.Serialization; using System.Web.Services; +using Umbraco.Core.Logging; using umbraco.DataLayer; using umbraco.BusinessLogic; using umbraco.presentation.webservices; @@ -81,7 +82,7 @@ namespace umbraco.presentation.umbraco.webservices } catch (Exception ex) { - Log.Add(LogTypes.Debug, -1, ex.ToString()); + LogHelper.Error("An error occurred", ex); } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs index 1e7a26052a..81095f530e 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/nodeSorter.asmx.cs @@ -3,6 +3,7 @@ using System.Collections; using System.ComponentModel; using System.Web.Script.Services; using System.Web.Services; +using Umbraco.Core.Logging; using umbraco.BasePages; using umbraco.BusinessLogic.Actions; using umbraco.cms.businesslogic.web; @@ -150,7 +151,7 @@ namespace umbraco.presentation.webservices } catch (Exception ex) { - BusinessLogic.Log.Add(global::umbraco.BusinessLogic.LogTypes.Debug, ParentId, ex.ToString()); + LogHelper.Error("An error occurred", ex); } } diff --git a/src/umbraco.businesslogic/BasePages/BasePage.cs b/src/umbraco.businesslogic/BasePages/BasePage.cs index 6889ca929b..a74f61b355 100644 --- a/src/umbraco.businesslogic/BasePages/BasePage.cs +++ b/src/umbraco.businesslogic/BasePages/BasePage.cs @@ -174,8 +174,8 @@ namespace umbraco.BasePages { return true; } - - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Logout, BusinessLogic.User.GetUser(uid), -1, ""); + var user = BusinessLogic.User.GetUser(uid); + LogHelper.Info("User {0} (Id:{1}) logged out", () => user.Name, () => user.Id); } return false; } @@ -334,7 +334,9 @@ namespace umbraco.BasePages "') ", SqlHelper.CreateParameter("@contextId", retVal)); umbracoUserContextID = retVal.ToString(); - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Login, u, -1, ""); + + LogHelper.Info("User {0} (Id: {1}) logged in", () => u.Name, () => u.Id); + } diff --git a/src/umbraco.businesslogic/BasePages/UmbracoEnsuredPage.cs b/src/umbraco.businesslogic/BasePages/UmbracoEnsuredPage.cs index d64fe79dc3..ba2b219c1b 100644 --- a/src/umbraco.businesslogic/BasePages/UmbracoEnsuredPage.cs +++ b/src/umbraco.businesslogic/BasePages/UmbracoEnsuredPage.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.businesslogic.Exceptions; using umbraco.IO; @@ -61,7 +62,8 @@ namespace umbraco.BasePages if (permissions.IndexOf(Action) > -1 && (Path.Contains("-20") || ("," + Path + ",").Contains("," + getUser().StartNodeId.ToString() + ","))) return true; - Log.Add(LogTypes.LoginFailure, getUser(), -1, "Insufficient permissions in UmbracoEnsuredPage: '" + Path + "', '" + permissions + "', '" + Action + "'"); + var user = getUser(); + LogHelper.Info("User {0} has insufficient permissions in UmbracoEnsuredPage: '{1}', '{2}', '{3}'", () => user.Name, () => Path, () => permissions, () => Action); return false; } diff --git a/src/umbraco.businesslogic/User.cs b/src/umbraco.businesslogic/User.cs index 5e7335d03a..f064b6bd07 100644 --- a/src/umbraco.businesslogic/User.cs +++ b/src/umbraco.businesslogic/User.cs @@ -2,6 +2,7 @@ using System; using System.Data; using System.Configuration; using System.Collections; +using Umbraco.Core.Logging; using umbraco.DataLayer; using System.Collections.Generic; using System.Linq; @@ -336,7 +337,10 @@ namespace umbraco.BusinessLogic // Logging if (tmp == null) - BusinessLogic.Log.Add(BusinessLogic.LogTypes.LoginFailure, BusinessLogic.User.GetUser(0), -1, "Login: '" + lname + "' failed, from IP: " + System.Web.HttpContext.Current.Request.UserHostAddress); + { + LogHelper.Info("Login: '" + lname + "' failed, from IP: " + System.Web.HttpContext.Current.Request.UserHostAddress); + } + return (tmp != null); } diff --git a/src/umbraco.cms/businesslogic/Packager/Installer.cs b/src/umbraco.cms/businesslogic/Packager/Installer.cs index ba8419448d..62767d5a1f 100644 --- a/src/umbraco.cms/businesslogic/Packager/Installer.cs +++ b/src/umbraco.cms/businesslogic/Packager/Installer.cs @@ -458,7 +458,6 @@ namespace umbraco.cms.businesslogic.packager if (n.Attributes["undo"] == null || n.Attributes["undo"].Value == "true") { insPack.Data.Actions += n.OuterXml; - Log.Add(LogTypes.Debug, -1, HttpUtility.HtmlEncode(n.OuterXml)); } if (n.Attributes["runat"] != null && n.Attributes["runat"].Value == "install") diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/StandardPackageActions.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/StandardPackageActions.cs deleted file mode 100644 index d77f2bfe26..0000000000 --- a/src/umbraco.cms/businesslogic/Packager/PackageActions/StandardPackageActions.cs +++ /dev/null @@ -1,1073 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Xml; -using System.Linq; -using umbraco.IO; - -namespace umbraco.cms.businesslogic.packager.standardPackageActions -{ - /*Build in standard actions */ - - /// - /// This class implements the IPackageAction Interface, used to execute code when packages are installed. - /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. - /// - public class addApplicationTree : umbraco.interfaces.IPackageAction - { - - #region IPackageAction Members - - /// - /// Executes the specified package action. - /// - /// Name of the package. - /// The XML data. - /// - /// - /// - /// - public bool Execute(string packageName, XmlNode xmlData) - { - bool silent = bool.Parse(xmlData.Attributes["silent"].Value); - bool initialize = bool.Parse(xmlData.Attributes["initialize"].Value); - byte sortOrder = byte.Parse(xmlData.Attributes["sortOrder"].Value); - - string applicationAlias = xmlData.Attributes["applicationAlias"].Value; - string treeAlias = xmlData.Attributes["treeAlias"].Value; - string treeTitle = xmlData.Attributes["treeTitle"].Value; - string iconOpened = xmlData.Attributes["iconOpened"].Value; - string iconClosed = xmlData.Attributes["iconClosed"].Value; - - string assemblyName = xmlData.Attributes["assemblyName"].Value; - string type = xmlData.Attributes["treeHandlerType"].Value; - string action = xmlData.Attributes["action"].Value; - - - BusinessLogic.ApplicationTree.MakeNew(silent, initialize, sortOrder, applicationAlias, treeAlias, treeTitle, iconClosed, iconOpened, assemblyName, type, action); - - return true; - } - - /// - /// Undoes the action - /// - /// Name of the package. - /// The XML data. - /// - public bool Undo(string packageName, XmlNode xmlData) - { - string treeAlias = xmlData.Attributes["treeAlias"].Value; - BusinessLogic.ApplicationTree.getByAlias(treeAlias).Delete(); - return true; - } - - /// - /// Action alias. - /// - /// - public string Alias() - { - return "addApplicationTree"; - } - - #endregion - - - public XmlNode SampleXml() - { - - string sample = ""; - return helper.parseStringToXmlNode(sample); - } - } - - /// - /// This class implements the IPackageAction Interface, used to execute code when packages are installed. - /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. - /// - public class addApplication : umbraco.interfaces.IPackageAction - { - - #region IPackageAction Members - - /// - /// Installs a new application in umbraco. - /// - /// Name of the package. - /// The XML data. - /// - /// - /// - /// true if successfull - public bool Execute(string packageName, XmlNode xmlData) - { - string name = xmlData.Attributes["appName"].Value; - string alias = xmlData.Attributes["appAlias"].Value; - string icon = xmlData.Attributes["appIcon"].Value; - - BusinessLogic.Application.MakeNew(name, alias, icon); - - return true; - } - - public bool Undo(string packageName, XmlNode xmlData) - { - string alias = xmlData.Attributes["appAlias"].Value; - BusinessLogic.Application.getByAlias(alias).Delete(); - return true; - } - /// - /// Action alias. - /// - /// - public string Alias() - { - return "addApplication"; - } - - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } - - /// - /// - /// - public class addDashboardSection : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - /// - /// Installs a dashboard section. This action reuses the action XML, so it has to be valid dashboard markup. - /// - /// Name of the package. - /// The XML data. - /// true if successfull - /// - /// - /// - ///
- /// - /// default - /// content - /// - /// - /// /usercontrols/dashboard/latestEdits.ascx - /// /usercontrols/umbracoBlog/dashboardBlogPostCreate.ascx - /// - /// - /// /usercontrols/umbracoBlog/dashboardBlogPostCreate.ascx - /// - ///
- ///
- ///
- ///
- public bool Execute(string packageName, XmlNode xmlData) - { - //this will need a complete section node to work... - - if (xmlData.HasChildNodes) - { - string sectionAlias = xmlData.Attributes["dashboardAlias"].Value; - string dbConfig = SystemFiles.DashboardConfig; - - XmlNode section = xmlData.SelectSingleNode("./section"); - XmlDocument dashboardFile = xmlHelper.OpenAsXmlDocument(dbConfig); - - XmlNode importedSection = dashboardFile.ImportNode(section, true); - - XmlAttribute alias = xmlHelper.addAttribute(dashboardFile, "alias", sectionAlias); - importedSection.Attributes.Append(alias); - - dashboardFile.DocumentElement.AppendChild(importedSection); - - dashboardFile.Save(IOHelper.MapPath(dbConfig)); - - return true; - } - - return false; - } - - - public string Alias() - { - return "addDashboardSection"; - } - - public bool Undo(string packageName, XmlNode xmlData) - { - - string sectionAlias = xmlData.Attributes["dashboardAlias"].Value; - string dbConfig = SystemFiles.DashboardConfig; - XmlDocument dashboardFile = xmlHelper.OpenAsXmlDocument(dbConfig); - - XmlNode section = dashboardFile.SelectSingleNode("//section [@alias = '" + sectionAlias + "']"); - - if (section != null) - { - - dashboardFile.SelectSingleNode("/dashBoard").RemoveChild(section); - dashboardFile.Save(IOHelper.MapPath(dbConfig)); - } - - return true; - } - - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } - /// - /// This class implements the IPackageAction Interface, used to execute code when packages are installed. - /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. - /// - public class allowDoctype : umbraco.interfaces.IPackageAction - { - - #region IPackageAction Members - - /// - /// Allows a documentType to be created below another documentType. - /// - /// Name of the package. - /// The XML data. - /// - /// - /// - /// Returns true on success - public bool Execute(string packageName, XmlNode xmlData) - { - string doctypeName = xmlData.Attributes["documentTypeAlias"].Value; - string parentDoctypeName = xmlData.Attributes["parentDocumentTypeAlias"].Value; - - cms.businesslogic.ContentType ct = cms.businesslogic.ContentType.GetByAlias(doctypeName); - cms.businesslogic.ContentType parentct = cms.businesslogic.ContentType.GetByAlias(parentDoctypeName); - - if (ct != null && parentct != null) - { - bool containsId = false; - ArrayList tmp = new ArrayList(); - - foreach (int i in parentct.AllowedChildContentTypeIDs.ToList()) - { - tmp.Add(i); - if (i == ct.Id) - containsId = true; - } - - if (!containsId) - { - - int[] ids = new int[tmp.Count + 1]; - for (int i = 0; i < tmp.Count; i++) ids[i] = (int)tmp[i]; - ids[ids.Length - 1] = ct.Id; - - parentct.AllowedChildContentTypeIDs = ids; - parentct.Save(); - return true; - } - } - return false; - } - - //this has no undo. - /// - /// This action has no undo. - /// - /// Name of the package. - /// The XML data. - /// - public bool Undo(string packageName, XmlNode xmlData) - { - return true; - } - - /// - /// Action Alias. - /// - /// - public string Alias() - { - return "allowDocumenttype"; - } - - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } - - public class addXsltExtension : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - public bool Execute(string packageName, XmlNode xmlData) - { - - string _assembly = xmlData.Attributes["assembly"].Value; - string _type = xmlData.Attributes["type"].Value; - string _alias = xmlData.Attributes["extensionAlias"].Value; - string xeConfig = SystemFiles.XsltextensionsConfig; - - XmlDocument xdoc = new XmlDocument(); - xdoc.PreserveWhitespace = true; - xdoc = xmlHelper.OpenAsXmlDocument(xeConfig); - - XmlNode xn = xdoc.SelectSingleNode("//XsltExtensions"); - - if (xn != null) - { - bool insertExt = true; - if (xn.HasChildNodes) - { - foreach (XmlNode ext in xn.SelectNodes("//ext")) - { - if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) - insertExt = false; - } - } - if (insertExt) - { - XmlNode newExt = umbraco.xmlHelper.addTextNode(xdoc, "ext", ""); - newExt.Attributes.Append(umbraco.xmlHelper.addAttribute(xdoc, "assembly", _assembly.Replace("/bin/", ""))); - newExt.Attributes.Append(umbraco.xmlHelper.addAttribute(xdoc, "type", _type)); - newExt.Attributes.Append(umbraco.xmlHelper.addAttribute(xdoc, "alias", _alias)); - xn.AppendChild(newExt); - - - xdoc.Save(IOHelper.MapPath(xeConfig)); - return true; - } - } - return false; - } - - public string Alias() - { - return "addXsltExtension"; - } - - public bool Undo(string packageName, XmlNode xmlData) - { - string _assembly = xmlData.Attributes["assembly"].Value; - string _type = xmlData.Attributes["type"].Value; - string _alias = xmlData.Attributes["extensionAlias"].Value; - string xeConfig = SystemFiles.XsltextensionsConfig; - - XmlDocument xdoc = new XmlDocument(); - xdoc.PreserveWhitespace = true; - xdoc = xmlHelper.OpenAsXmlDocument(xeConfig); - - XmlNode xn = xdoc.SelectSingleNode("//XsltExtensions"); - - if (xn != null) - { - bool inserted = false; - if (xn.HasChildNodes) - { - foreach (XmlNode ext in xn.SelectNodes("//ext")) - { - if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) - { - xn.RemoveChild(ext); - inserted = true; - } - } - } - - if (inserted) - { - xdoc.Save(IOHelper.MapPath(xeConfig)); - return true; - } - } - return false; - } - - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } - - public class addRestExtension : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - public bool Execute(string packageName, XmlNode xmlData) - { - - XmlNodeList _newExts = xmlData.SelectNodes("//ext"); - - if (_newExts.Count > 0) - { - - string reConfig = SystemFiles.RestextensionsConfig; - - XmlDocument xdoc = new XmlDocument(); - xdoc.PreserveWhitespace = true; - xdoc = xmlHelper.OpenAsXmlDocument(reConfig); - - - XmlNode xn = xdoc.SelectSingleNode("//RestExtensions"); - - if (xn != null) - { - for (int i = 0; i < _newExts.Count; i++) - { - XmlNode newExt = _newExts[i]; - string _alias = newExt.Attributes["alias"].Value; - - bool insertExt = true; - if (xn.HasChildNodes) - { - foreach (XmlNode ext in xn.SelectNodes("//ext")) - { - if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) - insertExt = false; - } - } - - if (insertExt) - { - xn.AppendChild(xdoc.ImportNode(newExt, true)); - } - } - - xdoc.Save(IOHelper.MapPath(reConfig)); - return true; - } - } - return false; - } - - public string Alias() - { - return "addRestExtension"; - } - - public bool Undo(string packageName, XmlNode xmlData) - { - - XmlNodeList _newExts = xmlData.SelectNodes("//ext"); - - if (_newExts.Count > 0) - { - string reConfig = SystemFiles.RestextensionsConfig; - - XmlDocument xdoc = new XmlDocument(); - xdoc.PreserveWhitespace = true; - xdoc.Load(reConfig); - - XmlNode xn = xdoc.SelectSingleNode("//RestExtensions"); - - if (xn != null) - { - bool inserted = false; - - for (int i = 0; i < _newExts.Count; i++) - { - XmlNode newExt = _newExts[i]; - string _alias = newExt.Attributes["alias"].Value; - if (xn.HasChildNodes) - { - foreach (XmlNode ext in xn.SelectNodes("//ext")) - { - if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) - { - xn.RemoveChild(ext); - inserted = true; - } - } - } - } - - if (inserted) - { - xdoc.Save(IOHelper.MapPath(reConfig)); - return true; - } - } - } - return false; - } - - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } - - public class addProxyFeedHost : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - public bool Execute(string packageName, XmlNode xmlData) - { - var hostname = xmlData.Attributes["host"].Value; - if (string.IsNullOrEmpty(hostname)) - return false; - - var xdoc = xmlHelper.OpenAsXmlDocument(SystemFiles.FeedProxyConfig); - - xdoc.PreserveWhitespace = true; - - var xn = xdoc.SelectSingleNode("//feedProxy"); - if (xn != null) - { - var insert = true; - - if (xn.HasChildNodes) - { - foreach (XmlNode node in xn.SelectNodes("//allow")) - { - if (node.Attributes["host"] != null && node.Attributes["host"].Value == hostname) - insert = false; - } - } - - if (insert) - { - var newHostname = xmlHelper.addTextNode(xdoc, "allow", string.Empty); - newHostname.Attributes.Append(xmlHelper.addAttribute(xdoc, "host", hostname)); - xn.AppendChild(newHostname); - - xdoc.Save(IOHelper.MapPath(SystemFiles.FeedProxyConfig)); - - return true; - } - } - - return false; - } - - public string Alias() - { - return "addProxyFeedHost"; - } - - public bool Undo(string packageName, XmlNode xmlData) - { - var hostname = xmlData.Attributes["host"].Value; - if (string.IsNullOrEmpty(hostname)) - return false; - - var xdoc = xmlHelper.OpenAsXmlDocument(SystemFiles.FeedProxyConfig); - xdoc.PreserveWhitespace = true; - - var xn = xdoc.SelectSingleNode("//feedProxy"); - if (xn != null) - { - bool inserted = false; - if (xn.HasChildNodes) - { - foreach (XmlNode node in xn.SelectNodes("//allow")) - { - if (node.Attributes["host"] != null && node.Attributes["host"].Value == hostname) - { - xn.RemoveChild(node); - inserted = true; - } - } - } - - if (inserted) - { - xdoc.Save(IOHelper.MapPath(SystemFiles.FeedProxyConfig)); - return true; - } - } - - return false; - } - - #endregion - - public XmlNode SampleXml() - { - string sample = ""; - return helper.parseStringToXmlNode(sample); - } - } - - /// - /// This class implements the IPackageAction Interface, used to execute code when packages are installed. - /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. - /// - public class moveRootDocument : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - /// - /// Executes the specified package action. - /// - /// Name of the package. - /// The XML data. - /// - /// - /// - /// True if executed succesfully - public bool Execute(string packageName, XmlNode xmlData) - { - - string documentName = xmlData.Attributes["documentName"].Value; - string parentDocumentType = xmlData.Attributes["parentDocumentType"].Value; - string parentDocumentName = ""; - - if (xmlData.Attributes["parentDocumentName"] != null) - parentDocumentName = xmlData.Attributes["parentDocumentName"].Value; - - int parentDocid = 0; - - ContentType ct = ContentType.GetByAlias(parentDocumentType); - Content[] docs = web.Document.getContentOfContentType(ct); - - if (docs.Length > 0) - { - if (String.IsNullOrEmpty(parentDocumentName)) - parentDocid = docs[0].Id; - else - { - foreach (Content doc in docs) - { - if (doc.Text == parentDocumentName) - parentDocid = doc.Id; - } - } - } - - if (parentDocid > 0) - { - web.Document[] rootDocs = web.Document.GetRootDocuments(); - - foreach (web.Document rootDoc in rootDocs) - { - if (rootDoc.Text == documentName) - { - rootDoc.Move(parentDocid); - rootDoc.PublishWithSubs(new umbraco.BusinessLogic.User(0)); - } - } - } - - - return true; - } - - //this has no undo. - /// - /// This action has no undo. - /// - /// Name of the package. - /// The XML data. - /// - public bool Undo(string packageName, XmlNode xmlData) - { - return true; - } - - /// - /// Action alias - /// - /// - public string Alias() - { - return "moveRootDocument"; - } - - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } - - /// - /// This class implements the IPackageAction Interface, used to execute code when packages are installed. - /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. - /// - public class publishRootDocument : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - /// - /// Executes the specified package action. - /// - /// Name of the package. - /// The XML data. - /// - /// - /// - /// True if executed succesfully - public bool Execute(string packageName, XmlNode xmlData) - { - - string documentName = xmlData.Attributes["documentName"].Value; - - int parentDocid = 0; - - web.Document[] rootDocs = web.Document.GetRootDocuments(); - - foreach (web.Document rootDoc in rootDocs) - { - if (rootDoc.Text.Trim() == documentName.Trim() && rootDoc != null && rootDoc.ContentType != null) - { - - rootDoc.PublishWithChildrenWithResult(umbraco.BusinessLogic.User.GetUser(0)); - - - break; - } - } - return true; - } - - //this has no undo. - /// - /// This action has no undo. - /// - /// Name of the package. - /// The XML data. - /// - public bool Undo(string packageName, XmlNode xmlData) - { - return true; - } - - /// - /// Action alias - /// - /// - public string Alias() - { - return "publishRootDocument"; - } - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } - - /// - /// This class implements the IPackageAction Interface, used to execute code when packages are installed. - /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. - /// addStringToHtmlElement adds a string to specific HTML element in a specific template, and can either append or prepend it. - /// It uses the action xml node to do this, exemple action xml node: - /// - /// The above will add the string "hello world!" to the first html element with the id "newsSection" in the template "news" - /// - public class addStringToHtmlElement : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - /// - /// Executes the specified package action. - /// - /// Name of the package. - /// The XML data. - /// - /// - /// - /// True if executed successfully - public bool Execute(string packageName, XmlNode xmlData) - { - - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "executing addStringToHtmlElement"); - - string templateAlias = xmlData.Attributes["templateAlias"].Value; - string htmlElementId = xmlData.Attributes["htmlElementId"].Value; - string position = xmlData.Attributes["position"].Value; - string value = xmlHelper.GetNodeValue(xmlData); - template.Template tmp = template.Template.GetByAlias(templateAlias); - - if (UmbracoSettings.UseAspNetMasterPages) - value = tmp.EnsureMasterPageSyntax(value); - - _addStringToHtmlElement(tmp, value, templateAlias, htmlElementId, position); - - return true; - } - - - /// - /// Undoes the addStringToHtml Execute() method, by removing the same string from the same template. - /// - /// Name of the package. - /// The XML data. - /// - public bool Undo(string packageName, XmlNode xmlData) - { - string templateAlias = xmlData.Attributes["templateAlias"].Value; - string htmlElementId = xmlData.Attributes["htmlElementId"].Value; - string value = xmlHelper.GetNodeValue(xmlData); - template.Template tmp = template.Template.GetByAlias(templateAlias); - - if (UmbracoSettings.UseAspNetMasterPages) - value = tmp.EnsureMasterPageSyntax(value); - - _removeStringFromHtmlElement(tmp, value, templateAlias, htmlElementId); - return true; - } - - /// - /// Action alias. - /// - /// - public string Alias() - { - return "addStringToHtmlElement"; - } - - private void _addStringToHtmlElement(template.Template tmp, string value, string templateAlias, string htmlElementId, string position) - { - bool hasAspNetContentBeginning = false; - string design = ""; - string directive = ""; - - if (tmp != null) - { - try - { - XmlDocument templateXml = new XmlDocument(); - templateXml.PreserveWhitespace = true; - - //Make sure that directive is remove before hacked non html4 compatiple replacement action... - design = tmp.Design; - - - splitDesignAndDirective(ref design, ref directive); - - //making sure that the template xml has a root node... - if (tmp.MasterTemplate > 0) - templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, "" + design + "", true)); - else - templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, design, true)); - - XmlNode xmlElement = templateXml.SelectSingleNode("//* [@id = '" + htmlElementId + "']"); - - if (xmlElement != null) - { - - if (position == "beginning") - { - xmlElement.InnerXml = "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true) + "\n" + xmlElement.InnerXml; - } - else - { - xmlElement.InnerXml = xmlElement.InnerXml + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true) + "\n"; - } - } - - tmp.Design = directive + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, templateXml.OuterXml, false); - tmp.Save(); - } - catch (Exception ex) - { - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString()); - } - } - else - { - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "template not found"); - } - } - - private void _removeStringFromHtmlElement(template.Template tmp, string value, string templateAlias, string htmlElementId) - { - bool hasAspNetContentBeginning = false; - string design = ""; - string directive = ""; - - - if (tmp != null) - { - try - { - XmlDocument templateXml = new XmlDocument(); - templateXml.PreserveWhitespace = true; - - //Make sure that directive is remove before hacked non html4 compatiple replacement action... - design = tmp.Design; - splitDesignAndDirective(ref design, ref directive); - - //making sure that the template xml has a root node... - if (tmp.MasterTemplate > 0) - templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, "" + design + "", true)); - else - templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, design, true)); - - XmlNode xmlElement = templateXml.SelectSingleNode("//* [@id = '" + htmlElementId + "']"); - - - - if (xmlElement != null) - { - string repValue = helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true); - xmlElement.InnerXml = xmlElement.InnerXml.Replace(repValue, ""); - } - - tmp.Design = directive + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, templateXml.OuterXml, false); - tmp.Save(); - } - catch (Exception ex) - { - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString()); - } - } - else - { - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "template not found"); - } - } - - - - private void splitDesignAndDirective(ref string design, ref string directive) - { - if (design.StartsWith("<%@")) - { - directive = design.Substring(0, design.IndexOf("%>") + 2).Trim(Environment.NewLine.ToCharArray()); - design = design.Substring(design.IndexOf("%>") + 3).Trim(Environment.NewLine.ToCharArray()); - } - } - - #endregion - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - } - - public class removeStringFromTemplate : umbraco.interfaces.IPackageAction - { - #region IPackageAction Members - - public bool Execute(string packageName, XmlNode xmlData) - { - addStringToHtmlElement ast = new addStringToHtmlElement(); - return ast.Undo(packageName, xmlData); - } - - public string Alias() - { - return "removeStringFromHtmlElement"; - } - - public bool Undo(string packageName, XmlNode xmlData) - { - return true; - } - - public XmlNode SampleXml() - { - throw new NotImplementedException(); - } - - #endregion - } - - - public class helper - { - //Helper method to replace umbraco tags that breaks the xml format.. - public static string parseToValidXml(template.Template templateObj, ref bool hasAspNetContentBeginning, string template, bool toValid) - { - string retVal = template; - if (toValid) - { - // test for asp:content as the first part of the design - if (retVal.StartsWith("") + 1); - retVal = retVal.Substring(0, retVal.Length - 14); - } - //shorten empty macro tags.. - retVal = retVal.Replace(">", " />"); - retVal = retVal.Replace(">", " />"); - - retVal = retVal.Replace("", ""); - retVal = retVal.Replace("", ""); - retVal = retVal.Replace("", ""); - - // add asp content element - if (hasAspNetContentBeginning) - { - retVal = templateObj.GetMasterContentElement(templateObj.MasterTemplate) + retVal + ""; - } - } - - return retVal; - } - - public static XmlNode parseStringToXmlNode(string value) - { - XmlDocument doc = new XmlDocument(); - XmlNode node = xmlHelper.addTextNode(doc, "error", ""); - - try - { - doc.LoadXml(value); - return doc.SelectSingleNode("."); - } - catch - { - return node; - } - - } - } -} diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/addApplication.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/addApplication.cs new file mode 100644 index 0000000000..3f5b08e35b --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/addApplication.cs @@ -0,0 +1,58 @@ +using System; +using System.Xml; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + /// + /// This class implements the IPackageAction Interface, used to execute code when packages are installed. + /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. + /// + public class addApplication : umbraco.interfaces.IPackageAction + { + + #region IPackageAction Members + + /// + /// Installs a new application in umbraco. + /// + /// Name of the package. + /// The XML data. + /// + /// + /// + /// true if successfull + public bool Execute(string packageName, XmlNode xmlData) + { + string name = xmlData.Attributes["appName"].Value; + string alias = xmlData.Attributes["appAlias"].Value; + string icon = xmlData.Attributes["appIcon"].Value; + + BusinessLogic.Application.MakeNew(name, alias, icon); + + return true; + } + + public bool Undo(string packageName, XmlNode xmlData) + { + string alias = xmlData.Attributes["appAlias"].Value; + BusinessLogic.Application.getByAlias(alias).Delete(); + return true; + } + /// + /// Action alias. + /// + /// + public string Alias() + { + return "addApplication"; + } + + #endregion + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/addApplicationTree.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/addApplicationTree.cs new file mode 100644 index 0000000000..6d6d3db6cf --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/addApplicationTree.cs @@ -0,0 +1,83 @@ +using System.Collections.Generic; +using System.Text; +using System.Xml; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + /*Build in standard actions */ + + /// + /// This class implements the IPackageAction Interface, used to execute code when packages are installed. + /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. + /// + public class addApplicationTree : umbraco.interfaces.IPackageAction + { + + #region IPackageAction Members + + /// + /// Executes the specified package action. + /// + /// Name of the package. + /// The XML data. + /// + /// + /// + /// + public bool Execute(string packageName, XmlNode xmlData) + { + bool silent = bool.Parse(xmlData.Attributes["silent"].Value); + bool initialize = bool.Parse(xmlData.Attributes["initialize"].Value); + byte sortOrder = byte.Parse(xmlData.Attributes["sortOrder"].Value); + + string applicationAlias = xmlData.Attributes["applicationAlias"].Value; + string treeAlias = xmlData.Attributes["treeAlias"].Value; + string treeTitle = xmlData.Attributes["treeTitle"].Value; + string iconOpened = xmlData.Attributes["iconOpened"].Value; + string iconClosed = xmlData.Attributes["iconClosed"].Value; + + string assemblyName = xmlData.Attributes["assemblyName"].Value; + string type = xmlData.Attributes["treeHandlerType"].Value; + string action = xmlData.Attributes["action"].Value; + + + BusinessLogic.ApplicationTree.MakeNew(silent, initialize, sortOrder, applicationAlias, treeAlias, treeTitle, iconClosed, iconOpened, assemblyName, type, action); + + return true; + } + + /// + /// Undoes the action + /// + /// Name of the package. + /// The XML data. + /// + public bool Undo(string packageName, XmlNode xmlData) + { + string treeAlias = xmlData.Attributes["treeAlias"].Value; + BusinessLogic.ApplicationTree.getByAlias(treeAlias).Delete(); + return true; + } + + /// + /// Action alias. + /// + /// + public string Alias() + { + return "addApplicationTree"; + } + + #endregion + + + public XmlNode SampleXml() + { + + string sample = ""; + return helper.parseStringToXmlNode(sample); + } + } +} diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/addDashboardSection.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/addDashboardSection.cs new file mode 100644 index 0000000000..70cf3070e7 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/addDashboardSection.cs @@ -0,0 +1,99 @@ +using System; +using System.Xml; +using umbraco.IO; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + /// + /// + /// + public class addDashboardSection : umbraco.interfaces.IPackageAction + { + #region IPackageAction Members + + /// + /// Installs a dashboard section. This action reuses the action XML, so it has to be valid dashboard markup. + /// + /// Name of the package. + /// The XML data. + /// true if successfull + /// + /// + /// + ///
+ /// + /// default + /// content + /// + /// + /// /usercontrols/dashboard/latestEdits.ascx + /// /usercontrols/umbracoBlog/dashboardBlogPostCreate.ascx + /// + /// + /// /usercontrols/umbracoBlog/dashboardBlogPostCreate.ascx + /// + ///
+ ///
+ ///
+ ///
+ public bool Execute(string packageName, XmlNode xmlData) + { + //this will need a complete section node to work... + + if (xmlData.HasChildNodes) + { + string sectionAlias = xmlData.Attributes["dashboardAlias"].Value; + string dbConfig = SystemFiles.DashboardConfig; + + XmlNode section = xmlData.SelectSingleNode("./section"); + XmlDocument dashboardFile = xmlHelper.OpenAsXmlDocument(dbConfig); + + XmlNode importedSection = dashboardFile.ImportNode(section, true); + + XmlAttribute alias = xmlHelper.addAttribute(dashboardFile, "alias", sectionAlias); + importedSection.Attributes.Append(alias); + + dashboardFile.DocumentElement.AppendChild(importedSection); + + dashboardFile.Save(IOHelper.MapPath(dbConfig)); + + return true; + } + + return false; + } + + + public string Alias() + { + return "addDashboardSection"; + } + + public bool Undo(string packageName, XmlNode xmlData) + { + + string sectionAlias = xmlData.Attributes["dashboardAlias"].Value; + string dbConfig = SystemFiles.DashboardConfig; + XmlDocument dashboardFile = xmlHelper.OpenAsXmlDocument(dbConfig); + + XmlNode section = dashboardFile.SelectSingleNode("//section [@alias = '" + sectionAlias + "']"); + + if (section != null) + { + + dashboardFile.SelectSingleNode("/dashBoard").RemoveChild(section); + dashboardFile.Save(IOHelper.MapPath(dbConfig)); + } + + return true; + } + + #endregion + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/addProxyFeedHost.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/addProxyFeedHost.cs new file mode 100644 index 0000000000..113ef2e014 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/addProxyFeedHost.cs @@ -0,0 +1,97 @@ +using System.Xml; +using umbraco.IO; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + public class addProxyFeedHost : umbraco.interfaces.IPackageAction + { + #region IPackageAction Members + + public bool Execute(string packageName, XmlNode xmlData) + { + var hostname = xmlData.Attributes["host"].Value; + if (string.IsNullOrEmpty(hostname)) + return false; + + var xdoc = xmlHelper.OpenAsXmlDocument(SystemFiles.FeedProxyConfig); + + xdoc.PreserveWhitespace = true; + + var xn = xdoc.SelectSingleNode("//feedProxy"); + if (xn != null) + { + var insert = true; + + if (xn.HasChildNodes) + { + foreach (XmlNode node in xn.SelectNodes("//allow")) + { + if (node.Attributes["host"] != null && node.Attributes["host"].Value == hostname) + insert = false; + } + } + + if (insert) + { + var newHostname = xmlHelper.addTextNode(xdoc, "allow", string.Empty); + newHostname.Attributes.Append(xmlHelper.addAttribute(xdoc, "host", hostname)); + xn.AppendChild(newHostname); + + xdoc.Save(IOHelper.MapPath(SystemFiles.FeedProxyConfig)); + + return true; + } + } + + return false; + } + + public string Alias() + { + return "addProxyFeedHost"; + } + + public bool Undo(string packageName, XmlNode xmlData) + { + var hostname = xmlData.Attributes["host"].Value; + if (string.IsNullOrEmpty(hostname)) + return false; + + var xdoc = xmlHelper.OpenAsXmlDocument(SystemFiles.FeedProxyConfig); + xdoc.PreserveWhitespace = true; + + var xn = xdoc.SelectSingleNode("//feedProxy"); + if (xn != null) + { + bool inserted = false; + if (xn.HasChildNodes) + { + foreach (XmlNode node in xn.SelectNodes("//allow")) + { + if (node.Attributes["host"] != null && node.Attributes["host"].Value == hostname) + { + xn.RemoveChild(node); + inserted = true; + } + } + } + + if (inserted) + { + xdoc.Save(IOHelper.MapPath(SystemFiles.FeedProxyConfig)); + return true; + } + } + + return false; + } + + #endregion + + public XmlNode SampleXml() + { + string sample = ""; + return helper.parseStringToXmlNode(sample); + } + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/addRestExtension.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/addRestExtension.cs new file mode 100644 index 0000000000..f77fdad206 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/addRestExtension.cs @@ -0,0 +1,117 @@ +using System; +using System.Xml; +using umbraco.IO; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + public class addRestExtension : umbraco.interfaces.IPackageAction + { + #region IPackageAction Members + + public bool Execute(string packageName, XmlNode xmlData) + { + + XmlNodeList _newExts = xmlData.SelectNodes("//ext"); + + if (_newExts.Count > 0) + { + + string reConfig = SystemFiles.RestextensionsConfig; + + XmlDocument xdoc = new XmlDocument(); + xdoc.PreserveWhitespace = true; + xdoc = xmlHelper.OpenAsXmlDocument(reConfig); + + + XmlNode xn = xdoc.SelectSingleNode("//RestExtensions"); + + if (xn != null) + { + for (int i = 0; i < _newExts.Count; i++) + { + XmlNode newExt = _newExts[i]; + string _alias = newExt.Attributes["alias"].Value; + + bool insertExt = true; + if (xn.HasChildNodes) + { + foreach (XmlNode ext in xn.SelectNodes("//ext")) + { + if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) + insertExt = false; + } + } + + if (insertExt) + { + xn.AppendChild(xdoc.ImportNode(newExt, true)); + } + } + + xdoc.Save(IOHelper.MapPath(reConfig)); + return true; + } + } + return false; + } + + public string Alias() + { + return "addRestExtension"; + } + + public bool Undo(string packageName, XmlNode xmlData) + { + + XmlNodeList _newExts = xmlData.SelectNodes("//ext"); + + if (_newExts.Count > 0) + { + string reConfig = SystemFiles.RestextensionsConfig; + + XmlDocument xdoc = new XmlDocument(); + xdoc.PreserveWhitespace = true; + xdoc.Load(reConfig); + + XmlNode xn = xdoc.SelectSingleNode("//RestExtensions"); + + if (xn != null) + { + bool inserted = false; + + for (int i = 0; i < _newExts.Count; i++) + { + XmlNode newExt = _newExts[i]; + string _alias = newExt.Attributes["alias"].Value; + if (xn.HasChildNodes) + { + foreach (XmlNode ext in xn.SelectNodes("//ext")) + { + if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) + { + xn.RemoveChild(ext); + inserted = true; + } + } + } + } + + if (inserted) + { + xdoc.Save(IOHelper.MapPath(reConfig)); + return true; + } + } + } + return false; + } + + #endregion + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/addStringToHtmlElement.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/addStringToHtmlElement.cs new file mode 100644 index 0000000000..4c17824945 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/addStringToHtmlElement.cs @@ -0,0 +1,198 @@ +using System; +using System.Xml; +using Umbraco.Core.Logging; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + /// + /// This class implements the IPackageAction Interface, used to execute code when packages are installed. + /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. + /// addStringToHtmlElement adds a string to specific HTML element in a specific template, and can either append or prepend it. + /// It uses the action xml node to do this, exemple action xml node: + /// + /// The above will add the string "hello world!" to the first html element with the id "newsSection" in the template "news" + /// + public class addStringToHtmlElement : umbraco.interfaces.IPackageAction + { + #region IPackageAction Members + + /// + /// Executes the specified package action. + /// + /// Name of the package. + /// The XML data. + /// + /// + /// + /// True if executed successfully + public bool Execute(string packageName, XmlNode xmlData) + { + + BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "executing addStringToHtmlElement"); + + string templateAlias = xmlData.Attributes["templateAlias"].Value; + string htmlElementId = xmlData.Attributes["htmlElementId"].Value; + string position = xmlData.Attributes["position"].Value; + string value = xmlHelper.GetNodeValue(xmlData); + template.Template tmp = template.Template.GetByAlias(templateAlias); + + if (UmbracoSettings.UseAspNetMasterPages) + value = tmp.EnsureMasterPageSyntax(value); + + _addStringToHtmlElement(tmp, value, templateAlias, htmlElementId, position); + + return true; + } + + + /// + /// Undoes the addStringToHtml Execute() method, by removing the same string from the same template. + /// + /// Name of the package. + /// The XML data. + /// + public bool Undo(string packageName, XmlNode xmlData) + { + string templateAlias = xmlData.Attributes["templateAlias"].Value; + string htmlElementId = xmlData.Attributes["htmlElementId"].Value; + string value = xmlHelper.GetNodeValue(xmlData); + template.Template tmp = template.Template.GetByAlias(templateAlias); + + if (UmbracoSettings.UseAspNetMasterPages) + value = tmp.EnsureMasterPageSyntax(value); + + _removeStringFromHtmlElement(tmp, value, templateAlias, htmlElementId); + return true; + } + + /// + /// Action alias. + /// + /// + public string Alias() + { + return "addStringToHtmlElement"; + } + + private void _addStringToHtmlElement(template.Template tmp, string value, string templateAlias, string htmlElementId, string position) + { + bool hasAspNetContentBeginning = false; + string design = ""; + string directive = ""; + + if (tmp != null) + { + try + { + XmlDocument templateXml = new XmlDocument(); + templateXml.PreserveWhitespace = true; + + //Make sure that directive is remove before hacked non html4 compatiple replacement action... + design = tmp.Design; + + + splitDesignAndDirective(ref design, ref directive); + + //making sure that the template xml has a root node... + if (tmp.MasterTemplate > 0) + templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, "" + design + "", true)); + else + templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, design, true)); + + XmlNode xmlElement = templateXml.SelectSingleNode("//* [@id = '" + htmlElementId + "']"); + + if (xmlElement != null) + { + + if (position == "beginning") + { + xmlElement.InnerXml = "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true) + "\n" + xmlElement.InnerXml; + } + else + { + xmlElement.InnerXml = xmlElement.InnerXml + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true) + "\n"; + } + } + + tmp.Design = directive + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, templateXml.OuterXml, false); + tmp.Save(); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred", ex); + } + } + else + { + LogHelper.Debug("template not found"); + } + } + + private void _removeStringFromHtmlElement(template.Template tmp, string value, string templateAlias, string htmlElementId) + { + bool hasAspNetContentBeginning = false; + string design = ""; + string directive = ""; + + + if (tmp != null) + { + try + { + XmlDocument templateXml = new XmlDocument(); + templateXml.PreserveWhitespace = true; + + //Make sure that directive is remove before hacked non html4 compatiple replacement action... + design = tmp.Design; + splitDesignAndDirective(ref design, ref directive); + + //making sure that the template xml has a root node... + if (tmp.MasterTemplate > 0) + templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, "" + design + "", true)); + else + templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, design, true)); + + XmlNode xmlElement = templateXml.SelectSingleNode("//* [@id = '" + htmlElementId + "']"); + + + + if (xmlElement != null) + { + string repValue = helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true); + xmlElement.InnerXml = xmlElement.InnerXml.Replace(repValue, ""); + } + + tmp.Design = directive + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, templateXml.OuterXml, false); + tmp.Save(); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred", ex); + } + } + else + { + LogHelper.Debug("template not found"); + } + } + + + + private void splitDesignAndDirective(ref string design, ref string directive) + { + if (design.StartsWith("<%@")) + { + directive = design.Substring(0, design.IndexOf("%>") + 2).Trim(Environment.NewLine.ToCharArray()); + design = design.Substring(design.IndexOf("%>") + 3).Trim(Environment.NewLine.ToCharArray()); + } + } + + #endregion + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/addXsltExtension.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/addXsltExtension.cs new file mode 100644 index 0000000000..848c3cf832 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/addXsltExtension.cs @@ -0,0 +1,102 @@ +using System; +using System.Xml; +using umbraco.IO; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + public class addXsltExtension : umbraco.interfaces.IPackageAction + { + #region IPackageAction Members + + public bool Execute(string packageName, XmlNode xmlData) + { + + string _assembly = xmlData.Attributes["assembly"].Value; + string _type = xmlData.Attributes["type"].Value; + string _alias = xmlData.Attributes["extensionAlias"].Value; + string xeConfig = SystemFiles.XsltextensionsConfig; + + XmlDocument xdoc = new XmlDocument(); + xdoc.PreserveWhitespace = true; + xdoc = xmlHelper.OpenAsXmlDocument(xeConfig); + + XmlNode xn = xdoc.SelectSingleNode("//XsltExtensions"); + + if (xn != null) + { + bool insertExt = true; + if (xn.HasChildNodes) + { + foreach (XmlNode ext in xn.SelectNodes("//ext")) + { + if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) + insertExt = false; + } + } + if (insertExt) + { + XmlNode newExt = umbraco.xmlHelper.addTextNode(xdoc, "ext", ""); + newExt.Attributes.Append(umbraco.xmlHelper.addAttribute(xdoc, "assembly", _assembly.Replace("/bin/", ""))); + newExt.Attributes.Append(umbraco.xmlHelper.addAttribute(xdoc, "type", _type)); + newExt.Attributes.Append(umbraco.xmlHelper.addAttribute(xdoc, "alias", _alias)); + xn.AppendChild(newExt); + + + xdoc.Save(IOHelper.MapPath(xeConfig)); + return true; + } + } + return false; + } + + public string Alias() + { + return "addXsltExtension"; + } + + public bool Undo(string packageName, XmlNode xmlData) + { + string _assembly = xmlData.Attributes["assembly"].Value; + string _type = xmlData.Attributes["type"].Value; + string _alias = xmlData.Attributes["extensionAlias"].Value; + string xeConfig = SystemFiles.XsltextensionsConfig; + + XmlDocument xdoc = new XmlDocument(); + xdoc.PreserveWhitespace = true; + xdoc = xmlHelper.OpenAsXmlDocument(xeConfig); + + XmlNode xn = xdoc.SelectSingleNode("//XsltExtensions"); + + if (xn != null) + { + bool inserted = false; + if (xn.HasChildNodes) + { + foreach (XmlNode ext in xn.SelectNodes("//ext")) + { + if (ext.Attributes["alias"] != null && ext.Attributes["alias"].Value == _alias) + { + xn.RemoveChild(ext); + inserted = true; + } + } + } + + if (inserted) + { + xdoc.Save(IOHelper.MapPath(xeConfig)); + return true; + } + } + return false; + } + + #endregion + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/allowDoctype.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/allowDoctype.cs new file mode 100644 index 0000000000..d15b6bfb37 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/allowDoctype.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections; +using System.Linq; +using System.Xml; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + /// + /// This class implements the IPackageAction Interface, used to execute code when packages are installed. + /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. + /// + public class allowDoctype : umbraco.interfaces.IPackageAction + { + + #region IPackageAction Members + + /// + /// Allows a documentType to be created below another documentType. + /// + /// Name of the package. + /// The XML data. + /// + /// + /// + /// Returns true on success + public bool Execute(string packageName, XmlNode xmlData) + { + string doctypeName = xmlData.Attributes["documentTypeAlias"].Value; + string parentDoctypeName = xmlData.Attributes["parentDocumentTypeAlias"].Value; + + cms.businesslogic.ContentType ct = cms.businesslogic.ContentType.GetByAlias(doctypeName); + cms.businesslogic.ContentType parentct = cms.businesslogic.ContentType.GetByAlias(parentDoctypeName); + + if (ct != null && parentct != null) + { + bool containsId = false; + ArrayList tmp = new ArrayList(); + + foreach (int i in parentct.AllowedChildContentTypeIDs.ToList()) + { + tmp.Add(i); + if (i == ct.Id) + containsId = true; + } + + if (!containsId) + { + + int[] ids = new int[tmp.Count + 1]; + for (int i = 0; i < tmp.Count; i++) ids[i] = (int)tmp[i]; + ids[ids.Length - 1] = ct.Id; + + parentct.AllowedChildContentTypeIDs = ids; + parentct.Save(); + return true; + } + } + return false; + } + + //this has no undo. + /// + /// This action has no undo. + /// + /// Name of the package. + /// The XML data. + /// + public bool Undo(string packageName, XmlNode xmlData) + { + return true; + } + + /// + /// Action Alias. + /// + /// + public string Alias() + { + return "allowDocumenttype"; + } + + #endregion + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/helper.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/helper.cs new file mode 100644 index 0000000000..fedb99f93e --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/helper.cs @@ -0,0 +1,80 @@ +using System; +using System.Xml; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + public class helper + { + //Helper method to replace umbraco tags that breaks the xml format.. + public static string parseToValidXml(template.Template templateObj, ref bool hasAspNetContentBeginning, string template, bool toValid) + { + string retVal = template; + if (toValid) + { + // test for asp:content as the first part of the design + if (retVal.StartsWith("") + 1); + retVal = retVal.Substring(0, retVal.Length - 14); + } + //shorten empty macro tags.. + retVal = retVal.Replace(">", " />"); + retVal = retVal.Replace(">", " />"); + + retVal = retVal.Replace("", ""); + retVal = retVal.Replace("", ""); + retVal = retVal.Replace("", ""); + + // add asp content element + if (hasAspNetContentBeginning) + { + retVal = templateObj.GetMasterContentElement(templateObj.MasterTemplate) + retVal + ""; + } + } + + return retVal; + } + + public static XmlNode parseStringToXmlNode(string value) + { + XmlDocument doc = new XmlDocument(); + XmlNode node = xmlHelper.addTextNode(doc, "error", ""); + + try + { + doc.LoadXml(value); + return doc.SelectSingleNode("."); + } + catch + { + return node; + } + + } + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/moveRootDocument.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/moveRootDocument.cs new file mode 100644 index 0000000000..bd63920073 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/moveRootDocument.cs @@ -0,0 +1,99 @@ +using System; +using System.Xml; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + /// + /// This class implements the IPackageAction Interface, used to execute code when packages are installed. + /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. + /// + public class moveRootDocument : umbraco.interfaces.IPackageAction + { + #region IPackageAction Members + + /// + /// Executes the specified package action. + /// + /// Name of the package. + /// The XML data. + /// + /// + /// + /// True if executed succesfully + public bool Execute(string packageName, XmlNode xmlData) + { + + string documentName = xmlData.Attributes["documentName"].Value; + string parentDocumentType = xmlData.Attributes["parentDocumentType"].Value; + string parentDocumentName = ""; + + if (xmlData.Attributes["parentDocumentName"] != null) + parentDocumentName = xmlData.Attributes["parentDocumentName"].Value; + + int parentDocid = 0; + + ContentType ct = ContentType.GetByAlias(parentDocumentType); + Content[] docs = web.Document.getContentOfContentType(ct); + + if (docs.Length > 0) + { + if (String.IsNullOrEmpty(parentDocumentName)) + parentDocid = docs[0].Id; + else + { + foreach (Content doc in docs) + { + if (doc.Text == parentDocumentName) + parentDocid = doc.Id; + } + } + } + + if (parentDocid > 0) + { + web.Document[] rootDocs = web.Document.GetRootDocuments(); + + foreach (web.Document rootDoc in rootDocs) + { + if (rootDoc.Text == documentName) + { + rootDoc.Move(parentDocid); + rootDoc.PublishWithSubs(new umbraco.BusinessLogic.User(0)); + } + } + } + + + return true; + } + + //this has no undo. + /// + /// This action has no undo. + /// + /// Name of the package. + /// The XML data. + /// + public bool Undo(string packageName, XmlNode xmlData) + { + return true; + } + + /// + /// Action alias + /// + /// + public string Alias() + { + return "moveRootDocument"; + } + + #endregion + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/publishRootDocument.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/publishRootDocument.cs new file mode 100644 index 0000000000..7bc48d3e05 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/publishRootDocument.cs @@ -0,0 +1,74 @@ +using System; +using System.Xml; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + /// + /// This class implements the IPackageAction Interface, used to execute code when packages are installed. + /// All IPackageActions only takes a PackageName and a XmlNode as input, and executes based on the data in the xmlnode. + /// + public class publishRootDocument : umbraco.interfaces.IPackageAction + { + #region IPackageAction Members + + /// + /// Executes the specified package action. + /// + /// Name of the package. + /// The XML data. + /// + /// + /// + /// True if executed succesfully + public bool Execute(string packageName, XmlNode xmlData) + { + + string documentName = xmlData.Attributes["documentName"].Value; + + int parentDocid = 0; + + web.Document[] rootDocs = web.Document.GetRootDocuments(); + + foreach (web.Document rootDoc in rootDocs) + { + if (rootDoc.Text.Trim() == documentName.Trim() && rootDoc != null && rootDoc.ContentType != null) + { + + rootDoc.PublishWithChildrenWithResult(umbraco.BusinessLogic.User.GetUser(0)); + + + break; + } + } + return true; + } + + //this has no undo. + /// + /// This action has no undo. + /// + /// Name of the package. + /// The XML data. + /// + public bool Undo(string packageName, XmlNode xmlData) + { + return true; + } + + /// + /// Action alias + /// + /// + public string Alias() + { + return "publishRootDocument"; + } + #endregion + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/PackageActions/removeStringFromTemplate.cs b/src/umbraco.cms/businesslogic/Packager/PackageActions/removeStringFromTemplate.cs new file mode 100644 index 0000000000..864a32d2f9 --- /dev/null +++ b/src/umbraco.cms/businesslogic/Packager/PackageActions/removeStringFromTemplate.cs @@ -0,0 +1,33 @@ +using System; +using System.Xml; + +namespace umbraco.cms.businesslogic.packager.standardPackageActions +{ + public class removeStringFromTemplate : umbraco.interfaces.IPackageAction + { + #region IPackageAction Members + + public bool Execute(string packageName, XmlNode xmlData) + { + addStringToHtmlElement ast = new addStringToHtmlElement(); + return ast.Undo(packageName, xmlData); + } + + public string Alias() + { + return "removeStringFromHtmlElement"; + } + + public bool Undo(string packageName, XmlNode xmlData) + { + return true; + } + + public XmlNode SampleXml() + { + throw new NotImplementedException(); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/Repositories/Repository.cs b/src/umbraco.cms/businesslogic/Packager/Repositories/Repository.cs index 2a253055c5..e7f3f91b47 100644 --- a/src/umbraco.cms/businesslogic/Packager/Repositories/Repository.cs +++ b/src/umbraco.cms/businesslogic/Packager/Repositories/Repository.cs @@ -4,6 +4,7 @@ using System.Text; using System.Xml; using System.IO; using System.Net; +using Umbraco.Core.Logging; using umbraco.IO; namespace umbraco.cms.businesslogic.packager.repositories { @@ -71,8 +72,10 @@ namespace umbraco.cms.businesslogic.packager.repositories { byte[] thumb = new byte[0]; //todo upload thumbnail... return Webservice.SubmitPackage(m_guid, authorGuid, packageGuid, pack, doc, thumb, packageName, "", "", description); - } catch (Exception ex) { - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString()); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred in SubmitPackage", ex); return SubmitStatus.Error; } diff --git a/src/umbraco.cms/businesslogic/Packager/data.cs b/src/umbraco.cms/businesslogic/Packager/data.cs index 9c0241c31f..d1264d38fe 100644 --- a/src/umbraco.cms/businesslogic/Packager/data.cs +++ b/src/umbraco.cms/businesslogic/Packager/data.cs @@ -4,6 +4,7 @@ using System.Xml.XPath; using System.Collections.Generic; using System.IO; using Umbraco.Core; +using Umbraco.Core.Logging; namespace umbraco.cms.businesslogic.packager { @@ -178,15 +179,19 @@ namespace umbraco.cms.businesslogic.packager List retVal = new List(); - for (int i = 0; i < nList.Count; i++) { - try { - retVal.Add(ConvertXmlToPackage(nList[i])); - } catch (Exception ex) { - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Debug, new BusinessLogic.User(0), -1, ex.ToString()); - } - } + for (int i = 0; i < nList.Count; i++) + { + try + { + retVal.Add(ConvertXmlToPackage(nList[i])); + } + catch (Exception ex) + { + LogHelper.Error("An error occurred in GetAllPackages", ex); + } + } - return retVal; + return retVal; } private static PackageInstance ConvertXmlToPackage(XmlNode n) { diff --git a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs index 73e9715a20..8eaa3760f7 100644 --- a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs +++ b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs @@ -1,6 +1,6 @@ using System; using System.Data; - +using Umbraco.Core.Logging; using umbraco.DataLayer; using umbraco.BusinessLogic; using umbraco.interfaces; @@ -155,7 +155,7 @@ namespace umbraco.cms.businesslogic.datatype } catch (Exception e) { - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, umbraco.BusinessLogic.User.GetUser(0), -1, "Error updating item: " + e.ToString()); + LogHelper.Error("Error updating item", e); if (value == null) value = ""; SqlHelper.ExecuteNonQuery("update cmsPropertyData set " + _dataType.DataFieldName + " = @value where id = " + m_PropertyId, SqlHelper.CreateParameter("@value", value)); } diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index 5f2ccee29a..3520ff5b73 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Web; using System.Xml; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.BusinessLogic.Actions; using umbraco.cms.businesslogic.property; @@ -1161,7 +1162,7 @@ where '" + Path + ",' like " + SqlHelper.Concat("node.path", "'%'")); SqlHelper.ExecuteNonQuery("update cmsDocument set published = 0 where nodeId = " + Id); SqlHelper.ExecuteNonQuery("update cmsDocument set published = 1 where versionId = @versionId", SqlHelper.CreateParameter("@versionId", tempVersion)); - BusinessLogic.Log.Add(LogTypes.Debug, -1, newVersion.ToString() + " - " + Id.ToString()); + LogHelper.Debug("PublishWithSubs: " + newVersion.ToString() + " - " + Id.ToString()); // Update xml in db XmlGenerate(new XmlDocument()); diff --git a/src/umbraco.cms/umbraco.cms.csproj b/src/umbraco.cms/umbraco.cms.csproj index f8016557e9..f00c31a471 100644 --- a/src/umbraco.cms/umbraco.cms.csproj +++ b/src/umbraco.cms/umbraco.cms.csproj @@ -242,6 +242,17 @@ True PackageFiles.resx + + + + + + + + + + + @@ -339,7 +350,7 @@ - + Code diff --git a/src/umbraco.editorControls/DefaultData.cs b/src/umbraco.editorControls/DefaultData.cs index f062f439fa..955d6da7c9 100644 --- a/src/umbraco.editorControls/DefaultData.cs +++ b/src/umbraco.editorControls/DefaultData.cs @@ -1,5 +1,5 @@ using System; - +using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.DataLayer; @@ -49,7 +49,8 @@ namespace umbraco.editorControls } catch (Exception e) { - umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, umbraco.BusinessLogic.User.GetUser(0), -1, "Error updating item: " + e.ToString()); + LogHelper.Error(typeof(DefaultData), "Error updating item: " + e.ToString(), e); + if (value==null) value =""; SqlHelper.ExecuteNonQuery("update cmsPropertyData set "+ _dataType.DataFieldName +" = @value where id = " + _propertyId, SqlHelper.CreateParameter("@value", value) ); _value = value; diff --git a/src/umbraco.webservices/BaseWebService.cs b/src/umbraco.webservices/BaseWebService.cs index 7e8132c5cf..3b024b411b 100644 --- a/src/umbraco.webservices/BaseWebService.cs +++ b/src/umbraco.webservices/BaseWebService.cs @@ -9,6 +9,8 @@ using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Services; using System.Web.Services.Protocols; +using Umbraco.Core.Logging; +using umbraco.BasePages; using umbraco.BusinessLogic; using System.IO; @@ -50,13 +52,16 @@ namespace umbraco.webservices User u = new User(username); if(!HttpContext.Current.Request.Url.Scheme.Equals("https")) - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Debug, u, -1, "Webservices login attempted without https"); + { + LogHelper.Debug("Webservices login attempted without https"); + } + try { if (Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].ValidateUser(username, password)) { - BusinessLogic.Log.Add(BusinessLogic.LogTypes.Login, u, -1,"Webservices"); + LogHelper.Info("User {0} (Id: {1}) logged in", () => u.Name, () => u.Id); return u; } }