PluginSecurityManager.cs 3.4 KB

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