终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 regels
1002 B

  1. using BPA.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.Business
  8. {
  9. public class Plugin : Singleton<Plugin>, IDisposable
  10. {
  11. private List<IPlugin> plugins = new List<IPlugin>();
  12. public void Dispose()
  13. {
  14. plugins.ForEach(p => p.Dispose());
  15. }
  16. public void Init()
  17. {
  18. this.GetType().Assembly.GetTypes().ToList().ForEach(plugin =>
  19. {
  20. if (plugin.GetInterfaces().Contains(typeof(IPlugin)))
  21. {
  22. plugins.Add((IPlugin)Activator.CreateInstance(plugin));
  23. }
  24. });
  25. plugins.ForEach(p => {
  26. p.Initialize();
  27. p.Start();
  28. });
  29. }
  30. public T GetPlugin<T>() where T : IPlugin
  31. {
  32. return (T)plugins.FirstOrDefault(p => p.GetType().Equals(typeof(T)));
  33. }
  34. }
  35. }