internal Component(IPlugin instance) { Plugin = instance; // depending on plugin interface version, an other interface might be available if (Plugin.GetType().GetInterface("Pic.Plugin.IPluginExt1") != null) { _ext1 = Plugin as IPluginExt1; } else if (Plugin.GetType().GetInterface("Pic.Plugin.IPluginExt2") != null) { _ext2 = Plugin as IPluginExt2; } else if (Plugin.GetType().GetInterface("Pic.Plugin.IPluginExt3") != null) { _ext3 = Plugin as IPluginExt3; } else if (Plugin.GetType().GetInterface("Pic.Plugin.IPluginExt4") != null) { _ext4 = Plugin as IPluginExt4; } else { throw new PluginException(string.Format("Failed to load plugin {0}\nOne of the following interface is expected: \n{1}" , Plugin.Name , "Pic.Plugin.IPluginExt1\nPic.Plugin.IPluginExt2\nPic.Plugin.IPluginExt3")); } }
public ParameterStack GetInitializedParameterStack(IPlugin plugin) { // check if already available in cache ParameterStack stack = null; stack = ComponentLoader.GetStackFromCache(plugin.Guid); if (null == stack) { if (!(_searchMethod is IComponentSearchMethod)) { throw new PluginException("Component loader was not initialized with a valid plugin search method."); } IPluginExt1 pluginExt1 = plugin as IPluginExt1; IPluginExt2 pluginExt2 = plugin as IPluginExt2; IPluginExt3 pluginExt3 = plugin as IPluginExt3; // get parameter stack if (null != pluginExt1) { stack = plugin.Parameters; } else if (null != pluginExt2) { stack = pluginExt2.BuildParameterStack(null); } else if (null != pluginExt3) { stack = pluginExt3.BuildParameterStack(null); } // check parameter stack if (null == stack) { throw new PluginException("Failed to build initial parameter stack."); } // load parameter values from plugins foreach (Parameter param in stack) { try { ParameterDouble pd = param as ParameterDouble; if (null != pd) { stack.SetDoubleParameter(pd.Name, _searchMethod.GetDoubleParameterDefaultValue(plugin.Guid, pd.Name)); } ParameterBool pb = param as ParameterBool; if (null != pb) { stack.SetBoolParameter(pb.Name, _searchMethod.GetBoolParameterDefaultValue(plugin.Guid, pb.Name)); } ParameterInt pi = param as ParameterInt; if (null != pi) { stack.SetIntParameter(pi.Name, _searchMethod.GetIntParameterDefaultValue(plugin.Guid, pi.Name)); } ParameterMulti pm = param as ParameterMulti; if (null != pm) { stack.SetMultiParameter(pm.Name, _searchMethod.GetMultiParameterDefaultValue(plugin.Guid, pm.Name)); } } catch (Exception /*ex*/) { } } // save in cache ComponentLoader.InsertParameterStackInCache(plugin.Guid, stack); } return(stack.Clone()); }
internal Component(IPlugin instance) { _instance = instance; // depending on plugin interface version, an other interface might be available if (_instance.GetType().GetInterface("Pic.Plugin.IPluginExt1") != null) _ext1 = _instance as IPluginExt1; else if (_instance.GetType().GetInterface("Pic.Plugin.IPluginExt2") != null) _ext2 = _instance as IPluginExt2; else if (_instance.GetType().GetInterface("Pic.Plugin.IPluginExt3") != null) _ext3 = _instance as IPluginExt3; else throw new PluginException(string.Format("Failed to load plugin {0}\nOne of the following interface is expected: \n{1}" , _instance.Name , "Pic.Plugin.IPluginExt1\nPic.Plugin.IPluginExt2\nPic.Plugin.IPluginExt3")); }