/// <summary> /// 执行SQL /// </summary> /// <param name="filename"></param> /// <param name="ConStr"></param> /// <returns></returns> private static string ExecSQLFile(string filename, string ConStr) { if (!File.Exists(filename)) { return("文件不存在"); } if (string.IsNullOrWhiteSpace(ConStr)) { return("数据库连接字符串未配置"); } string[] filetemp = filename.Split('\\'); try { string TmpSQL = ""; try { TmpSQL = Helper_FileDir.ReadFile(filename); } catch (Exception ex) { return("执行" + filetemp[filetemp.Length - 1] + "失败" + ex.Message); } using (MySqlConnection mycon = new MySqlConnection(ConStr)) { mycon.Open(); MySqlCommand cmd = new MySqlCommand(TmpSQL, mycon); cmd.CommandTimeout = 60; int rowCount = cmd.ExecuteNonQuery(); if (rowCount > 0) { //Component_Handle.Log_Lv(lv_Log, rowCount + "行,受影响", "", "成功", CommonColor.Success); } //插入版本 string[] nameArray = filetemp[filetemp.Length - 1].ToLower().Replace(".sql", "").Replace(".txt", "").Replace("update_", "").Split("_".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); string new_version = "", Remark = ""; new_version = nameArray[0];//记录版本号 if (nameArray.Length > 1) { Remark = nameArray[1];//有中文注释则记录 } MySqlCommand version_Cmd = new MySqlCommand("insert dbversion values('0','" + new_version + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + Remark + "')", mycon); version_Cmd.ExecuteNonQuery(); mycon.Close(); } } catch (Exception ex) { return("执行" + filetemp[filetemp.Length - 1] + "失败" + ex.Message); } return(""); }
/// <summary> /// 共享文件夹 /// </summary> /// <returns></returns> public bool ShareFolder() { try { Helper_FileDir.AddSecurityControll2Folder(path); Helper_FileDir.ShareFolder(path.TrimEnd('\\'), name); report.Add("共享" + name, "成功"); return(true); } catch (Exception e) { report.Error("共享文件夹异常", e); return(false); } }
/// <summary> /// 备份 /// </summary> /// <param name="name"></param> /// <returns></returns> public static bool Backup(string name) { try { bool GoOn = bool.Parse(Config.GetAppConfig("enable_backup")); if (!GoOn) { report.Add("已经禁用备份功能"); return(true); } DirectoryInfo dir = GetDir_FromDeploy(name, false); if (dir != null) { report.Add("开始备份..."); //删除原备份 foreach (DirectoryInfo old_backup in dir_backup.GetDirectories()) { if (old_backup.Name.ToLower() == name.ToLower()) { Directory.Delete(old_backup.FullName, true); report.Add("删除了原有备份"); break; } } //复制 try { Helper_FileDir.CopyDirectory(dir.FullName, dir_backup.FullName); report.Add("备份成功"); } catch (Exception e) { report.Error("备份拷贝异常", e); } return(true); } else { report.Error("无法备份:未找到" + name); return(false); } } 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 ? "成功" : "失败"); } }