コード例 #1
0
ファイル: PluginUtils.cs プロジェクト: hessonsu/bdhero
        public static void SavePreferences(PluginAssemblyInfo assemblyInfo, Object prefs)
        {
            var json      = JsonConvert.SerializeObject(prefs, Formatting.Indented);
            var directory = Path.GetDirectoryName(assemblyInfo.ConfigFilePath);

            if (directory != null)
            {
                Directory.CreateDirectory(directory);
            }
            File.WriteAllText(assemblyInfo.ConfigFilePath, json);
        }
コード例 #2
0
        private void AddPlugin(string dllPath)
        {
            // Create a new assembly from the plugin file we're adding..
            Assembly pluginAssembly = Assembly.LoadFrom(dllPath);

            var guid = AssemblyUtils.Guid(pluginAssembly);

            foreach (var plugin in _repository.PluginsByType)
            {
                if (plugin.AssemblyInfo.Guid == guid)
                {
                    return; // avoid loading duplicated plugin.dll file
                }
            }

            var machineName = Path.GetFileNameWithoutExtension(dllPath) ?? pluginAssembly.GetName().Name ?? "";

            machineName = Regex.Replace(machineName, "Plugin$", "", RegexOptions.IgnoreCase);
            var configFileName = machineName + ".config.json";
            var configFilePath = Path.Combine(_directoryLocator.PluginConfigDir, machineName, configFileName);

            var disabledGuids = _preferenceManager.Preferences.Plugins.DisabledPluginGuids;

            // Next we'll loop through all the Types found in the assembly
            foreach (Type pluginType in pluginAssembly.GetTypes().Where(IsValidPlugin))
            {
                // Create a new instance and store the instance in the collection for later use
                // We could change this later on to not load an instance.. we have 2 options
                // 1- Make one instance, and use it whenever we need it.. it's always there
                // 2- Don't make an instance, and instead make an instance whenever we use it, then close it
                // For now we'll just make an instance of all the plugins
                var newPlugin = (IPlugin)_kernel.Get(pluginType);

                // TODO: Store this in preferences file
                newPlugin.Enabled = !disabledGuids.Contains(guid);

                var assemblyInfo = new PluginAssemblyInfo(dllPath,
                                                          AssemblyUtils.GetAssemblyVersion(pluginAssembly),
                                                          AssemblyUtils.GetLinkerTimestamp(pluginAssembly),
                                                          guid,
                                                          configFilePath);

                // Initialize the plugin
                newPlugin.LoadPlugin(_repository, assemblyInfo);

                // Add the new plugin to our collection here
                _repository.Add(newPlugin);
            }
        }
コード例 #3
0
ファイル: PluginUtils.cs プロジェクト: hessonsu/bdhero
 public static T GetPreferences <T>(PluginAssemblyInfo assemblyInfo, TypeFactory <T> defaultFactory)
 {
     if (File.Exists(assemblyInfo.ConfigFilePath))
     {
         try
         {
             var json = File.ReadAllText(assemblyInfo.ConfigFilePath);
             return(JsonConvert.DeserializeObject <T>(json));
         }
         catch (Exception e)
         {
             Logger.WarnFormat("Unable to deserialize settings file: {0}", e);
         }
     }
     return(defaultFactory());
 }
コード例 #4
0
ファイル: IsanPlugin.cs プロジェクト: bdhero/bdhero-fat
 public void LoadPlugin(IPluginHost host, PluginAssemblyInfo assemblyInfo)
 {
     Host = host;
     AssemblyInfo = assemblyInfo;
 }
コード例 #5
0
ファイル: PluginService.cs プロジェクト: JGTM2016/bdhero
        private void AddPlugin(string dllPath)
        {
            // Create a new assembly from the plugin file we're adding..
            Assembly pluginAssembly = Assembly.LoadFrom(dllPath);

            var guid = AssemblyUtils.Guid(pluginAssembly);

            var machineName = Path.GetFileNameWithoutExtension(dllPath) ?? pluginAssembly.GetName().Name ?? "";
            machineName = Regex.Replace(machineName, "Plugin$", "", RegexOptions.IgnoreCase);
            var configFileName = machineName + ".config.json";
            var configFilePath = Path.Combine(_directoryLocator.PluginConfigDir, machineName, configFileName);

            var disabledGuids = _preferenceManager.Preferences.Plugins.DisabledPluginGuids;

            // Next we'll loop through all the Types found in the assembly
            foreach (Type pluginType in pluginAssembly.GetTypes().Where(IsValidPlugin))
            {
                // Create a new instance and store the instance in the collection for later use
                // We could change this later on to not load an instance.. we have 2 options
                // 1- Make one instance, and use it whenever we need it.. it's always there
                // 2- Don't make an instance, and instead make an instance whenever we use it, then close it
                // For now we'll just make an instance of all the plugins
                var newPlugin = (IPlugin) _kernel.Get(pluginType);

                // TODO: Store this in preferences file
                newPlugin.Enabled = !disabledGuids.Contains(guid);

                var assemblyInfo = new PluginAssemblyInfo(dllPath,
                                                          AssemblyUtils.GetAssemblyVersion(pluginAssembly),
                                                          AssemblyUtils.GetLinkerTimestamp(pluginAssembly),
                                                          guid,
                                                          configFilePath);

                // Initialize the plugin
                newPlugin.LoadPlugin(_repository, assemblyInfo);

                // Add the new plugin to our collection here
                _repository.Add(newPlugin);
            }
        }