Guest User

Untitled

a guest
Apr 25th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. ```CSharp
  2.  
  3. LoadPlugins<IStoreProvider>("载入数据访问插件", TCNCConsts.TcncPluginDir_DataAccess);
  4. LoadPlugins<IProtocolProvider>("载入协议支持插件", TCNCConsts.TcncPluginDir_Protocol);
  5.  
  6. /// <summary>
  7. /// 插件设置
  8. /// </summary>
  9. private void PluginSetting()
  10. {
  11. Notice.Notice("执行插件设置");
  12. Thread.Sleep(300);
  13. string priPath = "Plugins\\DataAccess;Plugins\\Protocol;";
  14. AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", priPath);
  15. AppDomain.CurrentDomain.SetData("BINPATH_PROBE_ONLY", priPath);
  16. var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
  17. var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
  18. m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", priPath });
  19. }
  20.  
  21. /// <summary>
  22. /// 载入插件
  23. /// </summary>
  24. private List<T> LoadPlugins<T>(string msg, string pluginDir) where T : class
  25. {
  26. Notice.Notice(msg);
  27. string storePluginDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pluginDir);
  28. var files = Directory.GetFiles(storePluginDir);
  29. List<T> stores = new List<T>();
  30. files.SafeForEach(file =>
  31. {
  32. if (file.EndsWith(".dll"))
  33. {
  34. Assembly ass = Assembly.LoadFrom(file);
  35. ass.GetTypes().SafeForEach(t =>
  36. {
  37. Type ti = typeof(T);
  38. if (ti.IsAssignableFrom(t))
  39. {
  40. var iStore = t.GetInstance() as T;
  41. stores.Add(iStore);
  42. }
  43. });
  44. }
  45. });
  46. return stores;
  47. }
  48.  
  49. ```
Add Comment
Please, Sign In to add comment