PluginSecurityManager.cs 3.4 KB

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