PageRenderTime 61ms CodeModel.GetById 56ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/App_Code/Controls/WidgetEditBase.cs

#
C# | 111 lines | 48 code | 22 blank | 41 comment | 4 complexity | a94a678595195a79088c8400704959b7 MD5 | raw file
  1// --------------------------------------------------------------------------------------------------------------------
  2// <summary>
  3//   Widget Edit 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 Edit Base
 19    /// </summary>
 20    public abstract class WidgetEditBase : UserControl
 21    {
 22        #region Events
 23
 24        /// <summary>
 25        ///     Occurs when [saved].
 26        /// </summary>
 27        public static event EventHandler<EventArgs> Saved;
 28
 29        #endregion
 30
 31        #region Properties
 32
 33        /// <summary>
 34        ///     Gets or sets a value indicating whether [show title].
 35        /// </summary>
 36        /// <value><c>true</c> if [show title]; otherwise, <c>false</c>.</value>
 37        public bool ShowTitle { get; set; }
 38
 39        /// <summary>
 40        ///     Gets or sets the title of the widget. It is mandatory for all widgets to set the Title.
 41        /// </summary>
 42        /// <value>The title of the widget.</value>
 43        public string Title { get; set; }
 44
 45        /// <summary>
 46        ///     Gets or sets the widget id.
 47        /// </summary>
 48        /// <value>The widget id.</value>
 49        public Guid WidgetId { get; set; }
 50
 51        #endregion
 52
 53        #region Public Methods
 54
 55        /// <summary>
 56        /// Called when [saved].
 57        /// </summary>
 58        public static void OnSaved()
 59        {
 60            if (Saved != null)
 61            {
 62                Saved(null, new EventArgs());
 63            }
 64        }
 65
 66        /// <summary>
 67        /// Get settings from data store
 68        /// </summary>
 69        /// <returns>
 70        /// The settings
 71        /// </returns>
 72        public StringDictionary GetSettings()
 73        {
 74            var cacheId = string.Format("be_widget_{0}", WidgetId);
 75            if (Blog.CurrentInstance.Cache[cacheId] == null)
 76            {
 77                var ws = new WidgetSettings(WidgetId.ToString());
 78                Blog.CurrentInstance.Cache[cacheId] = ws.GetSettings();
 79            }
 80
 81            return (StringDictionary)Blog.CurrentInstance.Cache[cacheId];
 82        }
 83
 84        /// <summary>
 85        /// Saves this the basic widget settings such as the Title.
 86        /// </summary>
 87        public abstract void Save();
 88
 89        #endregion
 90
 91        #region Methods
 92
 93        /// <summary>
 94        /// Saves settings to data store
 95        /// </summary>
 96        /// <param name="settings">
 97        /// The settings
 98        /// </param>
 99        protected virtual void SaveSettings(StringDictionary settings)
100        {
101            var cacheId = string.Format("be_widget_{0}", WidgetId);
102
103            var ws = new WidgetSettings(WidgetId.ToString());
104            ws.SaveSettings(settings);
105
106            Blog.CurrentInstance.Cache[cacheId] = settings;
107        }
108
109        #endregion
110    }
111}