private PluginInfoTemp TPluginInfo(PluginInfo plugin)
 {
     PluginInfoTemp p = new PluginInfoTemp();
     p.CompanyHomePage = plugin.CompanyHomePage;
     p.CompanyLinkman = plugin.CompanyLinkman;
     p.CompanyName = plugin.CompanyName;
     p.CompanyTel = plugin.CompanyTel;
     p.DirectoryName = plugin.DirectoryName;
     p.DisplayName = plugin.DisplayName;
     p.FileName = plugin.FileName;
     p.HashCode = plugin.HashCode;
     p.IsDefault = plugin.IsDefault;
     p.IsNeed = plugin.IsNeed;
     p.PluginCateCode = plugin.PluginCateCode;
     p.PluginUrl = plugin.PluginUrl;
     p.Sequence = plugin.Sequence;
     p.PluginSummary = plugin.Summary;
     p.TypeFullName = plugin.TypeFullName;
     p.Version = plugin.Version;
     p.PluginCode = plugin.PluginCode;
     p.IsNew = plugin.IsNew;
     p.IsUse = plugin.IsUse;
     p.IsIgnoreConfig = plugin.IsIgnoreConfig;
     p.configList = plugin.configList;
     p.ActionCode = plugin.ActionCode;
     p.ActionSummary = plugin.ActionSummary;
     p.VersionSummary = plugin.VersionSummary;
     return p;
 }
        public ActionResult SaveVerInfo(VersionTrack ver, string IsAdd, string IsUpdate, FormCollection form, string PluginCateCode)
        {
            var vmobject = new JsonReturnMessages();
            string vid = "";
            XmlConfigInfo xmlInfo = null;

            try
            {
                if (Request.Files.Count > 0)//�����ϴ��ļ�
                    xmlInfo = Decompressing(form["VersionIds"].ToString(), IsAdd);//��ѹ
                else
                {
                    IList<PluginInfoTemp> listp = new List<PluginInfoTemp>();
                    PluginInfoTemp p = new PluginInfoTemp();
                    p.Version = form["VersionName"];
                    p.PluginUrl = form["PluginUrl"];
                    p.PluginCode = form["PluginCode"];
                    listp.Add(p);
                    xmlInfo = new XmlConfigInfo();
                    xmlInfo.PluginInfo = listp;
                }
                if (PluginCateCode.Equals("1"))//��Ϊweb���
                {
                    xmlInfo.PluginInfo[0].PluginCateCode = Constants.PluginCateCode;
                    xmlInfo.oldCode = xmlInfo.PluginInfo[0].PluginCode;
                }
                foreach (PluginInfoTemp ps in xmlInfo.PluginInfo)
                {
                    ps.IsPublic = true;
                    ps.IsIgnoreConfig = Convert.ToBoolean(form["ck"]);
                }

                vid = BoFactory.GetVersionTrackBo.SavePluingZipInfo(ver, xmlInfo, IsAdd, IsUpdate, base.CurrentUser.UserUId, form["VersionIds"].ToString());

                if (Request.Files.Count > 0)//�����ϴ��ļ�
                    MoveFolder(xmlInfo);//�ƶ��ļ��м��ļ�
            }
            catch (Exception ex)
            {
                try
                {
                    string thisFilePath = AppConfig.filePath + Common.Entities.Constants.TempName;
                    while (Directory.Exists(thisFilePath))//��ɾ��ԭ����ʱ�ļ���
                    {
                        Directory.Delete(thisFilePath, true);
                    }
                    if (!string.IsNullOrEmpty(xmlInfo.savefile))
                    {
                        FileInfo f = new FileInfo(xmlInfo.savefile);//ɾ��ԭ�������zip
                        if (f.Exists)
                            f.Delete();
                    }
                }
                catch (Exception fe)
                {
                    vmobject.IsSuccess = false;
                    vmobject.Msg = fe.Message;
                }

                vmobject.IsSuccess = false;
                vmobject.Msg = vmobject.Msg + "," + ex.Message;
                return Json(vmobject, "text/html");
            }
            //��ȡ��һ���汾����
            SearchVersionTrack sea = new SearchVersionTrack();
            sea.VID = vid;
            VersionTrack vt = BoFactory.GetVersionTrackBo.GetVersionTrack(sea)[0];
            if (vt != null)
            {
                if (vt.PreVersionId != 0)
                    vid = vt.PreVersionId.ToString();
            }

            vmobject.Msg = vid;
            vmobject.IsSuccess = true;
            return Json(vmobject, "text/html");
        }
        /// <summary>
        /// 根据xml 获取pluginInfo
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        private static List<PluginInfoTemp> GetPluginInfoFromXml(XmlDocument xml)
        {
            List<PluginInfoTemp> pluginInfoList = new List<PluginInfoTemp>();

            // GetBaseInfo(pluginInfo, xml);

            var pluginInfonodes = xml.SelectNodes("//Plugins/*");
            if (pluginInfonodes == null)
            {
                throw new ArgumentNullException("没有Plugins节点");
            }
            foreach (XmlNode item in pluginInfonodes)
            {

                var pluginInfo = new PluginInfoTemp();
                pluginInfoList.Add(pluginInfo);
                GetBaseInfo(pluginInfo, xml);

                pluginInfo.DisplayName = GetNodeValue(item.SelectSingleNode("./Name"));
                pluginInfo.PluginCode = GetNodeValue(item.SelectSingleNode("./PluginCode"));
                pluginInfo.PluginCateCode = GetNodeValue(item.SelectSingleNode("./PluginCateCode"));
                pluginInfo.TypeFullName = GetNodeValue(item.SelectSingleNode("./TypeFullName"));
                pluginInfo.FileName = GetNodeValue(item.SelectSingleNode("./MainFileName"));
                //  pluginInfo.PluginSummary = GetNodeValue(item.SelectSingleNode("./PluginDescription"));
                pluginInfo.PluginSummary = GetNodeValue(item.SelectSingleNode("./Description"));
                pluginInfo.IsNeed = GetNodeValue(item.SelectSingleNode("./IsNeed")).ToLower() == "true";
                //web插件独有
                pluginInfo.PluginUrl = GetNodeValue(item.SelectSingleNode("./Url"));
                //Action插件独有
                pluginInfo.ActionCode = GetNodeValue(item.SelectSingleNode("./ActionCode"));
                pluginInfo.ActionSummary = GetNodeValue(item.SelectSingleNode("./ActionDescription"));
                //版本信息 必须
                pluginInfo.Version = GetNodeValue(item.SelectSingleNode("./VersionCode"));
                pluginInfo.VersionSummary = GetNodeValue(item.SelectSingleNode("./VersionDescription"));

                //是否需要权限控制
                if (item.SelectSingleNode("./IsPublic") != null && !string.IsNullOrEmpty(GetNodeValue(item.SelectSingleNode("./IsPublic"))))
                    pluginInfo.IsPublic = Convert.ToBoolean(GetNodeValue(item.SelectSingleNode("./IsPublic")));
                else
                    pluginInfo.IsPublic = true;
                pluginInfo.AppCode = GetNodeValue(item.SelectSingleNode("./AppCode"));
                pluginInfo.PrivilegeCode = GetNodeValue(item.SelectSingleNode("./PrivilegeCode"));
                // 获取配置信息
                pluginInfo.configList = GetPluginConfigListByXml(item);

            }
            return pluginInfoList;
        }
        public ActionResult SavePluginInfos(PluginInfoTemp pt, FormCollection form, ConfigTemp c,string IsAdd)
        {
            var vmobject = new JsonReturnMessages();
            IList<PluginInfoTemp> listtemp = new List<PluginInfoTemp>();
            IList<ConfigTemp> list = new List<ConfigTemp>();
            string vids = "";

            try
            {
                string[] keys = form.AllKeys;
                //��ȡ����б�
                for (int i = 0; i < keys.Length; i++)
                {
                    if (keys[i].EndsWith(".PluginCode"))
                    {
                        PluginInfoTemp p = new PluginInfoTemp();
                        string prefix = keys[i].Split('.')[0];
                        UpdateModel(p, prefix);  //��������ͬʱ���Ի������ʵ�����
                        p.CompanyHomePage = pt.CompanyHomePage;
                        p.CompanyLinkman = pt.CompanyLinkman;
                        p.CompanyName = pt.CompanyName;
                        p.CompanyTel = pt.CompanyTel;
                        if (p.IsNeed == true)
                            p.IsDefault = true;
                        listtemp.Add(p);
                    }
                }
                //��ȡ�б����
                if (listtemp[0].IsIgnoreConfig == false)
                {
                    for (int i = 0; i < keys.Length; i++)
                    {
                        if (keys[i].EndsWith(".Key1"))
                        {
                            ConfigTemp config = new ConfigTemp();
                            string prefix = keys[i].Split('.')[0];
                            UpdateModel(config, prefix);  //��������ͬʱ���Ի������ʵ�����
                            config.PluginCode = prefix.Split('|')[0];
                            list.Add(config);
                        }
                    }
                }

                BoFactory.GetVersionTrackBo.UpdateTempPlugin(listtemp, list, IsAdd, base.CurrentUser.UserUId);
            }
            catch (Exception ex)
            {
                vmobject.IsSuccess = false;
                vmobject.Msg = ex.Message;
                return Json(vmobject);
            }
            //��ȡ��һ���汾����
            SearchVersionTrack sea = new SearchVersionTrack();
            sea.PluginCode = listtemp[0].PluginCode;
            sea.VersionName = listtemp[0].Version;
            vids = BoFactory.GetVersionTrackBo.GetVersionTrack(sea)[0].VersionId.ToString();//Ĭ��Ϊ��ǰ��ʱ���һ��
            foreach (PluginInfoTemp pti in listtemp)
            {
                SearchVersionTrack search = new SearchVersionTrack();
                search.PluginCode = pti.PluginCode.ToString();
                search.VersionName = pti.Version;
                VersionTrack vst = BoFactory.GetVersionTrackBo.GetVersionTrack(search)[0];
                if (vst.PreVersionId != 0)
                {
                    vids = vst.PreVersionId.ToString();//�����һ���汾�����޸�״̬ʱ��ֱ��ѡ�񷢲���õ�vidһ��Ϊ�ϸ��汾vid
                    break;
                }

            }
            vmobject.IsSuccess = true;
            vmobject.Msg = vids;
            return Json(vmobject);
        }
        private static void GetBaseInfo(PluginInfoTemp pluginInfo, XmlDocument xml)
        {
            if (pluginInfo == null)
                throw new ArgumentNullException("请给要添加BaseInfo的实体赋值!");
            var pluginBaseInfonodes = xml.SelectNodes("//BaseInfo/*");
            if (pluginBaseInfonodes == null)
            {
                throw new ArgumentNullException("输入的Xml不存在BaseInfo节点");
            }
            foreach (XmlNode item in pluginBaseInfonodes)
            {
                var value = item.InnerText;
                switch (item.Name)
                {
                    case "CompanyName":
                        pluginInfo.CompanyName = value;
                        break;
                    case "CompanyLinkman":
                        pluginInfo.CompanyLinkman = value;
                        break;
                    case "CompanyTel":
                        pluginInfo.CompanyTel = value;
                        break;
                    case "CompanyHomePage":
                        pluginInfo.CompanyHomePage = value;
                        break;
                }

            }
        }