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); Key = Alias.EncodeAsGuid(); } /// /// 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; } } }