/// <summary> /// 升级 /// 流程:备份+获取版本号+(解压+修改配置文件)+获取新版本号 /// 适用:服务\应用程序\网络站点 /// </summary> /// <param name="stnm"></param> /// <param name="tcode"></param> /// <param name="ip"></param> /// <returns></returns> protected bool Update(string stnm, string tcode, string ip) { try { //备份 if (!Backup(name)) { return(false); } //获取旧版本号 FileInfo exe_old = GetFile_FromDeploy(name); if (exe_old != null) { report.Add("旧版本:" + Common_Handle.GetExeVersion(exe_old.FullName)); } //安装(解压+修改配置文件) if (!Install(stnm, tcode, ip)) { return(false); } return(true); } catch (Exception e) { report.Error(name + "升级异常", e); return(false); } }
/// <summary> /// 安装 /// </summary> /// <param name="StationName">站名</param> /// <param name="TelexCode">电报码</param> /// <param name="IP">IP</param> /// <returns></returns> private bool Install_DB(string StationName, string TelexCode, string IP) { try { //安装 if (!Install(StationName, TelexCode, IP)) { return(false); } //获取具体部署目录 DirectoryInfo dir_deploy_db = GetDir_FromDeploy(name); //CMD方式安装 report.Add("安装..."); List <string> cmds = new List <string>(); cmds.Add(@"cd " + dir_deploy_db.FullName + @"\bin\"); cmds.Add(dir_deploy.FullName.Substring(0, 1) + ":");//切换盘符 cmds.Add("mysqld install mysql"); cmds.Add("net start mysql"); cmds.Add("exit"); Common_Handle.RunCMD(cmds); #region 初始化-默认数据 report.Add("默认数据初始化..."); try { //数据库默认数据赋值 List <string> list_sql = new List <string>(); list_sql.Add("UPDATE line l SET l.TelexCode='" + TelexCode + "' , l.NextTelexCode='';"); list_sql.Add("UPDATE sys_CodeMap p SET `Value`='" + StationName + "' where p.`Code`='StationName';"); list_sql.Add("UPDATE sys_CodeMap p SET `Value`='" + TelexCode + "' where p.`Code`='TelexCode';"); list_sql.Add("UPDATE sys_CodeMap p SET `Value`='" + IP + "' where p.`Code`='IP';"); list_sql.Add("UPDATE account_t_station s SET s.StationName='" + StationName + "', s.ConnectString='" + IP + "', s.TelexCode='" + TelexCode + "', s.StationType='0' WHERE s.StationID='100'; "); list_sql.Add("UPDATE account_t_user u SET u.TelexCode='" + TelexCode + "' WHERE u.userid='1';"); foreach (string s in list_sql) { string error = ExecSQL(s, con); if (error != "") { report.Add("[执行" + s + "失败]" + error, "失败"); } } report.Add("数据库安装完成", "成功"); } catch { throw; } #endregion return(true); } catch (Exception e) { report.Error("数据库安装异常", e); return(false); } }
/// <summary> /// 部署 /// </summary> /// <param name="stnm"></param> /// <param name="tcode"></param> /// <param name="ip"></param> public override void Deploy(string stnm, string tcode, string ip) { bool flag = false; try { //查询网络站点 bool WebIsExist = false; ServerManager sm = new ServerManager(); for (int i = 0; i < sm.Sites.Count; i++) { if (sm.Sites[i].Name.ToLower() == name.ToLower()) { WebIsExist = true; break; } } //判断站点是否存在 if (WebIsExist) { report.Add(comment + "升级..."); flag = Update(stnm, tcode, ip);//升级 } else { report.Add(comment + "安装..."); //通用安装 if (!Install(stnm, tcode, ip)) { return; } try { report.Add("创建程序池..."); if (sm.ApplicationPools[name] == null) { sm.ApplicationPools.Add(name); ApplicationPool curAppPool = sm.ApplicationPools[name]; curAppPool.ManagedPipelineMode = ManagedPipelineMode.Integrated; curAppPool.Failure.RapidFailProtection = true; curAppPool.Enable32BitAppOnWin64 = true; sm.ApplicationPools[name].ManagedRuntimeVersion = "v4.0";//必须这么写才能选中默认V4.0.30319 curAppPool.AutoStart = true; } report.Add("创建站点..."); DirectoryInfo dir = GetDir_FromDeploy(name); Site curweb = sm.Sites.Add(name, "http", ip + ":" + port + ":", dir.FullName); //绑定默认IP curweb.Bindings.Add("202.202.202.1:" + port + ":", "http"); curweb.Applications[0].ApplicationPoolName = name; //开启站点 if (AutoStart) { curweb.ServerAutoStart = true; } report.Add("创建虚拟目录..."); foreach (KeyValuePair <string, string> vf in list_vf) { curweb.Applications[0].VirtualDirectories.Add("/" + vf.Key, vf.Value); } report.Add("设置权限..."); Helper_FileDir.AddSecurityControll2Folder(dir.FullName); sm.CommitChanges(); if (Directory.Exists(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319")) { report.Add("注册IIS..."); List <string> cmds = new List <string>(); cmds.Add(@"cd C:\Windows\Microsoft.NET\Framework\v4.0.30319"); cmds.Add("C:");//切换盘符 cmds.Add("aspnet_regiis.exe -i"); cmds.Add("exit"); Common_Handle.RunCMD(cmds); } flag = true; } catch (Exception e) { report.Error("站点搭建异常", e); } } } catch (Exception e) { report.Error("部署" + comment + "异常", e); } finally { report.Add("部署-" + comment, flag ? "成功" : "失败"); } }
/// <summary> /// 安装软件 /// 流程:解压 修改配置文件 /// 适用:数据库\服务\应用程序\网络站点 /// </summary> /// <param name="stnm"></param> /// <param name="tcode"></param> /// <param name="ip"></param> /// <returns></returns> protected bool Install(string stnm, string tcode, string ip) { try { //解压 report.Add("解压缩..."); FileInfo fi_zip = GetZipFile_FromSource(name); if (fi_zip == null) { return(false); } Helper_Zip.UnZip(fi_zip.FullName, dir_deploy.FullName, "", true); //获取具体软件部署目录 DirectoryInfo dir_soft = GetDir_FromDeploy(name); //修改配置文件 if (list_mx.Count > 0) { report.Add("修改配置文件..."); foreach (modify_xml mx in list_mx) { try { if (string.IsNullOrWhiteSpace(mx.innerText)) { Helper_XML.ModifyAttr_ByID(dir_soft.FullName + "\\" + mx.path, mx.id, mx.attr, mx.value.Replace("@TelexCode", tcode).Replace("@IP", ip), mx.encode); report.Add("【" + mx.path + "】id:" + mx.id + "的属性" + mx.attr + "置为" + mx.value.Replace("@TelexCode", tcode).Replace("@IP", ip), "成功"); } else { Helper_XML.ModifyText_ByID(dir_soft.FullName + "\\" + mx.path, mx.id, mx.innerText.Replace("@TelexCode", tcode).Replace("@IP", ip), mx.encode); report.Add("【" + mx.path + "】id:" + mx.id + "的InnerText置为" + mx.innerText.Replace("@TelexCode", tcode).Replace("@IP", ip), "成功"); } } catch (Exception ex) { report.Error(mx.path, ex); continue; } } } //获取新版本号 FileInfo exe_new = GetFile_FromDeploy(name); if (exe_new != null) { report.Add("新版本:" + Common_Handle.GetExeVersion(exe_new.FullName)); } return(true); } catch (Exception e) { report.Error(comment + "安装[解压+修改配置文件]异常", e); return(false); } }