Esempio n. 1
0
        private void btnAddFunctionPlugin_Click(object sender, EventArgs e)
        {
            string pluginName;
            string className;

            if (dlgPlugin.ShowDialog() != DialogResult.Cancel)
            {
                //Регистрируем плагин
                pluginName = dlgPlugin.FileName;
                className  = GetNumespaceName(pluginName);

                Assembly dll     = Assembly.LoadFrom(pluginName);
                Type     myClass = dll.GetType(className + "." + className);
                functionPlugin = (IFunctionPlugin)Activator.CreateInstance(myClass);

                //добавляем новую функциональность на форму
                Button btn = new Button();
                this.Controls.Add(btn);
                btn.Name   = "btn" + functionPlugin.GetFunctionPluginName();
                btn.Tag    = creatorList.Count - 1;
                btn.Click += btnPlugin_Click;
                btn.Width  = 196;
                btn.Height = 23;
                lastBtnPluginPosition.Y += 29;
                btn.Location             = lastBtnPluginPosition;
                btn.FlatStyle            = FlatStyle.System;
                btn.Text    = functionPlugin.GetFunctionPluginName();
                btn.Visible = true;
                btn.Show();
            }
        }
Esempio n. 2
0
        /// <summary>
        ///  Adds a plugin to this Env
        /// </summary>
        public void AddPlugin(IPlugin plugin)
        {
            if (plugin == null)
            {
                throw new ArgumentNullException("plugin");
            }

            _plugins.Add(plugin);

            IFunctionPlugin functionPlugin = plugin as IFunctionPlugin;

            if (functionPlugin != null)
            {
                foreach (KeyValuePair <string, Type> function in functionPlugin.GetFunctions())
                {
                    string functionName = function.Key.ToLowerInvariant();

                    if (_functionTypes.ContainsKey(functionName))
                    {
                        string message = string.Format("Function '{0}' already exists in environment but is added by plugin {1}",
                                                       functionName, plugin.GetName());
                        throw new InvalidOperationException(message);
                    }

                    AddFunction(functionName, function.Value);
                }
            }
        }
Esempio n. 3
0
        //Get an AlgoValue of type EmulatedFunction by supplying an external function load context.
        public AlgoValue GetEmulatedFuncValue(algoParser.Stat_loadFuncExtContext context)
        {
            //Attempt to get the text (as array) of the class and function from obj_access.
            if (context.particle().Length != 1)
            {
                Error.Fatal(context, "Import function is invalid, must be in the form \"Class.Function\".");
                return(null);
            }

            string className = context.IDENTIFIER()[1].GetText();
            string funcName  = context.particle()[0].IDENTIFIER().GetText();

            //Attempt to grab the plugin from the plugins manager.
            if (!PluginExists(className))
            {
                Error.Fatal(context, "Plugin name '" + className + "' is invalid or not loaded.");
                return(null);
            }
            IFunctionPlugin classPlugin = GetPlugin(className);

            //Does the plugin contain a function with the given name?
            if (classPlugin.Functions.FindIndex(x => x.Name == funcName) == -1)
            {
                Error.Fatal(context, "Plugin '" + className + "' does not contain a function of name '" + funcName + "', so cannot load it.");
                return(null);
            }

            //Return an EmulatedFunction AlgoValue.
            return(new AlgoValue()
            {
                Type = AlgoValueType.EmulatedFunction,
                Value = classPlugin.Functions.Find(x => x.Name == funcName)
            });
        }