コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: Marbax/SP
        private void FindPluginsAsync()
        {
            _plugins.Clear();
            string[] libs = Directory.GetFiles(_plaginDir, "*.dll");

            Parallel.ForEach(libs, (lib) =>
            {
                try
                {
                    Assembly assembly = Assembly.LoadFile(lib);

                    List <Type> types = assembly.GetTypes().Where(t => t.GetInterfaces().Where(i => i.FullName == typeof(Interface.IPlugin).FullName).Any()).ToList();

                    types.ForEach(type =>
                    {
                        Interface.IPlugin plugin = (Interface.IPlugin)Activator.CreateInstance(type);
                        _plugins.Add(plugin.Name, plugin);
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Plugin load exception\n" + ex.Message);
                }
            });
        }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: Marbax/SP
 public bool PluginRun(string pluginName, Interface.IModel runOn)
 {
     try
     {
         Interface.IPlugin plugin = (Interface.IPlugin)_plugins[pluginName];
         lock (_locker)
         {
             plugin.Transform(runOn);
         }
         return(true);
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Plugin {pluginName} isn't awailable at this very moment.\n {ex.Message}");
         return(false);
     }
 }