Example #1
0
        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());
        }