From bd180fd6bae1e8a7d459cedb245434e35a4bd5e6 Mon Sep 17 00:00:00 2001 From: "Morten@Thinkpad-X220" Date: Wed, 3 Oct 2012 11:59:49 -0200 Subject: [PATCH] Adds IMacro, IMacroProperty and IMacroPropertyType interfaces. Adds Macro and MacroProperty implementations U4-928. Adds enums used for MacroTypes and MacroPropertyTypeBaseTypes --- src/Umbraco.Core/Models/Content.cs | 2 +- src/Umbraco.Core/Models/ContentType.cs | 2 +- src/Umbraco.Core/Models/IMacro.cs | 94 +++++++++++++ src/Umbraco.Core/Models/IMacroProperty.cs | 39 ++++++ src/Umbraco.Core/Models/IMacroPropertyType.cs | 28 ++++ src/Umbraco.Core/Models/Macro.cs | 128 ++++++++++++++++++ src/Umbraco.Core/Models/MacroProperty.cs | 41 ++++++ .../Models/MacroPropertyTypeBaseTypes.cs | 12 ++ src/Umbraco.Core/Models/MacroTypes.cs | 15 ++ src/Umbraco.Core/Umbraco.Core.csproj | 7 + 10 files changed, 366 insertions(+), 2 deletions(-) create mode 100644 src/Umbraco.Core/Models/IMacro.cs create mode 100644 src/Umbraco.Core/Models/IMacroProperty.cs create mode 100644 src/Umbraco.Core/Models/IMacroPropertyType.cs create mode 100644 src/Umbraco.Core/Models/Macro.cs create mode 100644 src/Umbraco.Core/Models/MacroProperty.cs create mode 100644 src/Umbraco.Core/Models/MacroPropertyTypeBaseTypes.cs create mode 100644 src/Umbraco.Core/Models/MacroTypes.cs diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 7baa382e24..554ab0c2e6 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -10,7 +10,7 @@ using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models { /// - /// Defines a Content object + /// Represents a Content object /// [Serializable] [DataContract(IsReference = true)] diff --git a/src/Umbraco.Core/Models/ContentType.cs b/src/Umbraco.Core/Models/ContentType.cs index 579721901c..623334d0e8 100644 --- a/src/Umbraco.Core/Models/ContentType.cs +++ b/src/Umbraco.Core/Models/ContentType.cs @@ -9,7 +9,7 @@ using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models { /// - /// Defines the type of a object + /// Represents the type of a object /// [Serializable] [DataContract(IsReference = true)] diff --git a/src/Umbraco.Core/Models/IMacro.cs b/src/Umbraco.Core/Models/IMacro.cs new file mode 100644 index 0000000000..c46a32c790 --- /dev/null +++ b/src/Umbraco.Core/Models/IMacro.cs @@ -0,0 +1,94 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; +using Umbraco.Core.Models.EntityBase; + +namespace Umbraco.Core.Models +{ + /// + /// Defines a Macro + /// + public interface IMacro : IAggregateRoot + { + /// + /// Gets or sets the alias of the Macro + /// + [DataMember] + string Alias { get; set; } + + /// + /// Gets or sets the name of the Macro + /// + [DataMember] + string Name { get; set; } + + /// + /// Gets or sets a boolean indicating whether the Macro can be used in an Editor + /// + [DataMember] + bool UseInEditor { get; set; } + + /// + /// Gets or sets the Cache Duration for the Macro + /// + [DataMember] + int CacheDuration { get; set; } + + /// + /// Gets or sets a boolean indicating whether the Macro should be Cached by Page + /// + [DataMember] + bool CacheByPage { get; set; } + + /// + /// Gets or sets a boolean indicating whether the Macro should be Cached Personally + /// + [DataMember] + bool CacheByMember { get; set; } + + /// + /// Gets or sets a boolean indicating whether the Macro should be rendered in an Editor + /// + [DataMember] + bool DontRender { get; set; } + + /// + /// Gets or sets the path to the script file in use + /// + /// Optional: Can only be one of three Script, Python or Xslt + [DataMember] + string ScriptFile { get; set; } + + /// + /// Gets or sets the name of the assembly, which should be used by the Macro + /// + /// Will usually only be filled if the ScriptFile is a Usercontrol + [DataMember] + string ScriptAssembly { get; set; } + + /// + /// Gets or set the path to the Python file in use + /// + /// Optional: Can only be one of three Script, Python or Xslt + [DataMember] + string Python { get; set; } + + /// + /// Gets or sets the path to the Xslt file in use + /// + /// Optional: Can only be one of three Script, Python or Xslt + [DataMember] + string Xslt { get; set; } + + /// + /// Gets or sets a list of Macro Properties + /// + [DataMember] + List Properties { get; set; } + + /// + /// Returns an enum based on the properties on the Macro + /// + /// + MacroTypes FindMacroType(); + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/IMacroProperty.cs b/src/Umbraco.Core/Models/IMacroProperty.cs new file mode 100644 index 0000000000..91e80716dc --- /dev/null +++ b/src/Umbraco.Core/Models/IMacroProperty.cs @@ -0,0 +1,39 @@ +using System.Runtime.Serialization; +using Umbraco.Core.Models.EntityBase; + +namespace Umbraco.Core.Models +{ + /// + /// Defines a Property for a Macro + /// + public interface IMacroProperty : IValueObject + { + /// + /// Gets or sets the Alias of the Property + /// + [DataMember] + string Alias { get; set; } + + /// + /// Gets or sets the Name of the Property + /// + [DataMember] + string Name { get; set; } + + /// + /// Gets or sets the Sort Order of the Property + /// + [DataMember] + int SortOrder { get; set; } + + /// + /// Gets or sets the Type for this Property + /// + /// + /// The MacroPropertyTypes acts as a plugin for Macros. + /// All types was previously contained in the database, but has been ported to code. + /// + [DataMember] + IMacroPropertyType PropertyType { get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/IMacroPropertyType.cs b/src/Umbraco.Core/Models/IMacroPropertyType.cs new file mode 100644 index 0000000000..acbc9ec6ef --- /dev/null +++ b/src/Umbraco.Core/Models/IMacroPropertyType.cs @@ -0,0 +1,28 @@ +namespace Umbraco.Core.Models +{ + /// + /// Defines a PropertyType (plugin) for a Macro + /// + public interface IMacroPropertyType + { + /// + /// Gets the unique Alias of the Property Type + /// + string Alias { get; } + + /// + /// Gets the name of the Assembly used to render the Property Type + /// + string RenderingAssembly { get; } + + /// + /// Gets the name of the Type used to render the Property Type + /// + string RenderingType { get; } + + /// + /// Gets the Base Type for storing the PropertyType (Int32, String, Boolean) + /// + MacroPropertyTypeBaseTypes BaseType { get; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Macro.cs b/src/Umbraco.Core/Models/Macro.cs new file mode 100644 index 0000000000..916b804e40 --- /dev/null +++ b/src/Umbraco.Core/Models/Macro.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using Umbraco.Core.Models.EntityBase; + +namespace Umbraco.Core.Models +{ + /// + /// Represents a Macro + /// + [Serializable] + [DataContract(IsReference = true)] + public class Macro : Entity, IMacro + { + /// + /// Gets or sets the alias of the Macro + /// + [DataMember] + public string Alias { get; set; } + + /// + /// Gets or sets the name of the Macro + /// + [DataMember] + public string Name { get; set; } + + /// + /// Gets or sets a boolean indicating whether the Macro can be used in an Editor + /// + [DataMember] + public bool UseInEditor { get; set; } + + /// + /// Gets or sets the Cache Duration for the Macro + /// + [DataMember] + public int CacheDuration { get; set; } + + /// + /// Gets or sets a boolean indicating whether the Macro should be Cached by Page + /// + [DataMember] + public bool CacheByPage { get; set; } + + /// + /// Gets or sets a boolean indicating whether the Macro should be Cached Personally + /// + [DataMember] + public bool CacheByMember { get; set; } + + /// + /// Gets or sets a boolean indicating whether the Macro should be rendered in an Editor + /// + [DataMember] + public bool DontRender { get; set; } + + /// + /// Gets or sets the path to the script file in use + /// + /// Optional: Can only be one of three Script, Python or Xslt + [DataMember] + public string ScriptFile { get; set; } + + /// + /// Gets or sets the name of the assembly, which should be used by the Macro + /// + /// Will usually only be filled if the ScriptFile is a Usercontrol + [DataMember] + public string ScriptAssembly { get; set; } + + /// + /// Gets or set the path to the Python file in use + /// + /// Optional: Can only be one of three Script, Python or Xslt + [DataMember] + public string Python { get; set; } + + /// + /// Gets or sets the path to the Xslt file in use + /// + /// Optional: Can only be one of three Script, Python or Xslt + [DataMember] + public string Xslt { get; set; } + + /// + /// Gets or sets a list of Macro Properties + /// + [DataMember] + public List Properties { get; set; } + + /// + /// Overridden this method in order to set a random Id + /// + internal override void AddingEntity() + { + base.AddingEntity(); + + var random = new Random(); + Id = random.Next(10000, int.MaxValue); + } + + /// + /// Returns an enum based on the properties on the Macro + /// + /// + public MacroTypes FindMacroType() + { + if (!string.IsNullOrEmpty(Xslt)) + return MacroTypes.Xslt; + + if (!string.IsNullOrEmpty(Python)) + return MacroTypes.Python; + + if (!string.IsNullOrEmpty(ScriptFile)) + return MacroTypes.Script; + + if (!string.IsNullOrEmpty(ScriptFile) && ScriptFile.ToLower().IndexOf(".ascx", StringComparison.InvariantCultureIgnoreCase) > -1) + { + return MacroTypes.UserControl; + } + + if (!string.IsNullOrEmpty(ScriptFile) && !string.IsNullOrEmpty(ScriptAssembly)) + return MacroTypes.CustomControl; + + return MacroTypes.Unknown; + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/MacroProperty.cs b/src/Umbraco.Core/Models/MacroProperty.cs new file mode 100644 index 0000000000..bc183fbf7d --- /dev/null +++ b/src/Umbraco.Core/Models/MacroProperty.cs @@ -0,0 +1,41 @@ +using System; +using System.Runtime.Serialization; + +namespace Umbraco.Core.Models +{ + /// + /// Represents a Macro Property + /// + [Serializable] + [DataContract(IsReference = true)] + public class MacroProperty : IMacroProperty + { + /// + /// Gets or sets the Alias of the Property + /// + [DataMember] + public string Alias { get; set; } + + /// + /// Gets or sets the Name of the Property + /// + [DataMember] + public string Name { get; set; } + + /// + /// Gets or sets the Sort Order of the Property + /// + [DataMember] + public int SortOrder { get; set; } + + /// + /// Gets or sets the Type for this Property + /// + /// + /// The MacroPropertyTypes acts as a plugin for Macros. + /// All types was previously contained in the database, but has been ported to code. + /// + [DataMember] + public IMacroPropertyType PropertyType { get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/MacroPropertyTypeBaseTypes.cs b/src/Umbraco.Core/Models/MacroPropertyTypeBaseTypes.cs new file mode 100644 index 0000000000..0380f1df63 --- /dev/null +++ b/src/Umbraco.Core/Models/MacroPropertyTypeBaseTypes.cs @@ -0,0 +1,12 @@ +namespace Umbraco.Core.Models +{ + /// + /// Enum for the three allowed BaseTypes + /// + public enum MacroPropertyTypeBaseTypes + { + Int32, + Boolean, + String + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/MacroTypes.cs b/src/Umbraco.Core/Models/MacroTypes.cs new file mode 100644 index 0000000000..ef1083afe9 --- /dev/null +++ b/src/Umbraco.Core/Models/MacroTypes.cs @@ -0,0 +1,15 @@ +namespace Umbraco.Core.Models +{ + /// + /// Enum for the various types of Macros + /// + public enum MacroTypes + { + Xslt = 1, + CustomControl = 2, + UserControl = 3, + Unknown = 4, + Python = 5, + Script = 6 + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 8cd8d273bc..cb61131871 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -107,8 +107,15 @@ + + + + + + +