2
0

BasePlugin.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using MediaBrowser.Common.Json;
  7. namespace MediaBrowser.Common.Plugins
  8. {
  9. public abstract class BasePlugin<TConfigurationType> : IPlugin
  10. where TConfigurationType : BasePluginConfiguration, new()
  11. {
  12. public string Path { get; set; }
  13. public TConfigurationType Configuration { get; private set; }
  14. private string ConfigurationPath
  15. {
  16. get
  17. {
  18. return System.IO.Path.Combine(Path, "config.js");
  19. }
  20. }
  21. public void Init()
  22. {
  23. Configuration = GetConfiguration();
  24. if (Configuration.Enabled)
  25. {
  26. InitInternal();
  27. }
  28. }
  29. protected abstract void InitInternal();
  30. private TConfigurationType GetConfiguration()
  31. {
  32. if (!File.Exists(ConfigurationPath))
  33. {
  34. return new TConfigurationType();
  35. }
  36. return JsonSerializer.Deserialize<TConfigurationType>(ConfigurationPath);
  37. }
  38. }
  39. public interface IPlugin
  40. {
  41. string Path { get; set; }
  42. void Init();
  43. }
  44. }