FunctionConfig.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Autofac;
  2. using GreenTree.Nachtragsmanagement.Core;
  3. using GreenTree.Nachtragsmanagement.Core.Domain.User;
  4. using GreenTree.Nachtragsmanagement.Services.User;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Web;
  9. namespace GreenTree.Nachtragsmanagement.Plugin.MonitionList.App_Start
  10. {
  11. public class FunctionConfig
  12. {
  13. /// <summary>
  14. /// Registers all plugin functions provided by the plugin system
  15. /// </summary>
  16. public static void RegisterFunctions()
  17. {
  18. var userService = Singleton<IContainer>.Instance.Resolve<IUserService>();
  19. var pluginFunctions = AllPluginFunctions();
  20. foreach (var function in pluginFunctions)
  21. {
  22. var existingFunction = userService.GetFunctionByName(function.Name);
  23. if (existingFunction != null)
  24. {
  25. var equals =
  26. existingFunction.Description == function.Description &&
  27. existingFunction.ImageUrl == function.ImageUrl &&
  28. existingFunction.GroupName == function.GroupName &&
  29. existingFunction.RouteName == function.RouteName &&
  30. existingFunction.IsMenuMember == function.IsMenuMember &&
  31. existingFunction.Plugin == function.Plugin &&
  32. existingFunction.BaseWidth == function.BaseWidth &&
  33. existingFunction.MinWidth == function.MinWidth &&
  34. existingFunction.BaseHeight == function.BaseHeight &&
  35. existingFunction.MinHeight == function.MinHeight &&
  36. existingFunction.AllowMaximize == function.AllowMaximize;
  37. if (!equals)
  38. {
  39. existingFunction.Description = function.Description;
  40. existingFunction.ImageUrl = function.ImageUrl;
  41. existingFunction.GroupName = function.GroupName;
  42. existingFunction.RouteName = function.RouteName;
  43. existingFunction.IsMenuMember = function.IsMenuMember;
  44. existingFunction.Plugin = function.Plugin;
  45. existingFunction.BaseWidth = function.BaseWidth;
  46. existingFunction.MinWidth = function.MinWidth;
  47. existingFunction.BaseHeight = function.BaseHeight;
  48. existingFunction.MinHeight = function.MinHeight;
  49. existingFunction.AllowMaximize = function.AllowMaximize;
  50. userService.UpdateFunction(existingFunction);
  51. }
  52. }
  53. else
  54. userService.InsertFunction(function);
  55. }
  56. }
  57. private static Function[] AllPluginFunctions()
  58. {
  59. return new[]
  60. {
  61. new Function
  62. {
  63. Name = "MonotionList",
  64. Description = "Mahnlisten",
  65. ImageUrl = "~/Plugins/Misc.MonotionList/Content/Images/function-MonotionList-32.png",
  66. IsMenuMember = true,
  67. Plugin = "GreenTree.Nachtragsmanagement.Plugin.MonitionList"
  68. },
  69. new Function
  70. {
  71. Name = "MonotionList-Deviations",
  72. Description = "VA-Mahnliste",
  73. ImageUrl = "~/Plugins/Misc.MonotionList/Content/Images/function-MonitionList-Deviations-32.png",
  74. GroupName = "MonotionList",
  75. RouteName = "GreenTree.Nachtragsmanagement.Plugin.MonitionList.Deviations",
  76. IsMenuMember = true,
  77. Plugin = "GreenTree.Nachtragsmanagement.Plugin.MonitionList",
  78. BaseWidth = 900,
  79. MinWidth = 600,
  80. BaseHeight = 600,
  81. MinHeight = 400,
  82. AllowMaximize = true,
  83. MaximizedOnStart = true
  84. },
  85. new Function
  86. {
  87. Name = "MonotionList-Appendices",
  88. Description = "NT-Mahnliste",
  89. ImageUrl = "~/Plugins/Misc.MonotionList/Content/Images/function-MonitionList-Appendices-32.png",
  90. GroupName = "MonotionList",
  91. RouteName = "GreenTree.Nachtragsmanagement.Plugin.MonitionList.Appendices",
  92. IsMenuMember = true,
  93. Plugin = "GreenTree.Nachtragsmanagement.Plugin.MonitionList",
  94. BaseWidth = 900,
  95. MinWidth = 600,
  96. BaseHeight = 600,
  97. MinHeight = 400,
  98. AllowMaximize = true,
  99. MaximizedOnStart = true
  100. }
  101. };
  102. }
  103. }
  104. }