Guest User

Untitled

a guest
Jul 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. interface IServer{
  2. Void GetVersion();
  3. Void GetCapabilities();
  4. }
  5.  
  6. interface IPlugin{
  7. HResult CreatePlugin(IServer server, Iplugin plugin)
  8. }
  9.  
  10. interface IftpInterface : Iplugin {
  11. Void Login()
  12. Void Close()
  13. }
  14.  
  15. Public Class FtpLibrary : IftpInterface{
  16. Void Login();
  17. Void MakeDir();
  18. Void Close();
  19.  
  20. HResult CreatePlugin(IServer* server, Iplugin* plugin){
  21. FtpLibrary myFtpLibrary = new FtpLibrary();
  22. return myFtpLibrary; //maybe (new FtpLibrary())?
  23. }
  24. }
  25.  
  26. static void ReadPluginDirectory()
  27. {
  28. IFtpInteface iObj = default(IFtpInteface);
  29. //directory with dlls
  30. string pluginDir = Application.StartupPath + @"Plugins";
  31. {
  32. string[] files = Directory.GetFiles(pluginDir, "*.dll");
  33.  
  34. for (int i = 0; i < files.Length; i++)
  35. {
  36. try
  37. {
  38. //create Assembly class instance.
  39. Assembly asm = Assembly.LoadFile(files[0]);
  40. Type[] types = asm.GetTypes();
  41.  
  42. foreach (Type type in types)
  43. {
  44. if (type.IsClass && (type.FullName== "LibraryFtp.FTPLibrary"))
  45. {
  46. //classic class instance
  47. plugin = (IFtpInteface) asm.CreateInstance(type.FullName);
  48.  
  49. //LibraryFtp return result required method CreatePlugin
  50. value = (IFtpInteface)type.InvokeMember("CreatePlugin",
  51. BindingFlags.InvokeMethod | BindingFlags.Instance |
  52. BindingFlags.Public, null, plugin,
  53. new object[] {novyPlugin, novyServer});
  54. }
  55. iObj = (IFtpInteface)value;
  56.  
  57. {
  58. //add value to IList
  59. if (iObj != null)
  60. pluginy.Add(iObj);
  61. }
  62. }
  63. }
  64. catch (Exception e)
  65. {
  66. MessageBox.Show("Error reading plugin " + files[i] + ": " + e.Message, "FtpLibrary", MessageBoxButtons.OK, MessageBoxIcon.Error);
  67. }
  68. }
  69. }
  70. }
  71.  
  72. public static void Main(string[] args)
  73. {
  74. pluginy = new List<IFtpInteface>();
  75. ReadPluginDirectory();
  76.  
  77. //Vytvoříme si pole rozhraní všech pluginů, abychom jej pohli předat ostatním pluginům.
  78. IFtpInteface[] plugins = new IFtpInteface[pluginy.Count];
  79.  
  80. for (int x = 0; x < pluginy.Count; x++)
  81. {
  82. plugins[x] = (IFtpInteface)pluginy[x];
  83. }
  84.  
  85. var ftpClient = plugins[0]; //?????
  86.  
  87. try
  88. {
  89. ftpClient.Login();
  90. }
  91. catch (Exception ex)
  92. {
  93. throw new Exception(ex.Message);
  94. }
  95. }
Add Comment
Please, Sign In to add comment