コード例 #1
0
ファイル: Application.cs プロジェクト: webbasix/WBX.Engine
 public PlugingSetting(iPlugin plugin, string settingName, string environment, bool createEntry, string defaultEntry)
 {
     _plugin       = plugin;
     _settingName  = settingName;
     _environment  = environment;
     _createEntry  = createEntry;
     _defaultEntry = defaultEntry;
 }
コード例 #2
0
ファイル: Plugin.cs プロジェクト: webbasix/WBX.Engine
        public void Dispose()
        {
            if (_myInstance != null)
            {
                _myInstance.Deactivate();
                _myInstance.Dispose();
            }

            _myInstance = null;
        }
コード例 #3
0
ファイル: PlugInManager.cs プロジェクト: ianlessa/cashMiner
        public void SetState(string identifier, bool newState)
        {
            iPlugin target = plugIns.Find(x => x.Identifier.Equals(identifier));

            if (target != null)
            {
                target.Active = newState;
                config.AppSettings.Settings["plugin_" + target.Identifier].Value = newState ? "1" : "0";
                config.Save(ConfigurationSaveMode.Modified);
            }
        }
コード例 #4
0
ファイル: PlugInManager.cs プロジェクト: ianlessa/cashMiner
        public void Load()
        {
            plugIns = null;
            plugIns = new List <iPlugin>();
            if (Directory.Exists(plugInDir))
            {
                // This path is a directory
                string[] files = Directory.GetFiles(plugInDir);
                foreach (string file in files)
                {
                    AssemblyName assemblyName;
                    Assembly     assembly;
                    Type[]       types;
                    try
                    {
                        assemblyName = AssemblyName.GetAssemblyName(file);
                        assembly     = Assembly.Load(assemblyName);
                        types        = assembly.GetTypes();
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    if (types.Length != 1)
                    {
                        continue;
                    }
                    Type pluginType = types.ElementAt(0);


                    if (pluginType.GetInterfaces().Contains(typeof(iPlugin)) == false)
                    {
                        continue;//não é plugin.
                    }
                    if (pluginType.BaseType != typeof(PluginType))
                    {
                        continue; //não é do tipo específico deste gerenciador.
                    }

                    iPlugin plugIn = (iPlugin)Activator.CreateInstance(pluginType);
                    pluginType = null;
                    types      = null;

                    if (plugIns.Find(x => x.Identifier.Equals(plugIn.Identifier)) != null)
                    {
                        plugIn = null;
                        continue;
                    }

                    string strategyConfig = "plugin_" + plugIn.Identifier;
                    if (config.AppSettings.Settings[strategyConfig] == null)
                    {
                        config.AppSettings.Settings.Add(strategyConfig, "1");
                        config.Save(ConfigurationSaveMode.Modified);
                    }

                    string active = config.AppSettings.Settings[strategyConfig].Value;

                    if (active.Equals("1"))
                    {
                        plugIn.Active = true;
                    }
                    else
                    {
                        plugIn.Active = false;
                    }

                    plugIns.Add(plugIn);
                }
            }
            else
            {
            }
        }
コード例 #5
0
ファイル: Plugin.cs プロジェクト: webbasix/WBX.Engine
        private void init(string fileName, string nameSpace)
        {
            _myInstance     = null;
            _pluginIsLoaded = false;
            int count = 0;

            try
            {
                //--- make sure we found something
                if (fileName.Length > 0)
                {
                    //--- try load the assembly from the file
                    Assembly pluginAssembly = Assembly.LoadFrom(fileName);
                    //Logging.LogIt("\tLoading Assembly: " + fileName);
                    try
                    {
                        if (nameSpace.Trim().Length > 0)
                        {
                            Type singleType = pluginAssembly.GetType(nameSpace);
                            if (singleType != null)
                            {
                                Type typeInterface = singleType.GetInterface("WBXEngine.Manager.iPlugin", true);
                                if (typeInterface != null)
                                {
                                    //Logging.LogIt("\tAssembly Has Interface: " + fileName);

                                    _myInstance     = (iPlugin)Activator.CreateInstance(pluginAssembly.GetType(singleType.ToString()));
                                    _pluginIsLoaded = true;

                                    return;
                                    //Logging.LogIt("\t\tAssembly Loaded: " + fileName);
                                }
                                typeInterface = null;
                            }

                            //--- a namespace was specified but nothing was found
                            return;
                        }

                        //Next we'll loop through all the Types found in the assembly
                        foreach (Type pluginType in pluginAssembly.GetTypes())
                        {
                            if (pluginType.IsPublic)        //Only look at public types
                            {
                                if (!pluginType.IsAbstract) //Only look at non-abstract types
                                {
                                    //Gets a type object of the interface we need the plugins to match
                                    Type typeInterface = pluginType.GetInterface("WBXEngine.Manager.iPlugin", true);
                                    if (typeInterface != null)
                                    {
                                        //Logging.LogIt("\tAssembly Has Interface: " + fileName);

                                        _myInstance     = (iPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                                        _pluginIsLoaded = true;

                                        //Logging.LogIt("\t\tAssembly Loaded: " + fileName);
                                        return;
                                    }
                                    typeInterface = null;
                                }
                            }
                        }
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (Exception exSub in ex.LoaderExceptions)
                        {
                            sb.AppendLine(exSub.Message);
                            if (exSub is FileNotFoundException)
                            {
                                FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                                if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                                {
                                    sb.AppendLine("Fusion Log:");
                                    sb.AppendLine(exFileNotFound.FusionLog);
                                }
                            }
                            sb.AppendLine();
                        }
                        string errorMessage = sb.ToString();
                        //Display or log the error based on your application.

                        if (ex is System.Reflection.ReflectionTypeLoadException)
                        {
                            var typeLoadException = ex as ReflectionTypeLoadException;
                            var loaderExceptions  = typeLoadException.LoaderExceptions;
                        }



                        //Logging.LogIt("\tError Loading Assembly: " + fileName);
                    }
                    finally
                    {
                        pluginAssembly = null;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
コード例 #6
0
ファイル: Application.cs プロジェクト: webbasix/WBX.Engine
 public PlugingSetting(iPlugin plugin, string settingName)
 {
     //--- get the plugin name only, (remove any version info)
     _plugin      = plugin;
     _settingName = settingName;
 }