PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Trunk/Content/Community/Library/ExtensionPoints/ExtensionPointManager.cs

#
C# | 227 lines | 168 code | 41 blank | 18 comment | 46 complexity | ff19b5945d77c1584786aa48ffd86d35 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0
  1. #region Copyright
  2. //
  3. // DotNetNuke® - http://www.dotnetnuke.com
  4. // Copyright (c) 2002-2013
  5. // by DotNetNuke Corporation
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  8. // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  9. // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  10. // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all copies or substantial portions
  13. // of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  18. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. // DEALINGS IN THE SOFTWARE.
  20. #endregion
  21. using System;
  22. using System.Collections.Generic;
  23. using System.ComponentModel.Composition;
  24. using System.ComponentModel.Composition.Hosting;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Web;
  28. namespace DotNetNuke.ExtensionPoints
  29. {
  30. using Common;
  31. public class ExtensionPointManager
  32. {
  33. #pragma warning disable 649
  34. [ImportMany]
  35. private IEnumerable<Lazy<IScriptItemExtensionPoint, IExtensionPointData>> _scripts;
  36. [ImportMany]
  37. private IEnumerable<Lazy<IEditPageTabExtensionPoint, IExtensionPointData>> _editPageTabExtensionPoint;
  38. [ImportMany]
  39. private IEnumerable<Lazy<IToolBarButtonExtensionPoint, IExtensionPointData>> _toolbarButtonExtensionPoints;
  40. [ImportMany]
  41. private IEnumerable<Lazy<IEditPagePanelExtensionPoint, IExtensionPointData>> _editPagePanelExtensionPoints;
  42. [ImportMany]
  43. private IEnumerable<Lazy<IContextMenuItemExtensionPoint, IExtensionPointData>> _ctxMenuItemExtensionPoints;
  44. [ImportMany]
  45. private IEnumerable<Lazy<IUserControlExtensionPoint, IExtensionPointData>> _userControlExtensionPoints;
  46. [ImportMany]
  47. private IEnumerable<Lazy<IMenuItemExtensionPoint, IExtensionPointData>> _menuItems;
  48. [ImportMany]
  49. private IEnumerable<Lazy<IGridColumnExtensionPoint, IExtensionPointData>> _gridColumns;
  50. #pragma warning restore 649
  51. private static readonly object SyncRoot = new Object();
  52. private static CompositionContainer MefCompositionContainer
  53. {
  54. get
  55. {
  56. var container = HttpContext.Current.Application["MefCompositionContainer"] as CompositionContainer;
  57. if (container == null)
  58. {
  59. var catalog = new AggregateCatalog();
  60. var path = Path.Combine(Globals.ApplicationMapPath, "bin");
  61. catalog.Catalogs.Add(new SafeDirectoryCatalog(path));
  62. container = new CompositionContainer(catalog, true);
  63. HttpContext.Current.Application["MefCompositionContainer"] = container;
  64. }
  65. return container;
  66. }
  67. }
  68. public static void ComposeParts(params object[] attributeParts)
  69. {
  70. lock (SyncRoot)
  71. {
  72. MefCompositionContainer.ComposeParts(attributeParts);
  73. }
  74. }
  75. public ExtensionPointManager()
  76. {
  77. ComposeParts(this);
  78. }
  79. public IEnumerable<IEditPageTabExtensionPoint> GetEditPageTabExtensionPoints(string module)
  80. {
  81. return _editPageTabExtensionPoint.Where(e => e.Metadata.Module == module).OrderBy(e => e.Value.Order).Select(e => e.Value);
  82. }
  83. public IEnumerable<IEditPageTabExtensionPoint> GetEditPageTabExtensionPoints(string module, string group)
  84. {
  85. if (String.IsNullOrEmpty(group))
  86. {
  87. return GetEditPageTabExtensionPoints(module);
  88. }
  89. return _editPageTabExtensionPoint.Where(e => e.Metadata.Module == module && e.Metadata.Group == @group).OrderBy(e => e.Value.Order).Select(e => e.Value);
  90. }
  91. public IEnumerable<IToolBarButtonExtensionPoint> GetToolBarButtonExtensionPoints(string module)
  92. {
  93. return _toolbarButtonExtensionPoints.Where(e => e.Metadata.Module == module).OrderBy(e => e.Value.Order).Select(e => e.Value);
  94. }
  95. public IEnumerable<IToolBarButtonExtensionPoint> GetToolBarButtonExtensionPoints(string module, string group)
  96. {
  97. if (string.IsNullOrEmpty(group))
  98. {
  99. return GetToolBarButtonExtensionPoints(module);
  100. }
  101. return _toolbarButtonExtensionPoints.Where(e => e.Metadata.Module == module && e.Metadata.Group == @group).OrderBy(e => e.Value.Order).Select(e => e.Value);
  102. }
  103. public IEnumerable<IScriptItemExtensionPoint> GetScriptItemExtensionPoints(string module)
  104. {
  105. return _scripts.Where(e => e.Metadata.Module == module).OrderByDescending(e => e.Value.Order).Select(e => e.Value);
  106. }
  107. public IEnumerable<IScriptItemExtensionPoint> GetScriptItemExtensionPoints(string module, string group)
  108. {
  109. if (string.IsNullOrEmpty(group))
  110. {
  111. return GetScriptItemExtensionPoints(module);
  112. }
  113. return _scripts.Where(e => e.Metadata.Module == module && e.Metadata.Group == group).OrderBy(e => e.Value.Order).Select(e => e.Value);
  114. }
  115. public IEnumerable<IEditPagePanelExtensionPoint> GetEditPagePanelExtensionPoints(string module)
  116. {
  117. return _editPagePanelExtensionPoints.Where(e => e.Metadata.Module == module).OrderBy(e => e.Value.Order).Select(e => e.Value);
  118. }
  119. public IEnumerable<IEditPagePanelExtensionPoint> GetEditPagePanelExtensionPoints(string module, string group)
  120. {
  121. if(string.IsNullOrEmpty(group))
  122. {
  123. return GetEditPagePanelExtensionPoints(module);
  124. }
  125. return _editPagePanelExtensionPoints.Where(e => e.Metadata.Module == module && e.Metadata.Group == @group)
  126. .OrderBy(e => e.Value.Order)
  127. .Select(e => e.Value);
  128. }
  129. public IEditPagePanelExtensionPoint GetEditPagePanelExtensionPointFirstByPriority(string module, string name)
  130. {
  131. return _editPagePanelExtensionPoints.Where(e => e.Metadata.Module == module && e.Metadata.Name == name)
  132. .OrderBy(e => e.Metadata.Priority)
  133. .Select(e => e.Value)
  134. .FirstOrDefault();
  135. }
  136. public IEnumerable<IContextMenuItemExtensionPoint> GetContextMenuItemExtensionPoints(string module)
  137. {
  138. return _ctxMenuItemExtensionPoints.Where(e => e.Metadata.Module == module).OrderBy(e => e.Value.Order).Select(e => e.Value);
  139. }
  140. public IEnumerable<IContextMenuItemExtensionPoint> GetContextMenuItemExtensionPoints(string module, string group)
  141. {
  142. if (string.IsNullOrEmpty(group))
  143. {
  144. return GetContextMenuItemExtensionPoints(module);
  145. }
  146. return _ctxMenuItemExtensionPoints.Where(e => e.Metadata.Module == module && e.Metadata.Group == @group).OrderBy(e => e.Value.Order).Select(e => e.Value);
  147. }
  148. public IUserControlExtensionPoint GetUserControlExtensionPointFirstByPriority(string module, string name)
  149. {
  150. return _userControlExtensionPoints.Where(e => e.Metadata.Module == module && e.Metadata.Name == name)
  151. .OrderBy(e => e.Metadata.Priority)
  152. .Select(e => e.Value)
  153. .FirstOrDefault();
  154. }
  155. public IEnumerable<IUserControlExtensionPoint> GetUserControlExtensionPoints(string module, string group)
  156. {
  157. return _userControlExtensionPoints.Where(e => e.Metadata.Module == module && e.Metadata.Group == @group)
  158. .OrderBy(e => e.Value.Order)
  159. .Select(e => e.Value);
  160. }
  161. public IEnumerable<IMenuItemExtensionPoint> GetMenuItemExtensionPoints(string module)
  162. {
  163. return _menuItems.Where(e => e.Metadata.Module == module).OrderBy(e => e.Value.Order).Select(e => e.Value);
  164. }
  165. public IEnumerable<IMenuItemExtensionPoint> GetMenuItemExtensionPoints(string module, string group)
  166. {
  167. if (string.IsNullOrEmpty(group))
  168. {
  169. return GetMenuItemExtensionPoints(module);
  170. }
  171. return _menuItems.Where(e => e.Metadata.Module == module && e.Metadata.Group == @group).OrderBy(e => e.Value.Order).Select(e => e.Value);
  172. }
  173. public IEnumerable<IGridColumnExtensionPoint> GetGridColumnExtensionPoints(string module)
  174. {
  175. return _gridColumns.Where(e => e.Metadata.Module == module).OrderBy(e => e.Value.Order).Select(e => e.Value);
  176. }
  177. public IEnumerable<IGridColumnExtensionPoint> GetGridColumnExtensionPoints(string module, string group)
  178. {
  179. if (string.IsNullOrEmpty(group))
  180. {
  181. return GetGridColumnExtensionPoints(module);
  182. }
  183. return _gridColumns.Where(e => e.Metadata.Module == module && e.Metadata.Group == @group).OrderBy(e => e.Value.Order).Select(e => e.Value);
  184. }
  185. }
  186. }