Esempio n. 1
0
        public ParameterStack GetInitializedParameterStack(IPlugin plugin)
        {
            // check if already available in cache
            ParameterStack stack = GetStackFromCache(plugin.Guid);

            if (null == stack)
            {
                if (!(SearchMethod is IComponentSearchMethod))
                {
                    throw new PluginException("Component loader was not initialized with a valid plugin search method.");
                }

                // get parameter stack
                if (plugin is IPluginExt1 pluginExt1)
                {
                    stack = plugin.Parameters;
                }
                else if (plugin is IPluginExt2 pluginExt2)
                {
                    stack = pluginExt2.BuildParameterStack(null);
                }
                else if (plugin is IPluginExt3 pluginExt3)
                {
                    stack = pluginExt3.BuildParameterStack(null);
                }
                else if (plugin is IPluginExt4 pluginExt4)
                {
                    stack = pluginExt4.BuildParameterStack(null);
                }
                // check parameter stack
                if (null == stack)
                {
                    throw new PluginException("Failed to build initial parameter stack.");
                }

                string grpId = string.Empty;

                // load parameter values from plugins
                foreach (Parameter param in stack)
                {
                    try
                    {
                        if (param is ParameterDouble pd)
                        {
                            stack.SetDoubleParameter(pd.Name, SearchMethod.GetDoubleParameterDefaultValue(grpId, plugin.Guid, pd.Name));
                        }
                        if (param is ParameterBool pb)
                        {
                            stack.SetBoolParameter(pb.Name, SearchMethod.GetBoolParameterDefaultValue(grpId, plugin.Guid, pb.Name));
                        }
                        if (param is ParameterInt pi)
                        {
                            stack.SetIntParameter(pi.Name, SearchMethod.GetIntParameterDefaultValue(grpId, plugin.Guid, pi.Name));
                        }
                        if (param is ParameterMulti pm)
                        {
                            stack.SetMultiParameter(pm.Name, SearchMethod.GetMultiParameterDefaultValue(grpId, plugin.Guid, pm.Name));
                        }
                    }
                    catch (Exception /*ex*/)
                    {
                    }
                }
                // save in cache
                InsertParameterStackInCache(plugin.Guid, stack);
            }
            return(stack.Clone());
        }
Esempio n. 2
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());
        }