PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <summary>
  3. // Widget Edit Base
  4. // </summary>
  5. // --------------------------------------------------------------------------------------------------------------------
  6. using BlogEngine.Core;
  7. namespace App_Code.Controls
  8. {
  9. using System;
  10. using System.Collections.Specialized;
  11. using System.Web.UI;
  12. using BlogEngine.Core.DataStore;
  13. /// <summary>
  14. /// Widget Edit Base
  15. /// </summary>
  16. public abstract class WidgetEditBase : UserControl
  17. {
  18. #region Events
  19. /// <summary>
  20. /// Occurs when [saved].
  21. /// </summary>
  22. public static event EventHandler<EventArgs> Saved;
  23. #endregion
  24. #region Properties
  25. /// <summary>
  26. /// Gets or sets a value indicating whether [show title].
  27. /// </summary>
  28. /// <value><c>true</c> if [show title]; otherwise, <c>false</c>.</value>
  29. public bool ShowTitle { get; set; }
  30. /// <summary>
  31. /// Gets or sets the title of the widget. It is mandatory for all widgets to set the Title.
  32. /// </summary>
  33. /// <value>The title of the widget.</value>
  34. public string Title { get; set; }
  35. /// <summary>
  36. /// Gets or sets the widget id.
  37. /// </summary>
  38. /// <value>The widget id.</value>
  39. public Guid WidgetId { get; set; }
  40. #endregion
  41. #region Public Methods
  42. /// <summary>
  43. /// Called when [saved].
  44. /// </summary>
  45. public static void OnSaved()
  46. {
  47. if (Saved != null)
  48. {
  49. Saved(null, new EventArgs());
  50. }
  51. }
  52. /// <summary>
  53. /// Get settings from data store
  54. /// </summary>
  55. /// <returns>
  56. /// The settings
  57. /// </returns>
  58. public StringDictionary GetSettings()
  59. {
  60. var cacheId = string.Format("be_widget_{0}", WidgetId);
  61. if (Blog.CurrentInstance.Cache[cacheId] == null)
  62. {
  63. var ws = new WidgetSettings(WidgetId.ToString());
  64. Blog.CurrentInstance.Cache[cacheId] = ws.GetSettings();
  65. }
  66. return (StringDictionary)Blog.CurrentInstance.Cache[cacheId];
  67. }
  68. /// <summary>
  69. /// Saves this the basic widget settings such as the Title.
  70. /// </summary>
  71. public abstract void Save();
  72. #endregion
  73. #region Methods
  74. /// <summary>
  75. /// Saves settings to data store
  76. /// </summary>
  77. /// <param name="settings">
  78. /// The settings
  79. /// </param>
  80. protected virtual void SaveSettings(StringDictionary settings)
  81. {
  82. var cacheId = string.Format("be_widget_{0}", WidgetId);
  83. var ws = new WidgetSettings(WidgetId.ToString());
  84. ws.SaveSettings(settings);
  85. Blog.CurrentInstance.Cache[cacheId] = settings;
  86. }
  87. #endregion
  88. }
  89. }