PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <summary>
  3. // Widget 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 Base
  15. /// </summary>
  16. public abstract class WidgetBase : UserControl
  17. {
  18. #region Properties
  19. /// <summary>
  20. /// Gets a value indicating whether the header is visible. This only takes effect if the widgets isn't editable.
  21. /// </summary>
  22. /// <value><c>true</c> if the header is visible; otherwise, <c>false</c>.</value>
  23. public virtual bool DisplayHeader
  24. {
  25. get
  26. {
  27. return true;
  28. }
  29. }
  30. /// <summary>
  31. /// Gets a value indicating whether or not the widget can be edited.
  32. /// <remarks>
  33. /// The only way a widget can be editable is by adding a edit.ascx file to the widget folder.
  34. /// </remarks>
  35. /// </summary>
  36. public abstract bool IsEditable { get; }
  37. /// <summary>
  38. /// Gets the name. It must be exactly the same as the folder that contains the widget.
  39. /// </summary>
  40. public abstract string Name { get; }
  41. /// <summary>
  42. /// Gets or sets a value indicating whether [show title].
  43. /// </summary>
  44. /// <value><c>true</c> if [show title]; otherwise, <c>false</c>.</value>
  45. public bool ShowTitle { get; set; }
  46. /// <summary>
  47. /// Gets or sets the title of the widget. It is mandatory for all widgets to set the Title.
  48. /// </summary>
  49. /// <value>The title of the widget.</value>
  50. public string Title { get; set; }
  51. /// <summary>
  52. /// Gets or sets the widget ID.
  53. /// </summary>
  54. /// <value>The widget ID.</value>
  55. public Guid WidgetId { get; set; }
  56. /// <summary>
  57. /// Gets or sets the name of the containing WidgetZone
  58. /// </summary>
  59. public string Zone { get; set; }
  60. #endregion
  61. #region Public Methods
  62. /// <summary>
  63. /// Get settings from data store
  64. /// </summary>
  65. /// <returns>
  66. /// The settings
  67. /// </returns>
  68. public StringDictionary GetSettings()
  69. {
  70. var cacheId = string.Format("be_widget_{0}", this.WidgetId);
  71. if (Blog.CurrentInstance.Cache[cacheId] == null)
  72. {
  73. var ws = new WidgetSettings(this.WidgetId.ToString());
  74. Blog.CurrentInstance.Cache[cacheId] = ws.GetSettings();
  75. }
  76. return (StringDictionary)Blog.CurrentInstance.Cache[cacheId];
  77. }
  78. /// <summary>
  79. /// This method works as a substitute for Page_Load. You should use this method for
  80. /// data binding etc. instead of Page_Load.
  81. /// </summary>
  82. public abstract void LoadWidget();
  83. #endregion
  84. #region Methods
  85. /// <summary>
  86. /// Sends server control content to a provided <see cref="T:System.Web.UI.HtmlTextWriter"></see>
  87. /// object, which writes the content to be rendered on the client.
  88. /// </summary>
  89. /// <param name="writer">
  90. /// The <see cref="T:System.Web.UI.HtmlTextWriter"></see> object that receives the server control content.
  91. /// </param>
  92. protected override void Render(HtmlTextWriter writer)
  93. {
  94. if (string.IsNullOrEmpty(this.Name))
  95. {
  96. throw new NullReferenceException("Name must be set on a widget");
  97. }
  98. base.Render(writer);
  99. }
  100. #endregion
  101. }
  102. }