2
0

PluginSecurityManager.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using Mediabrowser.Model.Entities;
  2. using Mediabrowser.PluginSecurity;
  3. using MediaBrowser.Common.Kernel;
  4. using MediaBrowser.Common.Net;
  5. using System;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace MediaBrowser.Controller.Plugins
  9. {
  10. /// <summary>
  11. /// Class PluginSecurityManager
  12. /// </summary>
  13. public class PluginSecurityManager
  14. {
  15. /// <summary>
  16. /// The _is MB supporter
  17. /// </summary>
  18. private bool? _isMBSupporter;
  19. /// <summary>
  20. /// The _is MB supporter initialized
  21. /// </summary>
  22. private bool _isMBSupporterInitialized;
  23. /// <summary>
  24. /// The _is MB supporter sync lock
  25. /// </summary>
  26. private object _isMBSupporterSyncLock = new object();
  27. /// <summary>
  28. /// Gets a value indicating whether this instance is MB supporter.
  29. /// </summary>
  30. /// <value><c>true</c> if this instance is MB supporter; otherwise, <c>false</c>.</value>
  31. public bool IsMBSupporter
  32. {
  33. get
  34. {
  35. LazyInitializer.EnsureInitialized(ref _isMBSupporter, ref _isMBSupporterInitialized, ref _isMBSupporterSyncLock, () => GetRegistrationStatus("MBSupporter").Result.IsRegistered);
  36. return _isMBSupporter.Value;
  37. }
  38. }
  39. /// <summary>
  40. /// The _network manager
  41. /// </summary>
  42. private INetworkManager _networkManager;
  43. /// <summary>
  44. /// The _kernel
  45. /// </summary>
  46. private readonly IKernel _kernel;
  47. /// <summary>
  48. /// Initializes a new instance of the <see cref="PluginSecurityManager" /> class.
  49. /// </summary>
  50. /// <param name="kernel">The kernel.</param>
  51. /// <param name="networkManager">The network manager.</param>
  52. public PluginSecurityManager(IKernel kernel, INetworkManager networkManager)
  53. {
  54. if (kernel == null)
  55. {
  56. throw new ArgumentNullException("kernel");
  57. }
  58. if (networkManager == null)
  59. {
  60. throw new ArgumentNullException("networkManager");
  61. }
  62. _kernel = kernel;
  63. _networkManager = networkManager;
  64. }
  65. /// <summary>
  66. /// Gets the registration status.
  67. /// </summary>
  68. /// <param name="feature">The feature.</param>
  69. /// <param name="mb2Equivalent">The MB2 equivalent.</param>
  70. /// <returns>Task{MBRegistrationRecord}.</returns>
  71. public async Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
  72. {
  73. return await MBRegistration.GetRegistrationStatus(feature, mb2Equivalent).ConfigureAwait(false);
  74. }
  75. /// <summary>
  76. /// Gets or sets the supporter key.
  77. /// </summary>
  78. /// <value>The supporter key.</value>
  79. public string SupporterKey
  80. {
  81. get { return MBRegistration.SupporterKey; }
  82. set
  83. {
  84. if (value != MBRegistration.SupporterKey)
  85. {
  86. MBRegistration.SupporterKey = value;
  87. // Clear this so it will re-evaluate
  88. ResetSupporterInfo();
  89. // And we'll need to restart to re-evaluate the status of plug-ins
  90. _kernel.NotifyPendingRestart();
  91. }
  92. }
  93. }
  94. /// <summary>
  95. /// Gets or sets the legacy key.
  96. /// </summary>
  97. /// <value>The legacy key.</value>
  98. public string LegacyKey
  99. {
  100. get { return MBRegistration.LegacyKey; }
  101. set
  102. {
  103. MBRegistration.LegacyKey = value;
  104. // And we'll need to restart to re-evaluate the status of plug-ins
  105. _kernel.NotifyPendingRestart();
  106. }
  107. }
  108. /// <summary>
  109. /// Resets the supporter info.
  110. /// </summary>
  111. private void ResetSupporterInfo()
  112. {
  113. _isMBSupporter = null;
  114. _isMBSupporterInitialized = false;
  115. }
  116. }
  117. }