public static void savepluginclass(pluginxmlClass pluginclass)
        {
            if (pluginclass == null)
            {
                return;
            }

            if (xmlDoc == null)
            {
                InitConfig();
            }

            XmlNode pluginN = xmlDoc.DocumentElement.SelectSingleNode("plugin");

            pluginN.Attributes["name"].Value            = pluginclass.name;
            pluginN.Attributes["title"].Value           = pluginclass.title;
            pluginN.Attributes["version"].Value         = pluginclass.version;
            pluginN.Attributes["author"].Value          = pluginclass.author;
            pluginN.Attributes["plugintype"].Value      = pluginclass.plugintype;
            pluginN.Attributes["defaultdbkey"].Value    = pluginclass.defaultdbkey;
            pluginN.Attributes["defaultcachekey"].Value = pluginclass.defaultcachekey;
            pluginN.Attributes["isentry"].Value         = pluginclass.isentry;
            XmlNode dataN = pluginN.SelectSingleNode("baseinfo");

            if (dataN != null)
            {
                pluginN.RemoveChild(dataN);
            }

            XmlNode dllN = pluginN.SelectSingleNode("businessinfo");

            if (dllN != null)
            {
                pluginN.RemoveChild(dllN);
            }

            XmlNode issueN = pluginN.SelectSingleNode("issue");

            if (issueN != null)
            {
                pluginN.RemoveChild(issueN);
            }

            XmlNode setupN = pluginN.SelectSingleNode("setup");

            if (setupN != null)
            {
                pluginN.RemoveChild(setupN);
            }

            XmlNode menuN = pluginN.SelectSingleNode("menus");

            if (menuN != null)
            {
                pluginN.RemoveChild(menuN);
            }

            if (pluginclass.data.Count > 0)
            {
                XmlElement xe1 = xmlDoc.CreateElement("baseinfo");//创建一个节点
                pluginN.AppendChild(xe1);
            }
            if (pluginclass.dll.Count > 0)
            {
                XmlElement xe1 = xmlDoc.CreateElement("businessinfo");//创建一个节点
                pluginN.AppendChild(xe1);
            }
            if (pluginclass.issue.Count > 0)
            {
                XmlElement xe1 = xmlDoc.CreateElement("issue");//创建一个节点
                pluginN.AppendChild(xe1);
            }
            if (pluginclass.setup.Count > 0)
            {
                XmlElement xe1 = xmlDoc.CreateElement("setup");//创建一个节点
                pluginN.AppendChild(xe1);
            }
            if (pluginclass.menu.Count > 0)
            {
                XmlElement xe1 = xmlDoc.CreateElement("menus");//创建一个节点
                pluginN.AppendChild(xe1);
            }

            for (int i = 0; i < pluginclass.data.Count; i++)
            {
                XmlElement xe1 = xmlDoc.CreateElement("data");//创建一个节点
                xe1.SetAttribute("key", pluginclass.data[i].key);
                xe1.SetAttribute("value", pluginclass.data[i].value);
                pluginN.SelectSingleNode("baseinfo").AppendChild(xe1);
            }

            for (int i = 0; i < pluginclass.dll.Count; i++)
            {
                XmlElement xe1 = xmlDoc.CreateElement("dll");//创建一个节点
                xe1.SetAttribute("name", pluginclass.dll[i].name);
                xe1.SetAttribute("version", pluginclass.dll[i].version);
                pluginN.SelectSingleNode("businessinfo").AppendChild(xe1);
            }

            for (int i = 0; i < pluginclass.issue.Count; i++)
            {
                XmlElement xe1 = xmlDoc.CreateElement("add");//创建一个节点
                xe1.SetAttribute("type", pluginclass.issue[i].type);
                xe1.SetAttribute("path", pluginclass.issue[i].path);
                xe1.SetAttribute("source", pluginclass.issue[i].source);
                pluginN.SelectSingleNode("issue").AppendChild(xe1);
            }

            for (int i = 0; i < pluginclass.setup.Count; i++)
            {
                XmlElement xe1 = xmlDoc.CreateElement("add");//创建一个节点
                xe1.SetAttribute("type", pluginclass.setup[i].type);
                xe1.SetAttribute("path", pluginclass.setup[i].path);
                xe1.SetAttribute("copyto", pluginclass.setup[i].copyto);
                pluginN.SelectSingleNode("setup").AppendChild(xe1);
            }

            for (int i = 0; i < pluginclass.menu.Count; i++)
            {
                XmlElement xe1 = xmlDoc.CreateElement("add");//创建一个节点
                xe1.SetAttribute("menuname", pluginclass.menu[i].menuname);
                xe1.SetAttribute("pluginname", pluginclass.menu[i].pluginname);
                xe1.SetAttribute("controllername", pluginclass.menu[i].controllername);
                xe1.SetAttribute("viewname", pluginclass.menu[i].viewname);
                xe1.SetAttribute("menupath", pluginclass.menu[i].menupath);
                xe1.SetAttribute("memo", pluginclass.menu[i].memo);
                pluginN.SelectSingleNode("menus").AppendChild(xe1);
            }
            xmlDoc.Save(pluginfile);
        }
示例#2
0
        public static bool PluginSetup(string localzippath)
        {
            FileInfo fileinfo = new FileInfo(localzippath);

            if (fileinfo.Exists == false)
            {
                throw new Exception("插件包不存在!");
            }

            string temp_pluginpath = fileinfo.Directory.FullName + "\\" + fileinfo.Name.Replace(fileinfo.Extension, "");

            FastZipHelper.decompress(temp_pluginpath, localzippath);
            PluginXmlManage.pluginfile = temp_pluginpath + "\\plugin.xml";
            pluginxmlClass plugin = PluginXmlManage.getpluginclass();

            string pluginpath    = "";
            string pluginsyspath = "";
            string dbconfig      = "";
            string plugintype    = "";
            string ptype         = plugin.plugintype.ToLower();

            bool ishave = false;

            switch (ptype)
            {
            case "web":
                pluginsyspath = CommonHelper.WebPlatformPath + "\\Config\\pluginsys.xml";
                dbconfig      = CommonHelper.WebPlatformPath + "\\Web.config";
                plugintype    = "WebModulePlugin";
                pluginpath    = CommonHelper.WebPlatformPath + "\\ModulePlugin\\" + plugin.name;
                PluginSysManage.pluginsysFile = CommonHelper.WebPlatformPath + "\\Config\\pluginsys.xml";
                if (PluginSysManage.ContainsPlugin("WebModulePlugin", plugin.name))
                {
                    ishave = true;
                }
                break;

            case "winform":
                pluginsyspath = CommonHelper.WinformPlatformPath + "\\Config\\pluginsys.xml";
                dbconfig      = CommonHelper.WinformPlatformPath + "\\Config\\EntLib.config";
                plugintype    = "WinformModulePlugin";
                pluginpath    = CommonHelper.WinformPlatformPath + "\\ModulePlugin\\" + plugin.name;
                PluginSysManage.pluginsysFile = CommonHelper.WinformPlatformPath + "\\Config\\pluginsys.xml";
                if (PluginSysManage.ContainsPlugin("WinformModulePlugin", plugin.name))
                {
                    ishave = true;
                }
                break;

            case "wcf":
                pluginsyspath = CommonHelper.WinformPlatformPath + "\\Config\\pluginsys.xml";
                dbconfig      = CommonHelper.WinformPlatformPath + "\\Config\\EntLib.config";
                plugintype    = "WcfModulePlugin";
                pluginpath    = CommonHelper.WinformPlatformPath + "\\ModulePlugin\\" + plugin.name;
                PluginSysManage.pluginsysFile = CommonHelper.WinformPlatformPath + "\\Config\\pluginsys.xml";
                if (PluginSysManage.ContainsPlugin("WcfModulePlugin", plugin.name))
                {
                    ishave = true;
                }
                break;
            }

            //先判断此插件本地是否存在
            if (ishave == true)
            {
                DevComponents.DotNetBar.MessageBoxEx.Show("你选择的插件本地已安装!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            string connectionString;

            //添加创建数据库的方法
            if (PluginSetupCreateTable(temp_pluginpath, plugin.setup.FindAll(x => x.type == "sql"), out connectionString) == false)
            {
                if (MessageBoxEx.Show("是否继续安装此插件?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
                {
                    return(false);
                }
            }
            else//修改数据库连接
            {
                if (string.IsNullOrEmpty(dbconfig) == false && File.Exists(dbconfig) && string.IsNullOrEmpty(connectionString) == false)
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(dbconfig);

                    XmlNode nodeN = xmlDoc.DocumentElement.SelectSingleNode("connectionStrings/add[@name='" + plugin.defaultdbkey + "']");
                    if (nodeN != null)
                    {
                        nodeN.Attributes["connectionString"].Value = connectionString;
                        xmlDoc.Save(dbconfig);
                    }
                }
            }

            //移动到插件目录
            if (temp_pluginpath != pluginpath)
            {
                new DirectoryInfo(temp_pluginpath).MoveTo(pluginpath);
            }


            foreach (setupClass sc in plugin.setup)
            {
                if (sc.type == "dir")
                {
                    if (sc.copyto != "")
                    {
                        CommonHelper.CopyFolder(pluginpath + "\\" + sc.path, pluginpath + "\\" + sc.copyto);
                    }
                }
                else if (sc.type == "file")
                {
                    if (sc.copyto != "")
                    {
                        new FileInfo(pluginpath + "\\" + sc.path).CopyTo(pluginpath + "\\" + sc.copyto, true);
                    }
                }
            }

            //pluginsys.xml
            PluginSysManage.pluginsysFile = pluginsyspath;
            PluginSysManage.AddPlugin(plugintype, plugin.name, "ModulePlugin/" + plugin.name + "/plugin.xml", plugin.title, "0");

            return(true);
        }
        public static pluginxmlClass getpluginclass()
        {
            if (xmlDoc == null)
            {
                InitConfig();
            }


            pluginxmlClass plugin = new pluginxmlClass();

            plugin.data  = new List <baseinfodataClass>();
            plugin.dll   = new List <businessinfodllClass>();
            plugin.issue = new List <issueClass>();
            plugin.setup = new List <setupClass>();
            plugin.menu  = new List <menuClass>();

            XmlNode node = xmlDoc.DocumentElement.SelectSingleNode("plugin");

            plugin.name            = node.Attributes["name"].Value;
            plugin.title           = node.Attributes["title"].Value;
            plugin.version         = node.Attributes["version"].Value;
            plugin.author          = node.Attributes["author"].Value;
            plugin.plugintype      = node.Attributes["plugintype"].Value;
            plugin.defaultdbkey    = node.Attributes["defaultdbkey"].Value;
            plugin.defaultcachekey = node.Attributes["defaultcachekey"].Value;
            plugin.isentry         = node.Attributes["isentry"].Value;

            //node = xmlDoc.DocumentElement.SelectSingleNode("plugin/baseinfo/data[@key='introduction']");
            //plugin.introduction = node == null ? "" : node.Attributes["value"].Value;
            //node = xmlDoc.DocumentElement.SelectSingleNode("plugin/baseinfo/data[@key='updaterecord']");
            //plugin.updaterecord = node == null ? "" : node.Attributes["value"].Value;
            //node = xmlDoc.DocumentElement.SelectSingleNode("plugin/baseinfo/data[@key='headpic']");
            //plugin.headpic = node == null ? "" : node.Attributes["value"].Value;
            //node = xmlDoc.DocumentElement.SelectSingleNode("plugin/baseinfo/data[@key='StartItem']");
            //plugin.StartItem = node == null ? "" : node.Attributes["value"].Value;
            XmlNodeList nlist = null;

            if (xmlDoc.DocumentElement.SelectSingleNode("plugin/baseinfo") != null)
            {
                nlist = xmlDoc.DocumentElement.SelectSingleNode("plugin/baseinfo").ChildNodes;
                foreach (XmlNode n in nlist)
                {
                    baseinfodataClass data = new baseinfodataClass();
                    data.key   = n.Attributes["key"].Value;
                    data.value = n.Attributes["value"].Value;

                    plugin.data.Add(data);
                }
            }
            if (xmlDoc.DocumentElement.SelectSingleNode("plugin/businessinfo") != null)
            {
                nlist = xmlDoc.DocumentElement.SelectSingleNode("plugin/businessinfo").ChildNodes;
                foreach (XmlNode n in nlist)
                {
                    businessinfodllClass dll = new businessinfodllClass();
                    dll.name    = n.Attributes["name"].Value;
                    dll.version = n.Attributes["version"].Value;

                    plugin.dll.Add(dll);
                }
            }

            if (xmlDoc.DocumentElement.SelectSingleNode("plugin/issue") != null)
            {
                nlist = xmlDoc.DocumentElement.SelectSingleNode("plugin/issue").ChildNodes;
                foreach (XmlNode n in nlist)
                {
                    issueClass ic = new issueClass();
                    ic.type   = n.Attributes["type"].Value;
                    ic.path   = n.Attributes["path"].Value;
                    ic.source = n.Attributes["source"] == null ? "" : n.Attributes["source"].Value;

                    plugin.issue.Add(ic);
                }
            }

            if (xmlDoc.DocumentElement.SelectSingleNode("plugin/setup") != null)
            {
                nlist = xmlDoc.DocumentElement.SelectSingleNode("plugin/setup").ChildNodes;
                foreach (XmlNode n in nlist)
                {
                    setupClass sc = new setupClass();
                    sc.type   = n.Attributes["type"].Value;
                    sc.path   = n.Attributes["path"].Value;
                    sc.copyto = n.Attributes["copyto"] == null ? "" : n.Attributes["copyto"].Value;
                    plugin.setup.Add(sc);
                }
            }

            if (xmlDoc.DocumentElement.SelectSingleNode("plugin/menus") != null)
            {
                nlist = xmlDoc.DocumentElement.SelectSingleNode("plugin/menus").ChildNodes;
                foreach (XmlNode n in nlist)
                {
                    menuClass mc = new menuClass();
                    mc.menuname       = n.Attributes["menuname"].Value;
                    mc.pluginname     = n.Attributes["pluginname"].Value;
                    mc.controllername = n.Attributes["controllername"].Value;
                    mc.viewname       = n.Attributes["viewname"].Value;
                    mc.menupath       = n.Attributes["menupath"].Value;
                    mc.memo           = n.Attributes["memo"].Value;
                    plugin.menu.Add(mc);
                }
            }

            return(plugin);
        }