PageRenderTime 54ms CodeModel.GetById 39ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/App_Code/Controls/WidgetBase.cs

#
C# | 123 lines | 49 code | 21 blank | 53 comment | 3 complexity | 577548ac61f324967e8d206449577251 MD5 | raw file
  1// --------------------------------------------------------------------------------------------------------------------
  2// <summary>
  3//   Widget Base
  4// </summary>
  5// --------------------------------------------------------------------------------------------------------------------
  6
  7using BlogEngine.Core;
  8
  9namespace App_Code.Controls
 10{
 11    using System;
 12    using System.Collections.Specialized;
 13    using System.Web.UI;
 14
 15    using BlogEngine.Core.DataStore;
 16
 17    /// <summary>
 18    /// Widget Base
 19    /// </summary>
 20    public abstract class WidgetBase : UserControl
 21    {
 22        #region Properties
 23
 24        /// <summary>
 25        ///     Gets a value indicating whether the header is visible. This only takes effect if the widgets isn't editable.
 26        /// </summary>
 27        /// <value><c>true</c> if the header is visible; otherwise, <c>false</c>.</value>
 28        public virtual bool DisplayHeader
 29        {
 30            get
 31            {
 32                return true;
 33            }
 34        }
 35
 36        /// <summary>
 37        ///     Gets a value indicating whether or not the widget can be edited.
 38        ///     <remarks>
 39        ///         The only way a widget can be editable is by adding a edit.ascx file to the widget folder.
 40        ///     </remarks>
 41        /// </summary>
 42        public abstract bool IsEditable { get; }
 43
 44        /// <summary>
 45        ///     Gets the name. It must be exactly the same as the folder that contains the widget.
 46        /// </summary>
 47        public abstract string Name { get; }
 48
 49        /// <summary>
 50        ///     Gets or sets a value indicating whether [show title].
 51        /// </summary>
 52        /// <value><c>true</c> if [show title]; otherwise, <c>false</c>.</value>
 53        public bool ShowTitle { get; set; }
 54
 55        /// <summary>
 56        ///     Gets or sets the title of the widget. It is mandatory for all widgets to set the Title.
 57        /// </summary>
 58        /// <value>The title of the widget.</value>
 59        public string Title { get; set; }
 60
 61        /// <summary>
 62        ///     Gets or sets the widget ID.
 63        /// </summary>
 64        /// <value>The widget ID.</value>
 65        public Guid WidgetId { get; set; }
 66
 67        /// <summary>
 68        ///     Gets or sets the name of the containing WidgetZone
 69        /// </summary>
 70        public string Zone { get; set; }
 71
 72        #endregion
 73
 74        #region Public Methods
 75
 76        /// <summary>
 77        /// Get settings from data store
 78        /// </summary>
 79        /// <returns>
 80        /// The settings
 81        /// </returns>
 82        public StringDictionary GetSettings()
 83        {
 84            var cacheId = string.Format("be_widget_{0}", this.WidgetId);
 85            if (Blog.CurrentInstance.Cache[cacheId] == null)
 86            {
 87                var ws = new WidgetSettings(this.WidgetId.ToString());
 88                Blog.CurrentInstance.Cache[cacheId] = ws.GetSettings();
 89            }
 90
 91            return (StringDictionary)Blog.CurrentInstance.Cache[cacheId];
 92        }
 93
 94        /// <summary>
 95        /// This method works as a substitute for Page_Load. You should use this method for
 96        ///     data binding etc. instead of Page_Load.
 97        /// </summary>
 98        public abstract void LoadWidget();
 99
100        #endregion
101
102        #region Methods
103
104        /// <summary>
105        /// Sends server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter"></see> 
106        ///     object, which writes the content to be rendered on the client.
107        /// </summary>
108        /// <param name="writer">
109        /// The <see cref="T:System.Web.UI.HtmlTextWriter"></see> object that receives the server control content.
110        /// </param>
111        protected override void Render(HtmlTextWriter writer)
112        {
113            if (string.IsNullOrEmpty(this.Name))
114            {
115                throw new NullReferenceException("Name must be set on a widget");
116            }
117
118            base.Render(writer);
119        }
120
121        #endregion
122    }
123}