/// <param name="compilerVersion">Defaults to 'v4.0'</param>
        public static Assembly CompilePluginIntoAssembly(PluginClass plugin, string compilerVersion = null)
        {
            if (plugin == null)
            {
                throw new ArgumentNullException("plugin", "PluginClass is required");
            }
            if (string.IsNullOrWhiteSpace(plugin.Name))
            {
                throw new ArgumentException("Plugin name is required");
            }

            var sourceCode = ClassGenerator.GetClassAsString(plugin);
            var provider   = new CSharpCodeProvider(new Dictionary <string, string> {
                { "CompilerVersion", compilerVersion ?? "v4.0" }
            });
            var cp = new CompilerParameters();

            cp.ReferencedAssemblies.Add("Plugin.Interfaces.dll");
            cp.GenerateExecutable = false;
            cp.OutputAssembly     = plugin.Name + ".dll";
            cp.GenerateInMemory   = true;
            CompilerResults cr = provider.CompileAssemblyFromSource(cp, sourceCode);

            if (cr.Errors.Count > 0)
            {
                throw new PluginCompilationException(cr.Errors, "Plugin " + plugin.Name + "failed compilation");
            }
            return(cr.CompiledAssembly);
        }
        public void GetClassContent_Name_Namespace_TwoUsingClauses()
        {
            PluginClass testClass = new PluginClass()
            {
                Name         = "Heippa",
                Namespace    = "Joel.Testar",
                UsingClauses = new List <UsingClause>()
                {
                    new UsingClause()
                    {
                        Name = "System"
                    },
                    new UsingClause()
                    {
                        Name = "System.Collections.Generic"
                    },
                }
            };

            var expected = "using System;\nusing System.Collections.Generic;\nnamespace Joel.Testar\n{\n\tpublic class Heippa\n\t{\n\t}\n}\n";

            var actual = ClassGenerator.GetClassAsString(testClass);

            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        private TreeNode CreateNodeFromPlugin(PluginClass plugin)
        {
            var node = new TreeNode()
            {
                Text = string.Format("{0} {1}", plugin.Name, plugin.Version.ToString()),
            };

            node.Nodes.Add(plugin.Details);
            node.Nodes.Add(string.Format("Copyright©{0}", plugin.Copyright));

            if (plugin.ThirdPartyLicenses is LicenseInfo[] infos)
            {
                foreach (var info in infos)
                {
                    var node_l = new TreeNode(info.Name);

                    if ((info.Homepage != null) && (info.Homepage.Length > 0))
                    {
                        node_l.Nodes.Add(info.Homepage);
                    }
                    if ((info.LicenseName != null) && (info.LicenseName.Length > 0))
                    {
                        node_l.Nodes.Add(info.LicenseName);
                    }

                    node.Nodes.Add(node_l);
                }
            }

            return(node);
        }
        public bool Unload()
        {
            try
            {
                if (!Enabled)
                {
                    return(true);
                }

                PointBlankLogging.Log("Stopping " + Name + "...");

                SaveConfiguration();                                                               // Save the configuration
                SaveTranslation();                                                                 // Save the translation
                PointBlankPluginEvents.RunPluginStop(PluginClass);                                 // Run the stop event
                PluginClass.Unload();                                                              // Run the unload function
                PointBlankPluginEvents.RunPluginUnloaded(PluginClass);                             // Run the unloaded event

                Enviroment.runtimeObjects["Plugins"].RemoveCodeObject(PluginClass.GetType().Name); // Remove the plugin from gameobject

                Enabled = false;                                                                   // Set the enabled to false
                t.Abort();                                                                         // Abort the thread
                return(true);
            }
            catch (Exception ex)
            {
                PointBlankLogging.LogError("Error stopping plugin: " + Name, ex);
                return(false);
            }
        }
Exemple #5
0
    public float GetHighscore()
    {
        AndroidJavaObject activity  = PluginClass.GetStatic <AndroidJavaObject>("mainActivity");
        float             highscore = PluginInstance.Call <float>("readHighscore", activity);

        return(highscore);
    }
        public bool WriteClassToFile(PluginClass classToWrite, out string filePath, Encoding encoding)
        {
            if (classToWrite == null)
            {
                throw new ArgumentNullException("classToWrite", "RootClass is required");
            }
            if (_outputFolder == null)
            {
                throw new NullReferenceException("Target Directory is required");
            }
            try
            {
                var fileName     = classToWrite.Name + ".cs";
                var fileContents = ClassGenerator.GetClassAsString(classToWrite);
                var writePath    = Path.Combine(_outputFolder.FullName, fileName);

                File.WriteAllText(writePath, fileContents, encoding);

                filePath = writePath;
                return(true);
            }
            catch (Exception)
            {
                filePath = null;
                return(false);
            }
        }
Exemple #7
0
        private void treePlugin_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Tag != null)
            {
                PluginClass pc   = (PluginClass)e.Node.Tag;
                string      path = null;
                if (pc.plugintype == "WebModulePlugin")
                {
                    path = CommonHelper.WebPlatformPath + "\\" + pc.path;
                }
                else if (pc.plugintype == "WinformModulePlugin")
                {
                    path = CommonHelper.WinformPlatformPath + "\\" + pc.path;
                }
                else if (pc.plugintype == "WcfModulePlugin")
                {
                    path = CommonHelper.WinformPlatformPath + "\\" + pc.path;
                }

                pluginxmlClass plugin = null;
                if (File.Exists(path))
                {
                    PluginXmlManage.pluginfile = path;
                    plugin = PluginXmlManage.getpluginclass();
                }

                if (plugin != null)
                {
                    gridpluginmenu.AutoGenerateColumns = false;
                    gridpluginmenu.DataSource          = plugin.menu;
                }
            }
        }
Exemple #8
0
        private void 编译ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (griddev.CurrentCell == null)
            {
                return;
            }
            string retmsg = "";

            try
            {
                List <PluginClass> plist = griddev.DataSource as List <PluginClass>;
                PluginClass        pc    = plist[griddev.CurrentCell.RowIndex];
                FileInfo           file  = null;
                if (pc.plugintype == "WinformModulePlugin" || pc.plugintype == "WcfModulePlugin")
                {
                    file = new FileInfo(CommonHelper.WinformPlatformPath + "\\" + pc.path);
                }
                else if (pc.plugintype == "WebModulePlugin")
                {
                    file = new FileInfo(CommonHelper.WebPlatformPath + "\\" + pc.path);
                }
                string slnpath = file.Directory.FullName + "\\EFW_" + pc.name + ".sln";
                retmsg = MsBuildCommand.Build(slnpath);

                loadTitle();
                MessageBoxEx.Show("编译成功!\r\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception err)
            {
                MessageBoxEx.Show("编译失败!\r\n" + err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #9
0
        private static PluginClass PreProcess(PluginClass classToProcess)
        {
            if (string.IsNullOrWhiteSpace(classToProcess.Name))
            {
                throw new NullReferenceException("Missing Class Name");
            }
            if (string.IsNullOrWhiteSpace(classToProcess.Namespace))
            {
                throw new NullReferenceException("Missing Class Namespace");
            }

            var preProcessedClass = classToProcess.Clone();

            if (preProcessedClass.UsingClauses == null)
            {
                preProcessedClass.UsingClauses = new List <UsingClause>();
            }
            if (preProcessedClass.Methods == null)
            {
                preProcessedClass.Methods = new List <Method>();
            }
            if (preProcessedClass.Interfaces == null)
            {
                preProcessedClass.Interfaces = new List <Interface>();
            }

            return(preProcessedClass);
        }
Exemple #10
0
        //打开所在目录
        private void btnexplorer_Click(object sender, EventArgs e)
        {
            if (griddev.CurrentCell == null)
            {
                return;
            }
            List <PluginClass> plist     = griddev.DataSource as List <PluginClass>;
            PluginClass        pc        = plist[griddev.CurrentCell.RowIndex];
            string             dirplugin = "";

            if (pc.plugintype == "WinformModulePlugin" || pc.plugintype == "WcfModulePlugin")
            {
                FileInfo finfo = new FileInfo(CommonHelper.WinformPlatformPath + "\\" + pc.path);
                if (finfo.Exists)
                {
                    dirplugin = finfo.Directory.FullName;
                }
            }
            else if (pc.plugintype == "WebModulePlugin")
            {
                FileInfo finfo = new FileInfo(CommonHelper.WebPlatformPath + "\\" + pc.path);
                if (finfo.Exists)
                {
                    dirplugin = finfo.Directory.FullName;
                }
            }
            if (dirplugin != "")
            {
                CommonHelper.ShellExecute(IntPtr.Zero, "open", "explorer.exe", dirplugin, "", CommonHelper.ShowCommands.SW_NORMAL);
            }
        }
Exemple #11
0
        void app_BeforeDocumentSave(Document doc)
        {
            if (griddev.CurrentCell == null)
            {
                return;
            }

            List <PluginClass> plist = griddev.DataSource as List <PluginClass>;
            PluginClass        pc    = plist[griddev.CurrentCell.RowIndex];
            string             path  = string.Empty;

            if (pc.plugintype == "WebModulePlugin")
            {
                path = CommonHelper.WebPlatformPath + "\\" + pc.path;
            }
            else if (pc.plugintype == "WinformModulePlugin")
            {
                path = CommonHelper.WinformPlatformPath + "\\" + pc.path;
            }
            else if (pc.plugintype == "WcfModulePlugin")
            {
                path = CommonHelper.WinformPlatformPath + "\\" + pc.path;
            }
            string docpic = new FileInfo(path).DirectoryName + "_pic";

            if (!Directory.Exists(docpic))
            {
                Directory.CreateDirectory(docpic);
            }
            foreach (Page page in doc.Pages)
            {
                page.Export(docpic + "\\" + page.Name + ".jpg");
            }
        }
Exemple #12
0
        private static string MakeClassString(PluginClass classToConvert)
        {
            var classContents = new StringBuilder();

            foreach (var statement in classToConvert.UsingClauses)
            {
                classContents.Append("using " + statement.Name + ";\n");
            }

            classContents.Append("namespace " + classToConvert.Namespace + "\n");
            classContents.Append("{\n");

            classContents.Append(string.Format("\t{0} class {1}", classToConvert.AccessModifier.GetString(), classToConvert.Name));
            classContents.Append(MakeClassInheritenceString(classToConvert));
            classContents.Append("\n\t{\n");

            foreach (var method in classToConvert.Methods)
            {
                classContents.Append(MakeMethodString(method));
            }

            classContents.Append("\t}\n");
            classContents.Append("}\n");

            return(classContents.ToString());
        }
Exemple #13
0
        private static string MakeClassInheritenceString(PluginClass classToConvert)
        {
            var inheritence   = new StringBuilder();
            var hasBaseClass  = !string.IsNullOrWhiteSpace(classToConvert.BaseClassName);
            var hasInterfaces = classToConvert.Interfaces.Count() > 0;

            if (hasBaseClass || hasInterfaces)
            {
                inheritence.Append(":");

                if (hasBaseClass)
                {
                    inheritence.Append(classToConvert.BaseClassName);
                    if (hasInterfaces)
                    {
                        inheritence.Append(",");
                    }
                }
                foreach (var mInterface in classToConvert.Interfaces)
                {
                    inheritence.Append(mInterface.Name + ",");
                }
            }

            var inheritenceString = inheritence.ToString();

            if (inheritenceString.Contains(','))
            {
                inheritenceString = inheritenceString.Remove(inheritenceString.LastIndexOf(','));
            }
            return(inheritenceString);
        }
Exemple #14
0
        private void tsRun2_Click(object sender, EventArgs e)
        {
            if (griddev.CurrentCell == null)
            {
                return;
            }
            List <PluginClass> plist = griddev.DataSource as List <PluginClass>;
            PluginClass        pc    = plist[griddev.CurrentCell.RowIndex];

            if (pc.plugintype == "WinformModulePlugin" || pc.plugintype == "WcfModulePlugin")
            {
                if (pc.name != entryplugin)
                {
                    FrmDevSetting frmdev = new FrmDevSetting();
                    frmdev.ShowDialog();
                    loadTitle();
                    return;
                }

                if (pc.plugintype == "WcfModulePlugin")
                {
                    CommonHelper.OpenProcess(CommonHelper.AppRootPath + "\\WCF服务主机.bat");
                }
                CommonHelper.OpenProcess(CommonHelper.AppRootPath + "\\EFWWin.bat");
            }
            else if (pc.plugintype == "WebModulePlugin")
            {
                CommonHelper.OpenProcess(CommonHelper.AppRootPath + "\\NetWebServer.exe");
            }
        }
        public void GetClassContent_Name_Namespace_BaseClass_TwoInterfaces()
        {
            PluginClass testClass = new PluginClass()
            {
                Name          = "Heippa",
                Namespace     = "Joel.Testar",
                BaseClassName = "TestClassBase",
                Interfaces    = new List <Interface>()
                {
                    new Interface()
                    {
                        Name = "FirstInterface"
                    },
                    new Interface()
                    {
                        Name = "SecondInterface"
                    }
                }
            };

            var expected = "namespace Joel.Testar\n{\n\tpublic class Heippa:TestClassBase,FirstInterface,SecondInterface\n\t{\n\t}\n}\n";

            var actual = ClassGenerator.GetClassAsString(testClass);

            Assert.AreEqual(expected, actual);
        }
        public void GetClassContent_Method_TwoParameters_NoStatements()
        {
            Method MoveMouse = new Method()
            {
                Name           = "DoMoveMouse",
                AccessModifier = AccessModifierEnum.INTERNAL,
                ReturnType     = null,
                Parameters     = new List <MethodParameter>()
                {
                    new MethodParameter()
                    {
                        Name = "xPos", ParamType = typeof(int)
                    },
                    new MethodParameter()
                    {
                        Name = "yPos", ParamType = typeof(int)
                    }
                }
            };
            PluginClass testClass = new PluginClass()
            {
                Name      = "Heippa",
                Namespace = "Joel.Testar",
                Methods   = new List <Method>()
                {
                    MoveMouse
                }
            };

            var expected = "namespace Joel.Testar\n{\n\tpublic class Heippa\n\t{\n\t\tinternal void DoMoveMouse(int xPos,int yPos)\n\t\t{\n\t\t}\n\t}\n}\n";

            var actual = ClassGenerator.GetClassAsString(testClass);

            Assert.AreEqual(expected, actual);
        }
        public FrmPluginConfigEdit(PluginClass pc)
        {
            InitializeComponent();
            _pc = pc;
            loadplugin(pc);

            txtmenupn.Text = pc.name;
        }
Exemple #18
0
        public FrmPack(PluginClass pc)
        {
            InitializeComponent();
            this.txtname.Text       = pc.name;
            this.txttitle.Text      = pc.title;
            this.txtupdatedate.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


            if (pc.plugintype == "WebModulePlugin")
            {
                plugintype = "web";
                path       = CommonHelper.WebPlatformPath + "\\" + pc.path;
            }
            else if (pc.plugintype == "WinformModulePlugin")
            {
                plugintype = "winform";
                path       = CommonHelper.WinformPlatformPath + "\\" + pc.path;
            }
            else if (pc.plugintype == "WcfModulePlugin")
            {
                plugintype = "wcf";
                path       = CommonHelper.WinformPlatformPath + "\\" + pc.path;
            }

            FileInfo finfo = new FileInfo(path);

            if (finfo.Exists)
            {
                prjpath = finfo.Directory.FullName;
                prjname = finfo.Directory.Name;
            }


            PluginXmlManage.pluginfile = path;
            plugin = PluginXmlManage.getpluginclass();
            if (pc.name != plugin.name)
            {
                MessageBoxEx.Show("plugin.xml 与 pluginsys.xml 的名称不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            txtname.Text         = plugin.name;
            txttitle.Text        = plugin.title;
            txtauthor.Text       = plugin.author;
            txtversion.Text      = plugin.version;
            txtintroduction.Text = plugin.data.FindIndex(x => x.key == "introduction") > -1 ? plugin.data.Find(x => x.key == "introduction").value : "";
            txtupdaterecord.Text = plugin.data.FindIndex(x => x.key == "updaterecord") > -1 ? plugin.data.Find(x => x.key == "updaterecord").value : "";
            if (plugin.data.FindIndex(x => x.key == "headpic") > -1 && plugin.data.Find(x => x.key == "headpic").value != "")
            {
                //pb_headpic.Image = Image.FromFile(prjpath + "\\" + plugin.data.Find(x => x.key == "headpic").value);
                pb_headpic.Tag = plugin.data.Find(x => x.key == "headpic").value;
            }
            else
            {
                pb_headpic.Tag = "/ModulePlugin/efwplus_website/headpic/default.png";
            }
            txtStartItem.Text = plugin.data.FindIndex(x => x.key == "StartItem") > -1 ? plugin.data.Find(x => x.key == "StartItem").value : "";
        }
Exemple #19
0
        //将菜单设置为启动项
        private void btnSetstartitem_Click(object sender, EventArgs e)
        {
            //FrmDevSetting setting = new FrmDevSetting();
            //setting.ShowDialog();

            if (gridpluginmenu.CurrentCell == null)
            {
                return;
            }
            if (treePlugin.SelectedNode == null || treePlugin.SelectedNode.Tag == null)
            {
                return;
            }
            PluginClass pc = (PluginClass)treePlugin.SelectedNode.Tag;

            List <menuClass> mlist = gridpluginmenu.DataSource as List <menuClass>;
            menuClass        menu  = mlist[gridpluginmenu.CurrentCell.RowIndex];

            if (pc.plugintype == "WebModulePlugin")
            {
                string      netwebserver     = CommonHelper.AppRootPath + "\\NetWebServer.exe.config";
                XmlDocument xmlDoc_webserver = new System.Xml.XmlDocument();
                xmlDoc_webserver.Load(netwebserver);
                XmlNode node = xmlDoc_webserver.DocumentElement.SelectSingleNode("appSettings/add[@key='defaultpage']");
                node.Attributes["value"].Value = menu.menupath;
                xmlDoc_webserver.Save(netwebserver);
            }
            else if (pc.plugintype == "WinformModulePlugin")
            {
                string      pluginsysFile = CommonHelper.WinformPlatformPath + "\\Config\\pluginsys.xml";
                string      appconfig     = CommonHelper.WinformPlatformPath + "\\EFWWin.exe.config";
                XmlDocument xmlDoc_app    = new System.Xml.XmlDocument();
                xmlDoc_app.Load(appconfig);
                PluginSysManage.pluginsysFile = pluginsysFile;
                XmlNode node = xmlDoc_app.DocumentElement.SelectSingleNode("appSettings/add[@key='ClientType']");
                node.Attributes["value"].Value = "Winform";
                xmlDoc_app.Save(appconfig);
                PluginSysManage.SetWinformEntry(menu.pluginname, menu.viewname == "" ? menu.controllername : menu.controllername + "|" + menu.viewname);
            }
            else if (pc.plugintype == "WcfModulePlugin")
            {
                string      pluginsysFile = CommonHelper.WinformPlatformPath + "\\Config\\pluginsys.xml";
                string      appconfig     = CommonHelper.WinformPlatformPath + "\\EFWWin.exe.config";
                XmlDocument xmlDoc_app    = new System.Xml.XmlDocument();
                xmlDoc_app.Load(appconfig);
                PluginSysManage.pluginsysFile = pluginsysFile;
                XmlNode node = xmlDoc_app.DocumentElement.SelectSingleNode("appSettings/add[@key='ClientType']");
                node.Attributes["value"].Value = "WCFClient";
                xmlDoc_app.Save(appconfig);
                PluginSysManage.SetWcfClientEntry(menu.pluginname, menu.viewname == "" ? menu.controllername : menu.controllername + "|" + menu.viewname);
            }

            MessageBoxEx.Show("设置启动项成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #20
0
        public static string GetClassAsString(PluginClass classToWrite)
        {
            if (classToWrite == null)
            {
                throw new ArgumentNullException("classToWrite", "SUG MIN KUK is required");
            }

            var preProcessedClass = PreProcess(classToWrite);

            return(MakeClassString(preProcessedClass));
        }
Exemple #21
0
        private void btnCode_Click(object sender, EventArgs e)
        {
            if (griddev.CurrentCell == null)
            {
                return;
            }
            List <PluginClass> plist = griddev.DataSource as List <PluginClass>;
            PluginClass        pc    = plist[griddev.CurrentCell.RowIndex];
            FrmCodeMaker       code  = new FrmCodeMaker(pc);

            code.ShowDialog();
        }
        private void loadplugin(PluginClass pc)
        {
            if (pc.plugintype == "WebModulePlugin")
            {
                path = CommonHelper.WebPlatformPath + "\\" + pc.path;
            }
            else if (pc.plugintype == "WinformModulePlugin")
            {
                path = CommonHelper.WinformPlatformPath + "\\" + pc.path;
            }
            else if (pc.plugintype == "WcfModulePlugin")
            {
                path = CommonHelper.WinformPlatformPath + "\\" + pc.path;
            }

            if (File.Exists(path))
            {
                textEditorControl.LoadFile(path);
            }

            PluginXmlManage.pluginfile = path;
            plugin = PluginXmlManage.getpluginclass();

            //将plugin赋值给控件
            if (plugin != null)
            {
                txtname.Text            = plugin.name;
                txttitle.Text           = plugin.title;
                txtauthor.Text          = plugin.author;
                txtversion.Text         = plugin.version;
                cbplugintype.Text       = plugin.plugintype;
                txtdefaultdbkey.Text    = plugin.defaultdbkey;
                txtdefaultcachekey.Text = plugin.defaultcachekey;

                gridbasedata.AutoGenerateColumns = false;
                gridbasedata.DataSource          = plugin.data;

                griddll.AutoGenerateColumns = false;
                griddll.DataSource          = plugin.dll;

                gridissue.AutoGenerateColumns = false;
                gridissue.DataSource          = plugin.issue;

                gridsetup.AutoGenerateColumns = false;
                gridsetup.DataSource          = plugin.setup;

                gridmenu.AutoGenerateColumns = false;
                gridmenu.DataSource          = plugin.menu;
            }
        }
Exemple #23
0
        private void 配置插件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (griddev.CurrentCell == null)
            {
                return;
            }

            List <PluginClass> plist = griddev.DataSource as List <PluginClass>;
            PluginClass        pc    = plist[griddev.CurrentCell.RowIndex];

            FrmPluginConfigEdit config = new FrmPluginConfigEdit(pc);

            config.ShowDialog();
        }
        public void GetClassContent_Name_Namespace()
        {
            PluginClass testClass = new PluginClass()
            {
                Name      = "Heippa",
                Namespace = "Joel.Testar"
            };

            var expected = "namespace Joel.Testar\n{\n\tpublic class Heippa\n\t{\n\t}\n}\n";

            var actual = ClassGenerator.GetClassAsString(testClass);

            Assert.AreEqual(expected, actual);
        }
        public FrmCodeMaker(PluginClass pc)
        {
            InitializeComponent();
            plugin = pc;
            treeCodeType.ExpandAll();

            if (plugin.plugintype == "WebModulePlugin")
            {
                txtcodepath.Text = ProjectPath = CommonHelper.WebPlatformPath + "\\ModulePlugin\\" + plugin.name;
            }
            else if (plugin.plugintype == "WinformModulePlugin" || plugin.plugintype == "WcfModulePlugin")
            {
                txtcodepath.Text = ProjectPath = CommonHelper.WinformPlatformPath + "\\ModulePlugin\\" + plugin.name;
            }
        }
Exemple #26
0
        //VS打开
        private void btnvsopen_Click(object sender, EventArgs e)
        {
            try
            {
                if (griddev.CurrentCell == null)
                {
                    return;
                }
                List <PluginClass> plist   = griddev.DataSource as List <PluginClass>;
                PluginClass        pc      = plist[griddev.CurrentCell.RowIndex];
                string             slnname = "";
                if (pc.plugintype == "WinformModulePlugin" || pc.plugintype == "WcfModulePlugin")
                {
                    FileInfo finfo = new FileInfo(CommonHelper.WinformPlatformPath + "\\" + pc.path);
                    if (finfo.Exists)
                    {
                        slnname = finfo.Directory.FullName + "\\" + "EFW_" + pc.name + ".sln";
                    }
                }
                else if (pc.plugintype == "WebModulePlugin")
                {
                    FileInfo finfo = new FileInfo(CommonHelper.WebPlatformPath + "\\" + pc.path);
                    if (finfo.Exists)
                    {
                        slnname = finfo.Directory.FullName + "\\" + "EFW_" + pc.name + ".sln";
                    }

                    //修改web.config中的EntLib.config配置目录
                    string      webconfig = CommonHelper.WebPlatformPath + "\\Web.config";
                    XmlDocument xmlDoc    = new XmlDocument();
                    xmlDoc.Load(webconfig);
                    XmlNode xn = xmlDoc.DocumentElement.SelectSingleNode("enterpriseLibrary.ConfigurationSource/sources/add[@name='EntLibConfiguration']");
                    if (xn != null)
                    {
                        xn.Attributes["filePath"].Value = CommonHelper.WebPlatformPath + @"\Config\EntLib.config";
                    }
                    xmlDoc.Save(webconfig);
                }
                if (slnname != "")
                {
                    VSOpenCommand.Open(slnname);
                }
            }
            catch (Exception err)
            {
                MessageBoxEx.Show("请先配置好VisualStudio工具,点击界面上右上角的“设置”!\n\r" + err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool Load()
        {
            try
            {
                if (Enabled)
                {
                    return(true);
                }

                PointBlankLogging.Log("Starting " + Name + "...");
                Type _class = PluginAssembly.GetTypes().First(a => a.IsClass && typeof(PointBlankPlugin).IsAssignableFrom(a)); // Get the first plugin class

                PluginClass = Enviroment.runtimeObjects["Plugins"].AddCodeObject(_class) as PointBlankPlugin;                  // Instentate the plugin class
                Name        = PluginClass.GetType().Name;                                                                      // Change the name
                Version     = PluginClass.Version;

                if (CheckUpdates())
                {
                    if (PluginConfiguration.NotifyUpdates)
                    {
                        Notify();
                    }
                    if (PluginConfiguration.AutoUpdate)
                    {
                        Update();
                    }
                }

                LoadConfiguration();                                 // Load the configuration
                LoadTranslation();                                   // Load the translation
                PointBlankPluginEvents.RunPluginStart(PluginClass);  // Run the start event
                PluginClass.Load();                                  // Run the load function
                PointBlankPluginEvents.RunPluginLoaded(PluginClass); // Run the loaded event

                Enabled = true;                                      // Set the enabled to true
                t.Start();                                           // Start the thread
                return(true);
            }
            catch (Exception ex)
            {
                PointBlankLogging.LogError("Error starting plugin: " + Name, ex);
                Unload();
                return(false);
            }
        }
Exemple #28
0
        public void LoadPlugins(Assembly assembly)
        {
            List <PluginClass> pluginClassList = new List <PluginClass>();

            foreach (var type in assembly.GetTypes())
            {
                bool            isAPlugin           = false;
                PluginAttribute pluginAttribute     = null;
                var             dependsOnAttributes = new List <DependsOnAttribute>();
                foreach (var customAttribute in type.GetCustomAttributes(true))
                {
                    if (customAttribute is PluginAttribute)
                    {
                        isAPlugin       = true;
                        pluginAttribute = customAttribute as PluginAttribute;
                    }
                    if (customAttribute is DependsOnAttribute)
                    {
                        dependsOnAttributes.Add(customAttribute as DependsOnAttribute);
                    }
                }
                if (isAPlugin)
                {
                    if (typeof(TPlugin).IsAssignableFrom(type))
                    {
                        var pluginClass = new PluginClass
                        {
                            Type            = type,
                            PluginAttribute = pluginAttribute,
                        };
                        pluginClassList.Add(pluginClass);
                        foreach (var dependsOnAttribute in dependsOnAttributes)
                        {
                            pluginClass.DependsOn.Add(dependsOnAttribute.Type);
                        }
                    }
                }
            }
            pluginClassList = ResolvPluginClassOrder(pluginClassList);
            foreach (var pluginClass in pluginClassList)
            {
                LoadPlugin(pluginClass.Type, pluginClass.PluginAttribute);
            }
        }
Exemple #29
0
        //插件发布
        private void btnPack_Click(object sender, EventArgs e)
        {
            if (CommonHelper.issuekey == "!@#$%^")
            {
                if (griddev.CurrentCell == null)
                {
                    return;
                }

                List <PluginClass> plist = griddev.DataSource as List <PluginClass>;
                PluginClass        pc    = plist[griddev.CurrentCell.RowIndex];

                FrmPack pack = new FrmPack(pc);
                pack.ShowDialog();
            }
            else
            {
                //MessageBox.Show("sorry,你没有发布插件的权限!");
                MessageBoxEx.Show("sorry,你没有发布插件的权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #30
0
        internal static object ExecuteMethod(PluginClass pluginClass, string methodName, object[] parameters = null)
        {
            var methodInfo = pluginClass.Instance.GetType().GetMethod(methodName);

            if (methodInfo != null)
            {
                try
                {
                    return(methodInfo.Invoke(pluginClass.Instance, parameters));
                }
                catch (Exception ex)
                {
                    if (pluginClass.PluginSetting.MethodsAllowedToFail == false)
                    {
                        PluginClasses.Remove(pluginClass);
                    }
                    Debug.Log(string.Format("Failed to execute method {0}. Error:\n{1}", methodInfo.Name, ex));
                }
            }
            return(null);
        }