Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface IServer{
- Void GetVersion();
- Void GetCapabilities();
- }
- interface IPlugin{
- HResult CreatePlugin(IServer server, Iplugin plugin)
- }
- interface IftpInterface : Iplugin {
- Void Login()
- Void Close()
- }
- Public Class FtpLibrary : IftpInterface{
- Void Login();
- Void MakeDir();
- Void Close();
- HResult CreatePlugin(IServer* server, Iplugin* plugin){
- FtpLibrary myFtpLibrary = new FtpLibrary();
- return myFtpLibrary; //maybe (new FtpLibrary())?
- }
- }
- static void ReadPluginDirectory()
- {
- IFtpInteface iObj = default(IFtpInteface);
- //directory with dlls
- string pluginDir = Application.StartupPath + @"Plugins";
- {
- string[] files = Directory.GetFiles(pluginDir, "*.dll");
- for (int i = 0; i < files.Length; i++)
- {
- try
- {
- //create Assembly class instance.
- Assembly asm = Assembly.LoadFile(files[0]);
- Type[] types = asm.GetTypes();
- foreach (Type type in types)
- {
- if (type.IsClass && (type.FullName== "LibraryFtp.FTPLibrary"))
- {
- //classic class instance
- plugin = (IFtpInteface) asm.CreateInstance(type.FullName);
- //LibraryFtp return result required method CreatePlugin
- value = (IFtpInteface)type.InvokeMember("CreatePlugin",
- BindingFlags.InvokeMethod | BindingFlags.Instance |
- BindingFlags.Public, null, plugin,
- new object[] {novyPlugin, novyServer});
- }
- iObj = (IFtpInteface)value;
- {
- //add value to IList
- if (iObj != null)
- pluginy.Add(iObj);
- }
- }
- }
- catch (Exception e)
- {
- MessageBox.Show("Error reading plugin " + files[i] + ": " + e.Message, "FtpLibrary", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
- public static void Main(string[] args)
- {
- pluginy = new List<IFtpInteface>();
- ReadPluginDirectory();
- //Vytvoříme si pole rozhraní všech pluginů, abychom jej pohli předat ostatním pluginům.
- IFtpInteface[] plugins = new IFtpInteface[pluginy.Count];
- for (int x = 0; x < pluginy.Count; x++)
- {
- plugins[x] = (IFtpInteface)pluginy[x];
- }
- var ftpClient = plugins[0]; //?????
- try
- {
- ftpClient.Login();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
Add Comment
Please, Sign In to add comment