From 711afe8bb731ad9a2629b7b05583ec989366e0ce Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 3 Apr 2013 11:41:53 -0200 Subject: [PATCH 1/8] Breaking changes reverted --- src/Umbraco.Web.UI/umbraco/Umbraco.aspx.cs | 3 +-- src/Umbraco.Web.UI/umbraco/umbraco.aspx | 2 +- .../Modules/ItemEditing/LiveEditingItemRenderer.cs | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI/umbraco/Umbraco.aspx.cs b/src/Umbraco.Web.UI/umbraco/Umbraco.aspx.cs index f81688f47f..f844e41e50 100644 --- a/src/Umbraco.Web.UI/umbraco/Umbraco.aspx.cs +++ b/src/Umbraco.Web.UI/umbraco/Umbraco.aspx.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -12,7 +11,7 @@ using Umbraco.Core; namespace Umbraco.Web.UI.Umbraco { - public partial class UmbracoMainPage : Pages.UmbracoEnsuredPage + public partial class Umbraco : Pages.UmbracoEnsuredPage { public string DefaultApp { get; private set; } diff --git a/src/Umbraco.Web.UI/umbraco/umbraco.aspx b/src/Umbraco.Web.UI/umbraco/umbraco.aspx index f3e554a825..1726b5509c 100644 --- a/src/Umbraco.Web.UI/umbraco/umbraco.aspx +++ b/src/Umbraco.Web.UI/umbraco/umbraco.aspx @@ -1,5 +1,5 @@ <%@ Page Trace="false" Language="c#" CodeBehind="umbraco.aspx.cs" AutoEventWireup="True" - Inherits="Umbraco.Web.UI.Umbraco.UmbracoMainPage" %> + Inherits="Umbraco.Web.UI.Umbraco.Umbraco" %> <%@ Import Namespace="System.Web.Script.Serialization" %> diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/ItemEditing/LiveEditingItemRenderer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/ItemEditing/LiveEditingItemRenderer.cs index 8959f97f92..c247e0050a 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/ItemEditing/LiveEditingItemRenderer.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/LiveEditing/Modules/ItemEditing/LiveEditingItemRenderer.cs @@ -14,7 +14,9 @@ namespace umbraco.presentation.LiveEditing.Modules.ItemEditing /// public class LiveEditingItemRenderer : ItemRenderer { - //public const string RICHTEXTEDITOR_DATATYPE_ID = "{5E9B75AE-FACE-41c8-B47E-5F4B0FD82F83}"; + [Obsolete("Use Umbraco.Core.Constants.PropertyEditors.TinyMCEv3 instead")] + public const string RichtexteditorDatatypeId = Constants.PropertyEditors.TinyMCEv3; + /// Returns the instance of . public new readonly static LiveEditingItemRenderer Instance = new LiveEditingItemRenderer(); From fa43cfd58f17846b143bb8532b95772bdaf181d2 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 3 Apr 2013 11:43:28 -0200 Subject: [PATCH 2/8] Silly designer file, of course you need to change to. kthxbi --- src/Umbraco.Web.UI/umbraco/Umbraco.aspx.designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI/umbraco/Umbraco.aspx.designer.cs b/src/Umbraco.Web.UI/umbraco/Umbraco.aspx.designer.cs index 9592e4d87b..f7e448af08 100644 --- a/src/Umbraco.Web.UI/umbraco/Umbraco.aspx.designer.cs +++ b/src/Umbraco.Web.UI/umbraco/Umbraco.aspx.designer.cs @@ -10,7 +10,7 @@ namespace Umbraco.Web.UI.Umbraco { - public partial class UmbracoMainPage + public partial class Umbraco { /// From eab9be4ef7c87ee91d8f1474111f86c82e7173b8 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 4 Apr 2013 06:02:08 -0200 Subject: [PATCH 3/8] Fixing issue with reimporting document types and the structure of allowed doc types. Removing old code from Installer. --- src/Umbraco.Core/Services/PackagingService.cs | 2 + .../Services/Importing/PackageImportTests.cs | 24 +++ .../businesslogic/Packager/Installer.cs | 181 ------------------ 3 files changed, 26 insertions(+), 181 deletions(-) diff --git a/src/Umbraco.Core/Services/PackagingService.cs b/src/Umbraco.Core/Services/PackagingService.cs index 1c93a4f56d..037878b44f 100644 --- a/src/Umbraco.Core/Services/PackagingService.cs +++ b/src/Umbraco.Core/Services/PackagingService.cs @@ -423,6 +423,8 @@ namespace Umbraco.Core.Services if (_importedContentTypes.ContainsKey(alias)) { var allowedChild = _importedContentTypes[alias]; + if(allowedChild == null || allowedChildren.Any(x => x.Alias == alias)) continue; + allowedChildren.Add(new ContentTypeSort(new Lazy(() => allowedChild.Id), sortOrder, allowedChild.Alias)); sortOrder++; } diff --git a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs index 60a74bb962..f791894f92 100644 --- a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs +++ b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs @@ -223,5 +223,29 @@ namespace Umbraco.Tests.Services.Importing Assert.That(contentTypes.Any(x => x.HasIdentity == false), Is.False); Assert.That(contentTypes.Count(), Is.EqualTo(1)); } + + [Test] + public void PackagingService_Can_ReImport_Single_DocTypr() + { + // Arrange + string strXml = ImportResources.SingleDocType; + var docTypeElement = XElement.Parse(strXml); + var packagingService = ServiceContext.PackagingService; + + // Act + var contentTypes = packagingService.ImportContentTypes(docTypeElement); + var contentTypesUpdated = packagingService.ImportContentTypes(docTypeElement); + + // Assert + Assert.That(contentTypes.Any(), Is.True); + Assert.That(contentTypes.Any(x => x.HasIdentity == false), Is.False); + Assert.That(contentTypes.Count(), Is.EqualTo(1)); + Assert.That(contentTypes.First().AllowedContentTypes.Count(), Is.EqualTo(1)); + + Assert.That(contentTypesUpdated.Any(), Is.True); + Assert.That(contentTypesUpdated.Any(x => x.HasIdentity == false), Is.False); + Assert.That(contentTypesUpdated.Count(), Is.EqualTo(1)); + Assert.That(contentTypesUpdated.First().AllowedContentTypes.Count(), Is.EqualTo(1)); + } } } \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/Packager/Installer.cs b/src/umbraco.cms/businesslogic/Packager/Installer.cs index 6d355dbfd2..a3d8618a57 100644 --- a/src/umbraco.cms/businesslogic/Packager/Installer.cs +++ b/src/umbraco.cms/businesslogic/Packager/Installer.cs @@ -937,187 +937,6 @@ namespace umbraco.cms.businesslogic.packager { var element = n.GetXElement(); var contentTypes = ApplicationContext.Current.Services.PackagingService.ImportContentTypes(element, u.Id); - /*DocumentType dt = DocumentType.GetByAlias(xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias"))); - if (dt == null) - { - dt = DocumentType.MakeNew(u, xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Name"))); - dt.Alias = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias")); - - - //Master content type - DocumentType mdt = DocumentType.GetByAlias(xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Master"))); - if (mdt != null) - dt.MasterContentType = mdt.Id; - } - else - { - dt.Text = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Name")); - } - - - // Info - dt.IconUrl = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Icon")); - dt.Thumbnail = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Thumbnail")); - dt.Description = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/Description")); - - // Allow at root (check for node due to legacy) - bool allowAtRoot = false; - string allowAtRootNode = xmlHelper.GetNodeValue(n.SelectSingleNode("Info/AllowAtRoot")); - if (!String.IsNullOrEmpty(allowAtRootNode)) - { - bool.TryParse(allowAtRootNode, out allowAtRoot); - } - dt.AllowAtRoot = allowAtRoot; - - // Templates - ArrayList templates = new ArrayList(); - foreach (XmlNode tem in n.SelectNodes("Info/AllowedTemplates/Template")) - { - template.Template t = template.Template.GetByAlias(xmlHelper.GetNodeValue(tem)); - if (t != null) - templates.Add(t); - } - - try - { - template.Template[] at = new template.Template[templates.Count]; - for (int i = 0; i < templates.Count; i++) - at[i] = (template.Template)templates[i]; - dt.allowedTemplates = at; - } - catch (Exception ee) - { - LogHelper.Error("Packager: Error handling allowed templates", ee); - } - - // Default template - try - { - if (xmlHelper.GetNodeValue(n.SelectSingleNode("Info/DefaultTemplate")) != "") - dt.DefaultTemplate = template.Template.GetByAlias(xmlHelper.GetNodeValue(n.SelectSingleNode("Info/DefaultTemplate"))).Id; - } - catch (Exception ee) - { - LogHelper.Error("Packager: Error assigning default template", ee); - } - - // Tabs - cms.businesslogic.ContentType.TabI[] tabs = dt.getVirtualTabs; - string tabNames = ";"; - for (int t = 0; t < tabs.Length; t++) - tabNames += tabs[t].Caption + ";"; - - - //So the Tab is added to the DocumentType and then to this Hashtable, but its never used anywhere - WHY? - Hashtable ht = new Hashtable(); - foreach (XmlNode t in n.SelectNodes("Tabs/Tab")) - { - if (tabNames.IndexOf(";" + xmlHelper.GetNodeValue(t.SelectSingleNode("Caption")) + ";") == -1) - { - ht.Add(int.Parse(xmlHelper.GetNodeValue(t.SelectSingleNode("Id"))), - dt.AddVirtualTab(xmlHelper.GetNodeValue(t.SelectSingleNode("Caption")))); - } - } - - dt.ClearVirtualTabs(); - // Get all tabs in hashtable - Hashtable tabList = new Hashtable(); - foreach (cms.businesslogic.ContentType.TabI t in dt.getVirtualTabs.ToList()) - { - if (!tabList.ContainsKey(t.Caption)) - tabList.Add(t.Caption, t.Id); - } - - // Generic Properties - datatype.controls.Factory f = new datatype.controls.Factory(); - foreach (XmlNode gp in n.SelectNodes("GenericProperties/GenericProperty")) - { - int dfId = 0; - Guid dtId = new Guid(xmlHelper.GetNodeValue(gp.SelectSingleNode("Type"))); - - if (gp.SelectSingleNode("Definition") != null && !string.IsNullOrEmpty(xmlHelper.GetNodeValue(gp.SelectSingleNode("Definition")))) - { - Guid dtdId = new Guid(xmlHelper.GetNodeValue(gp.SelectSingleNode("Definition"))); - if (CMSNode.IsNode(dtdId)) - dfId = new CMSNode(dtdId).Id; - } - if (dfId == 0) - { - try - { - dfId = FindDataTypeDefinitionFromType(ref dtId); - } - catch - { - throw new Exception(String.Format("Could not find datatype with id {0}.", dtId)); - } - } - - // Fix for rich text editor backwards compatibility - if (dfId == 0 && dtId == new Guid("a3776494-0574-4d93-b7de-efdfdec6f2d1")) - { - dtId = new Guid("83722133-f80c-4273-bdb6-1befaa04a612"); - dfId = FindDataTypeDefinitionFromType(ref dtId); - } - - if (dfId != 0) - { - PropertyType pt = dt.getPropertyType(xmlHelper.GetNodeValue(gp.SelectSingleNode("Alias"))); - if (pt == null) - { - dt.AddPropertyType( - datatype.DataTypeDefinition.GetDataTypeDefinition(dfId), - xmlHelper.GetNodeValue(gp.SelectSingleNode("Alias")), - xmlHelper.GetNodeValue(gp.SelectSingleNode("Name")) - ); - pt = dt.getPropertyType(xmlHelper.GetNodeValue(gp.SelectSingleNode("Alias"))); - } - else - { - pt.DataTypeDefinition = datatype.DataTypeDefinition.GetDataTypeDefinition(dfId); - pt.Name = xmlHelper.GetNodeValue(gp.SelectSingleNode("Name")); - } - - pt.Mandatory = bool.Parse(xmlHelper.GetNodeValue(gp.SelectSingleNode("Mandatory"))); - pt.ValidationRegExp = xmlHelper.GetNodeValue(gp.SelectSingleNode("Validation")); - pt.Description = xmlHelper.GetNodeValue(gp.SelectSingleNode("Description")); - - // tab - try - { - if (tabList.ContainsKey(xmlHelper.GetNodeValue(gp.SelectSingleNode("Tab")))) - pt.TabId = (int)tabList[xmlHelper.GetNodeValue(gp.SelectSingleNode("Tab"))]; - } - catch (Exception ee) - { - LogHelper.Error("Packager: Error assigning property to tab", ee); - } - } - } - - if (ImportStructure) - { - if (dt != null) - { - ArrayList allowed = new ArrayList(); - foreach (XmlNode structure in n.SelectNodes("Structure/DocumentType")) - { - DocumentType dtt = DocumentType.GetByAlias(xmlHelper.GetNodeValue(structure)); - if (dtt != null) - allowed.Add(dtt.Id); - } - int[] adt = new int[allowed.Count]; - for (int i = 0; i < allowed.Count; i++) - adt[i] = (int)allowed[i]; - dt.AllowedChildContentTypeIDs = adt; - } - } - - // clear caching - foreach (DocumentType.TabI t in dt.getVirtualTabs.ToList()) - DocumentType.FlushTabCache(t.Id, dt.Id); - - dt.Save();*/ } #endregion From 7610ee5f8bc0c7f6b2c682df5759e1a391ed2419 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 4 Apr 2013 07:16:33 -0200 Subject: [PATCH 4/8] Adding event proxies to the ContentService for publishing events for easier discoverability. Fixes U4-2046 --- src/Umbraco.Core/Services/ContentService.cs | 41 +++++++++++++++++++ .../umbraco/editContent.aspx.cs | 3 +- src/umbraco.cms/businesslogic/web/Document.cs | 9 +++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 9ea5d47951..7f4d4be062 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -1480,6 +1480,47 @@ namespace Umbraco.Core.Services #endregion + #region Proxy Event Handlers + /// + /// Occurs before publish. + /// + /// Proxy to the real event on the + public static event TypedEventHandler> Publishing + { + add { PublishingStrategy.Publishing += value; } + remove { PublishingStrategy.Publishing -= value; } + } + + /// + /// Occurs after publish. + /// + /// Proxy to the real event on the + public static event TypedEventHandler> Published + { + add { PublishingStrategy.Published += value; } + remove { PublishingStrategy.Published -= value; } + } + /// + /// Occurs before unpublish. + /// + /// Proxy to the real event on the + public static event TypedEventHandler> UnPublishing + { + add { PublishingStrategy.UnPublishing += value; } + remove { PublishingStrategy.UnPublishing -= value; } + } + + /// + /// Occurs after unpublish. + /// + /// Proxy to the real event on the + public static event TypedEventHandler> UnPublished + { + add { PublishingStrategy.UnPublished += value; } + remove { PublishingStrategy.UnPublished -= value; } + } + #endregion + #region Event Handlers /// /// Occurs before Delete diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs index 7371da9160..e22da74d90 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs @@ -318,9 +318,8 @@ namespace umbraco.cms.presentation Trace.Warn("before d.publish"); - if (_document.PublishWithResult(base.getUser())) + if (_document.PublishWithResult(base.getUser(), false)) { - library.UpdateDocumentCache(_document.Id); ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editContentPublishedHeader", null), ui.Text("speechBubbles", "editContentPublishedText", null)); littPublishStatus.Text = string.Format("{0}: {1}
", ui.Text("content", "lastPublished", base.getUser()), _document.VersionDate.ToString()); diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index 6c9f039976..e86949df2e 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -798,13 +798,20 @@ namespace umbraco.cms.businesslogic.web [MethodImpl(MethodImplOptions.Synchronized)] [Obsolete("Obsolete, Use Umbraco.Core.Services.ContentService.Publish()", false)] public bool PublishWithResult(User u) + { + return PublishWithResult(u, true); + } + + [MethodImpl(MethodImplOptions.Synchronized)] + [Obsolete("Obsolete, Use Umbraco.Core.Services.ContentService.Publish()", false)] + internal bool PublishWithResult(User u, bool omitCacheRefresh) { var e = new PublishEventArgs(); FireBeforePublish(e); if (!e.Cancel) { - var result = ((ContentService)ApplicationContext.Current.Services.ContentService).Publish(Content, true, u.Id); + var result = ((ContentService)ApplicationContext.Current.Services.ContentService).Publish(Content, omitCacheRefresh, u.Id); _published = result; FireAfterPublish(e); From 9edcc0c90308779f794b059029786d37f7ab6ab9 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 4 Apr 2013 09:46:20 -0200 Subject: [PATCH 5/8] Revert UserType caching changes until Shannon can commit UserTypeCacheRefresher --- .../Cache/CacheRefresherEventHandler.cs | 6 +- src/Umbraco.Web/Umbraco.Web.csproj | 1 - src/umbraco.businesslogic/UserType.cs | 203 +++++++++--------- 3 files changed, 106 insertions(+), 104 deletions(-) diff --git a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs index 6176446088..ba7aa87735 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherEventHandler.cs @@ -23,9 +23,9 @@ namespace Umbraco.Web.Cache protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { //bind to user type events - UserType.Deleted += UserTypeDeleted; - UserType.New += UserTypeNew; - UserType.Updated += UserTypeUpdated; + //UserType.Deleted += UserTypeDeleted; + //UserType.New += UserTypeNew; + //UserType.Updated += UserTypeUpdated; //Bind to dictionary events //NOTE: we need to bind to legacy and new API events currently: http://issues.umbraco.org/issue/U4-1979 diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 4cf8f78146..ad5099541e 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -279,7 +279,6 @@ - diff --git a/src/umbraco.businesslogic/UserType.cs b/src/umbraco.businesslogic/UserType.cs index e049a4023a..c1685e73da 100644 --- a/src/umbraco.businesslogic/UserType.cs +++ b/src/umbraco.businesslogic/UserType.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; using System.Data; -using System.Runtime.CompilerServices; using System.Web; using System.Web.Caching; -using Umbraco.Core; -using Umbraco.Core.Cache; -using Umbraco.Core.Events; + using umbraco.DataLayer; namespace umbraco.BusinessLogic @@ -33,6 +30,7 @@ namespace umbraco.BusinessLogic /// The UserType id to find public UserType(int id) { + Cache(); this.LoadByPrimaryKey(id); } @@ -43,8 +41,8 @@ namespace umbraco.BusinessLogic /// The name. public UserType(int id, string name) { - _id = id; - _name = name; + m_id = id; + m_name = name; } /// @@ -56,17 +54,26 @@ namespace umbraco.BusinessLogic /// public UserType(int id, string name, string defaultPermissions, string alias) { - _name = name; - _id = id; - _defaultPermissions = defaultPermissions; - _alias = alias; + m_name = name; + m_id = id; + m_defaultPermissions = defaultPermissions; + m_alias = alias; } - - private int _id; - private string _name; - private string _defaultPermissions; - private string _alias; + /// + /// A static constructor that will Cache the current UserTypes + /// + static UserType() + { + Cache(); + } + + private const string CACHE_KEY = "UserTypeCache"; + + private int m_id; + private string m_name; + private string m_defaultPermissions; + private string m_alias; /// /// The cache storage for all user types @@ -75,24 +82,14 @@ namespace umbraco.BusinessLogic { get { - return ApplicationContext.Current.ApplicationCache.GetCacheItem( - CacheKeys.UserTypeCacheKey, - () => - { - var tmp = new List(); - using (var dr = SqlHelper.ExecuteReader("select id, userTypeName, userTypeAlias, userTypeDefaultPermissions from umbracoUserType")) - { - while (dr.Read()) - { - tmp.Add(new UserType( - dr.GetShort("id"), - dr.GetString("userTypeName"), - dr.GetString("userTypeDefaultPermissions"), - dr.GetString("userTypeAlias"))); - } - } - return tmp; - }); + //ensure cache exists + if (HttpRuntime.Cache[CACHE_KEY] == null) + ReCache(); + return HttpRuntime.Cache[CACHE_KEY] as List; + } + set + { + HttpRuntime.Cache[CACHE_KEY] = value; } } @@ -107,8 +104,8 @@ namespace umbraco.BusinessLogic /// public string Alias { - get { return _alias; } - set { _alias = value; } + get { return m_alias; } + set { m_alias = value; } } /// @@ -116,8 +113,8 @@ namespace umbraco.BusinessLogic /// public string Name { - get { return _name; } - set { _name = value; } + get { return m_name; } + set { m_name = value; } } /// @@ -125,7 +122,7 @@ namespace umbraco.BusinessLogic /// public int Id { - get { return _id; } + get { return m_id; } } /// @@ -133,8 +130,8 @@ namespace umbraco.BusinessLogic /// public string DefaultPermissions { - get { return _defaultPermissions; } - set { _defaultPermissions = value; } + get { return m_defaultPermissions; } + set { m_defaultPermissions = value; } } /// @@ -153,21 +150,20 @@ namespace umbraco.BusinessLogic public void Save() { //ensure that this object has an ID specified (it exists in the database) - if (_id <= 0) + if (m_id <= 0) throw new Exception("The current UserType object does not exist in the database. New UserTypes should be created with the MakeNew method"); SqlHelper.ExecuteNonQuery(@" update umbracoUserType set userTypeAlias=@alias,userTypeName=@name,userTypeDefaultPermissions=@permissions where id=@id", - SqlHelper.CreateParameter("@alias", _alias), - SqlHelper.CreateParameter("@name", _name), - SqlHelper.CreateParameter("@permissions", _defaultPermissions), - SqlHelper.CreateParameter("@id", _id) - ); + SqlHelper.CreateParameter("@alias", m_alias), + SqlHelper.CreateParameter("@name", m_name), + SqlHelper.CreateParameter("@permissions", m_defaultPermissions), + SqlHelper.CreateParameter("@id", m_id) + ); - //raise event - OnUpdated(this, new EventArgs()); + ReCache(); } /// @@ -176,13 +172,14 @@ namespace umbraco.BusinessLogic public void Delete() { //ensure that this object has an ID specified (it exists in the database) - if (_id <= 0) + if (m_id <= 0) throw new Exception("The current UserType object does not exist in the database. New UserTypes should be created with the MakeNew method"); - SqlHelper.ExecuteNonQuery(@"delete from umbracoUserType where id=@id", SqlHelper.CreateParameter("@id", _id)); + SqlHelper.ExecuteNonQuery(@" + delete from umbracoUserType where id=@id", + SqlHelper.CreateParameter("@id", m_id)); - //raise event - OnDeleted(this, new EventArgs()); + ReCache(); } /// @@ -193,14 +190,14 @@ namespace umbraco.BusinessLogic /// and the data was loaded, false if it wasn't public bool LoadByPrimaryKey(int id) { - var userType = GetUserType(id); + UserType userType = GetUserType(id); if (userType == null) return false; - _id = userType.Id; - _alias = userType.Alias; - _defaultPermissions = userType.DefaultPermissions; - _name = userType.Name; + this.m_id = userType.Id; + this.m_alias = userType.Alias; + this.m_defaultPermissions = userType.DefaultPermissions; + this.m_name = userType.Name; return true; } @@ -211,13 +208,16 @@ namespace umbraco.BusinessLogic /// /// /// - [MethodImpl(MethodImplOptions.Synchronized)] public static UserType MakeNew(string name, string defaultPermissions, string alias) { //ensure that the current alias does not exist //get the id for the new user type - var existing = UserTypes.Find(ut => (ut.Alias == alias)); - + UserType existing = UserTypes.Find( + delegate(UserType ut) + { + return (ut.Alias == alias); + } + ); if (existing != null) throw new Exception("The UserType alias specified already exists"); @@ -228,30 +228,18 @@ namespace umbraco.BusinessLogic SqlHelper.CreateParameter("@alias", alias), SqlHelper.CreateParameter("@name", name), SqlHelper.CreateParameter("@permissions", defaultPermissions)); - - //get it's id - var newId = SqlHelper.ExecuteScalar("SELECT MAX(id) FROM umbracoUserType WHERE userTypeAlias=@alias", SqlHelper.CreateParameter("@alias", alias)); - //load the instance and return it - using (var dr = SqlHelper.ExecuteReader( - "select id, userTypeName, userTypeAlias, userTypeDefaultPermissions from umbracoUserType where id=@id", - SqlHelper.CreateParameter("@id", newId))) - { - if (dr.Read()) + ReCache(); + + //find the new user type + existing = UserTypes.Find( + delegate(UserType ut) { - var ut = new UserType( - dr.GetShort("id"), - dr.GetString("userTypeName"), - dr.GetString("userTypeDefaultPermissions"), - dr.GetString("userTypeAlias")); - - //raise event - OnNew(ut, new EventArgs()); - - return ut; + return (ut.Alias == alias); } - throw new InvalidOperationException("Could not read the new User Type with id of " + newId); - } + ); + + return existing; } /// @@ -261,7 +249,12 @@ namespace umbraco.BusinessLogic /// public static UserType GetUserType(int id) { - return UserTypes.Find(ut => (ut.Id == id)); + return UserTypes.Find( + delegate(UserType ut) + { + return (ut.Id == id); + } + ); } /// @@ -273,32 +266,42 @@ namespace umbraco.BusinessLogic return UserTypes; } - internal static event TypedEventHandler New; - private static void OnNew(UserType userType, EventArgs args) + /// + /// Removes the UserType cache and re-reads the data from the db. + /// + private static void ReCache() { - if (New != null) - { - New(userType, args); - } + HttpRuntime.Cache.Remove(CACHE_KEY); + Cache(); } - internal static event TypedEventHandler Deleted; - private static void OnDeleted(UserType userType, EventArgs args) + /// + /// Read all UserType data and store it in cache. + /// + private static void Cache() { - if (Deleted != null) + //don't query the database is the cache is not null + if (HttpRuntime.Cache[CACHE_KEY] != null) + return; + + List tmp = new List(); + using (IRecordsReader dr = + SqlHelper.ExecuteReader("select id, userTypeName, userTypeAlias, userTypeDefaultPermissions from umbracoUserType")) { - Deleted(userType, args); + while (dr.Read()) + { + tmp.Add(new UserType( + dr.GetShort("id"), + dr.GetString("userTypeName"), + dr.GetString("userTypeDefaultPermissions"), + dr.GetString("userTypeAlias"))); + } } + + UserTypes = tmp; + } - internal static event TypedEventHandler Updated; - private static void OnUpdated(UserType userType, EventArgs args) - { - if (Updated != null) - { - Updated(userType, args); - } - } } } \ No newline at end of file From 7ddbc83731dc33fba0ebcca80b6fc978b566139d Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 4 Apr 2013 10:20:13 -0200 Subject: [PATCH 6/8] Merge gone wrong, my bad! --- src/umbraco.cms/businesslogic/web/Document.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index 016cba8e3d..bafd18486a 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -815,9 +815,9 @@ namespace umbraco.cms.businesslogic.web if (!e.Cancel) { - var result = ((ContentService)ApplicationContext.Current.Services.ContentService).Publish(Content, omitCacheRefresh, u.Id); - _published = result; - + var result = ((ContentService)ApplicationContext.Current.Services.ContentService).PublishInternal(Content, u.Id); + _published = result.Success; + FireAfterPublish(e); return result.Success; From 14aeb55c1459cb759648b1a4c5199c47c992d588 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 4 Apr 2013 12:02:27 -0200 Subject: [PATCH 7/8] Removing unused ServiceStack.Text reference/nuget package. Ignore Macro tests for the model and repo as its not used and still internal. Might be an idea to remove it altogether. --- .../Configuration/UmbracoVersion.cs | 2 +- .../Repositories/MacroRepository.cs | 4 +- .../Serialization/JsonNetSerializer.cs | 72 +++++++++++++++++++ .../ServiceStackJsonSerializer.cs | 29 -------- .../ServiceStackXmlSerializer.cs | 26 ------- src/Umbraco.Core/Umbraco.Core.csproj | 7 +- src/Umbraco.Core/packages.config | 2 +- src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs | 12 ++-- src/Umbraco.Tests/Models/MacroTests.cs | 18 ++--- .../Repositories/MacroRepositoryTest.cs | 2 +- 10 files changed, 95 insertions(+), 79 deletions(-) create mode 100644 src/Umbraco.Core/Serialization/JsonNetSerializer.cs delete mode 100644 src/Umbraco.Core/Serialization/ServiceStackJsonSerializer.cs delete mode 100644 src/Umbraco.Core/Serialization/ServiceStackXmlSerializer.cs diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index 908426637c..583e1097bf 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -5,7 +5,7 @@ namespace Umbraco.Core.Configuration { public class UmbracoVersion { - private static readonly Version Version = new Version("6.1.0"); + private static readonly Version Version = new Version("6.0.3"); /// /// Gets the current version of Umbraco. diff --git a/src/Umbraco.Core/Persistence/Repositories/MacroRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MacroRepository.cs index 8203ced55d..069205fc94 100644 --- a/src/Umbraco.Core/Persistence/Repositories/MacroRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/MacroRepository.cs @@ -35,8 +35,8 @@ namespace Umbraco.Core.Persistence.Repositories private void EnsureDependencies() { _fileSystem = new PhysicalFileSystem("~/App_Data/Macros"); - var serviceStackSerializer = new ServiceStackJsonSerializer(); - _serializationService = new SerializationService(serviceStackSerializer); + var jsonSerializer = new JsonNetSerializer(); + _serializationService = new SerializationService(jsonSerializer); } #region Overrides of RepositoryBase diff --git a/src/Umbraco.Core/Serialization/JsonNetSerializer.cs b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs new file mode 100644 index 0000000000..800278abf0 --- /dev/null +++ b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs @@ -0,0 +1,72 @@ +using System; +using System.IO; +using System.Reflection; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Umbraco.Core.Serialization +{ + internal class JsonNetSerializer : ISerializer + { + private readonly JsonSerializerSettings _settings; + + public JsonNetSerializer() + { + _settings = new JsonSerializerSettings(); + + //var customResolver = new CustomIgnoreResolver + // { + // DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.Public + // }; + //_settings.ContractResolver = customResolver; + + var javaScriptDateTimeConverter = new JavaScriptDateTimeConverter(); + + _settings.Converters.Add(javaScriptDateTimeConverter); + _settings.Converters.Add(new EntityKeyMemberConverter()); + _settings.Converters.Add(new KeyValuePairConverter()); + _settings.Converters.Add(new ExpandoObjectConverter()); + _settings.Converters.Add(new XmlNodeConverter()); + + _settings.NullValueHandling = NullValueHandling.Include; + _settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; + _settings.TypeNameHandling = TypeNameHandling.Objects; + _settings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor; + } + + #region Implementation of ISerializer + + /// + /// Deserialize input stream to object + /// + /// + /// + /// + public object FromStream(Stream input, Type outputType) + { + byte[] bytes = new byte[input.Length]; + input.Position = 0; + input.Read(bytes, 0, (int)input.Length); + string s = Encoding.UTF8.GetString(bytes); + + return JsonConvert.DeserializeObject(s, outputType, _settings); + } + + /// + /// Serialize object to streamed result + /// + /// + /// + public IStreamedResult ToStream(object input) + { + string s = JsonConvert.SerializeObject(input, Formatting.Indented, _settings); + byte[] bytes = Encoding.UTF8.GetBytes(s); + MemoryStream ms = new MemoryStream(bytes); + + return new StreamedResult(ms, true); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Serialization/ServiceStackJsonSerializer.cs b/src/Umbraco.Core/Serialization/ServiceStackJsonSerializer.cs deleted file mode 100644 index 11928d9af0..0000000000 --- a/src/Umbraco.Core/Serialization/ServiceStackJsonSerializer.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.IO; -using ServiceStack.Text; - -namespace Umbraco.Core.Serialization -{ - public class ServiceStackJsonSerializer : ISerializer - { - public ServiceStackJsonSerializer() - { - JsConfig.DateHandler = JsonDateHandler.ISO8601; - JsConfig.ExcludeTypeInfo = false; - JsConfig.IncludeNullValues = true; - JsConfig.ThrowOnDeserializationError = true; - } - - public object FromStream(Stream input, Type outputType) - { - return JsonSerializer.DeserializeFromStream(outputType, input); - } - - public IStreamedResult ToStream(object input) - { - var ms = new MemoryStream(); - JsonSerializer.SerializeToStream(input, ms); - return new StreamedResult(ms, true); - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Serialization/ServiceStackXmlSerializer.cs b/src/Umbraco.Core/Serialization/ServiceStackXmlSerializer.cs deleted file mode 100644 index b7abf29328..0000000000 --- a/src/Umbraco.Core/Serialization/ServiceStackXmlSerializer.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.IO; -using System.Text; -using ServiceStack.Text; - -namespace Umbraco.Core.Serialization -{ - public class ServiceStackXmlSerializer : ISerializer - { - public ServiceStackXmlSerializer() - { - } - - public object FromStream(Stream input, Type outputType) - { - return XmlSerializer.DeserializeFromStream(outputType, input); - } - - public IStreamedResult ToStream(object input) - { - string output = XmlSerializer.SerializeToString(input); - var stream = new MemoryStream(Encoding.UTF8.GetBytes(output)); - return new StreamedResult(stream, true); - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 7a170ea4c2..c4b1a039e8 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -42,8 +42,8 @@ True ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - - ..\packages\ServiceStack.Text.3.9.21\lib\net35\ServiceStack.Text.dll + + ..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll @@ -688,10 +688,9 @@ + - - diff --git a/src/Umbraco.Core/packages.config b/src/Umbraco.Core/packages.config index 287a84c472..6c2b077259 100644 --- a/src/Umbraco.Core/packages.config +++ b/src/Umbraco.Core/packages.config @@ -5,6 +5,6 @@ - + \ No newline at end of file diff --git a/src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs b/src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs index 647a8fd307..4153b0d90f 100644 --- a/src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs +++ b/src/Umbraco.Tests/CodeFirst/CodeFirstTests.cs @@ -28,8 +28,8 @@ namespace Umbraco.Tests.CodeFirst base.Initialize(); - var serviceStackSerializer = new ServiceStackJsonSerializer(); - SerializationService = new SerializationService(serviceStackSerializer); + var jsonNetSerializer = new JsonNetSerializer(); + SerializationService = new SerializationService(jsonNetSerializer); } [Test] @@ -59,8 +59,8 @@ namespace Umbraco.Tests.CodeFirst Assert.That(contentType.Value.PropertyTypes.Count(), Is.EqualTo(2)); var result = SerializationService.ToStream(contentType.Value); - var xml = result.ResultStream.ToJsonString(); - Console.WriteLine(xml); + var json = result.ResultStream.ToJsonString(); + Console.WriteLine(json); } [Test] @@ -90,8 +90,8 @@ namespace Umbraco.Tests.CodeFirst Assert.That(contentType.Value.PropertyTypes.Count(), Is.EqualTo(5)); var result = SerializationService.ToStream(contentType.Value); - var xml = result.ResultStream.ToJsonString(); - Console.WriteLine(xml); + var json = result.ResultStream.ToJsonString(); + Console.WriteLine(json); } [Test] diff --git a/src/Umbraco.Tests/Models/MacroTests.cs b/src/Umbraco.Tests/Models/MacroTests.cs index c45b20f329..be32674cfa 100644 --- a/src/Umbraco.Tests/Models/MacroTests.cs +++ b/src/Umbraco.Tests/Models/MacroTests.cs @@ -8,15 +8,15 @@ using Umbraco.Core.Serialization; namespace Umbraco.Tests.Models { - [TestFixture] + [TestFixture, Ignore] public class MacroTests { [Test] public void Can_Create_And_Serialize_Macro() { // Arrange - var serviceStackSerializer = new ServiceStackJsonSerializer(); - var serializationService = new SerializationService(serviceStackSerializer); + var jsonNetSerializer = new JsonNetSerializer(); + var serializationService = new SerializationService(jsonNetSerializer); var macro = new Macro { @@ -49,8 +49,8 @@ namespace Umbraco.Tests.Models public void Can_Create_And_Serialize_Then_Deserialize_Macro() { // Arrange - var serviceStackSerializer = new ServiceStackJsonSerializer(); - var serializationService = new SerializationService(serviceStackSerializer); + var jsonNetSerializer = new JsonNetSerializer(); + var serializationService = new SerializationService(jsonNetSerializer); var macro = new Macro { @@ -92,8 +92,8 @@ namespace Umbraco.Tests.Models public void Can_Write_Serialized_Macro_To_Disc() { // Arrange - var serviceStackSerializer = new ServiceStackJsonSerializer(); - var serializationService = new SerializationService(serviceStackSerializer); + var jsonNetSerializer = new JsonNetSerializer(); + var serializationService = new SerializationService(jsonNetSerializer); var fileSystem = new PhysicalFileSystem("~/App_Data/Macros"); var macro = new Macro @@ -126,8 +126,8 @@ namespace Umbraco.Tests.Models public void Can_Read_And_Deserialize_Macro_From_Disc() { // Arrange - var serviceStackSerializer = new ServiceStackJsonSerializer(); - var serializationService = new SerializationService(serviceStackSerializer); + var jsonNetSerializer = new JsonNetSerializer(); + var serializationService = new SerializationService(jsonNetSerializer); var fileSystem = new PhysicalFileSystem("~/App_Data/Macros"); var macro = new Macro diff --git a/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs index f681e4927c..707dbbece2 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs @@ -10,7 +10,7 @@ using Umbraco.Core.Persistence.UnitOfWork; namespace Umbraco.Tests.Persistence.Repositories { - [TestFixture] + [TestFixture, Ignore] public class MacroRepositoryTest { [Test] From 03c65c8eeca1a0d5c90a51d9818c9e5e5d4d7055 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 4 Apr 2013 12:13:59 -0200 Subject: [PATCH 8/8] Updating build version to 6.1.0 beta Updating nuspec with new references. --- build/Build.bat | 4 ++-- build/NuSpecs/UmbracoCms.Core.nuspec | 2 +- build/NuSpecs/tools/install.ps1 | 3 +++ src/Umbraco.Core/Configuration/UmbracoVersion.cs | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build/Build.bat b/build/Build.bat index 66f0c7e3b9..8617827d70 100644 --- a/build/Build.bat +++ b/build/Build.bat @@ -1,6 +1,6 @@ @ECHO OFF -SET release=6.0.3 -SET comment= +SET release=6.1.0 +SET comment=beta SET version=%release% IF [%comment%] EQU [] (SET version=%release%) ELSE (SET version=%release%-%comment%) diff --git a/build/NuSpecs/UmbracoCms.Core.nuspec b/build/NuSpecs/UmbracoCms.Core.nuspec index 90e25d6b3f..59163ba62e 100644 --- a/build/NuSpecs/UmbracoCms.Core.nuspec +++ b/build/NuSpecs/UmbracoCms.Core.nuspec @@ -16,7 +16,7 @@ umbraco - + diff --git a/build/NuSpecs/tools/install.ps1 b/build/NuSpecs/tools/install.ps1 index 94449c1898..19af134c2a 100644 --- a/build/NuSpecs/tools/install.ps1 +++ b/build/NuSpecs/tools/install.ps1 @@ -21,4 +21,7 @@ if ($project) { $projectDestinationPath = Split-Path $project.FullName -Parent $umbracoFilesPath = Join-Path $rootPath "UmbracoFiles\*" Copy-Item $umbracoFilesPath $projectDestinationPath -recurse -force + + # Open readme.txt file + $DTE.ItemOperations.OpenFile($toolsPath + '\Readme.txt') } \ No newline at end of file diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index 583e1097bf..3558901033 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -5,7 +5,7 @@ namespace Umbraco.Core.Configuration { public class UmbracoVersion { - private static readonly Version Version = new Version("6.0.3"); + private static readonly Version Version = new Version("6.1.0"); /// /// Gets the current version of Umbraco. @@ -23,7 +23,7 @@ namespace Umbraco.Core.Configuration /// Gets the version comment (like beta or RC). /// /// The version comment. - public static string CurrentComment { get { return ""; } } + public static string CurrentComment { get { return "beta"; } } // Get the version of the umbraco.dll by looking at a class in that dll // Had to do it like this due to medium trust issues, see: http://haacked.com/archive/2010/11/04/assembly-location-and-medium-trust.aspx