static ConfigurationManage() { IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory); //获取当目录下的所有的配置文件的路径 var files = new System.IO.DirectoryInfo(AppContext.BaseDirectory).GetFiles("appsettings*.json"); if (files == null && files.Count() <= 0) { throw new NoFoundException("appsettings.json找不到"); } //需要在appsettings.json中添加ASPNETCORE_ENVIRONMENT环境变量的key //获取当前系统的环境变量从appsetting中 var environmentName = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory).AddJsonFile("appsettings.json").Build().GetValue <string>(EnvironmentName); //遍历名称 foreach (var item in files) { if (item.Name.Equals("appsettings.json") || item.Name.Equals($"appsettings.{environmentName}.json")) { configurationBuilder.AddJsonFile(item.Name, true, true); } } configuration = configurationBuilder.Build(); }
public void shouhuzhong() { MyFuncUtilNoJingTai my = new MyFuncUtilNoJingTai(); long ks = my.GetTimestamp(); long ks2 = my.GetTimestamp(); long ks3 = my.GetTimestamp(); long ks4 = my.GetTimestamp(); long ks5 = my.GetTimestamp(); long ks6 = my.GetTimestamp(); long ks7 = my.GetTimestamp(); long ks8 = my.GetTimestamp(); long ks9 = my.GetTimestamp(); int duokai = 0; int ksgx = 0; int ksck = 0; while (true) { if (ksgx == 0) { System.Threading.Thread.Sleep(1000 * 10); ksgx = 1; WriteLog.WriteLogFile("第一次打开要更新" + System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe") + " " + System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"); UpdateCaoZuo sh = new UpdateCaoZuo(); sh.updateWlxm(); } if (ksck == 0) { System.Threading.Thread.Sleep(1000 * 30); ksck = 1; WriteLog.WriteLogFile("第一次打开要看否打开了wlxm" + System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe") + " " + System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"); bool t = false; string appname = "wlxm"; int a = 0; Process[] processes = Process.GetProcessesByName(appname); foreach (Process process in processes) { if (a == 0 && process.ProcessName == appname) { t = true; a = 1; break; } } if (!t) { string appNamec = System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"; WriteLog.WriteLogFile("wlxm位置" + System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"); if (System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe")) { WriteLog.WriteLogFile("wlxm找到文件位置"); Process p = new Process(); p.StartInfo.FileName = appNamec; //启动程序 p.Start(); ks2 = my.GetTimestamp();//关机项重新计时 WriteLog.WriteLogFile("结束打开wlxm"); } } } long js = my.GetTimestamp(); //只是说明还活着 if ((js - ks) > 1000 * 60 * 5) { ks = my.GetTimestamp(); ShouHu s = new ShouHu(); s.wohaihuozhe(); } //长时间没有数则重启 1号机之外的机器1个半小时 if (!MyFuncUtil.getMachineName().ToUpper().Equals("1HAO") && (js - ks2) > 1000 * 60 * 90) { ks2 = my.GetTimestamp(); ShouHu s = new ShouHu(); bool t = s.panDuanChongQi(MyFuncUtil.getMachineName()); t = false; if (!MyFuncUtil.getMachineName().ToLower().Equals("wlzhongkong") && t) { WriteLog.WriteLogFile("重启啦!!!"); System.Diagnostics.Process.Start("shutdown.exe", "-r -f -t 15"); } } //长时间没有数则重启 1号机 1个半小时 if (MyFuncUtil.getMachineName().ToUpper().Equals("1HAO") && (js - ks2) > 1000 * 60 * 90) { ks2 = my.GetTimestamp(); ShouHu s = new ShouHu(); bool t = s.panDuanChongQi(MyFuncUtil.getMachineName()); t = false; if (!MyFuncUtil.getMachineName().ToLower().Equals("wlzhongkong") && t) { WriteLog.WriteLogFile("重启啦!!!"); System.Diagnostics.Process.Start("shutdown.exe", "-r -f -t 15"); } } //定时更新运行情况 if ((js - ks3) > 1000 * 60 * 20) { ks3 = MyFuncUtil.GetTimestamp(); DateTime dt = getYunXingQkLasttime(); TimeSpan span = DateTime.Now.Subtract(dt); //WriteLog.WriteLogFile("准备更新与上次统计相比,间隔 " + span.Minutes + "分钟"); if (span.Hours >= 1) { //WriteLog.WriteLogFile("与上次统计相比,间隔 " + span.Minutes + "分钟"); //gxYunXingQk("jingjieguanfang"); } } //检测wlxm if ((js - ks4) > 1000 * 60 * 10) { ks4 = MyFuncUtil.GetTimestamp(); Process current = Process.GetCurrentProcess(); string appname = "wlxm"; bool t = false; Process[] processes = Process.GetProcessesByName(appname); int a = 0; foreach (Process process in processes) { if (a == 0 && process.ProcessName == appname) { t = true; a = 1; break; } } if (!t) { ks8 = MyFuncUtil.GetTimestamp(); string appNamec = System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"; WriteLog.WriteLogFile("wlxm位置" + System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"); if (System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe")) { WriteLog.WriteLogFile("wlxm找到文件位置"); Process p = new Process(); p.StartInfo.FileName = appNamec; //启动程序 p.Start(); ks2 = my.GetTimestamp();//关机项重新计时 WriteLog.WriteLogFile("结束打开wlxm"); } } } //检测多开器 if ((js - ks5) > 1000 * 60 * 20) { ks5 = MyFuncUtil.GetTimestamp(); Process current = Process.GetCurrentProcess(); string appname = "dnmultiplayer"; bool t = false; Process[] processes = Process.GetProcessesByName(appname); foreach (Process process in processes) { if (process.ProcessName == appname) { t = true; duokai = 0; break; } } if (!t) { System.Threading.Thread.Sleep(30000); Process p = new Process(); p.StartInfo.FileName = @"D:\ChangZhi\dnplayer2\dnmultiplayer.exe"; //启动程序 p.Start(); WriteLog.WriteLogFile("结束打开多开器2"); System.Threading.Thread.Sleep(10000); } processes = Process.GetProcessesByName(appname); foreach (Process process in processes) { if (process.ProcessName == appname) { t = true; duokai = 0; break; } } if (!t) { duokai++; } if (!MyFuncUtil.getMachineName().ToLower().Equals("wlzhongkong") && duokai > 1) { WriteLog.WriteLogFile("dnmultiplayer不存在了"); //WriteLog.WriteLogFile("重启啦!!!"); //System.Diagnostics.Process.Start("shutdown.exe", "-r -f -t 15"); //WriteLog.WriteLogFile("结束打开dnmultiplayer"); } } //检测wlxm if ((js - ks6) > 1000 * 60 * 10) { ks6 = MyFuncUtil.GetTimestamp(); UpdateCaoZuo sh = new UpdateCaoZuo(); sh.updateWlxm(); } if ((js - ks7) > 1000 * 60 * 45) { ks7 = my.GetTimestamp(); ShouHu s = new ShouHu(); bool t = s.panDuanChongQi(MyFuncUtil.getMachineName()); t = false; if (t) { ks8 = MyFuncUtil.GetTimestamp(); MyFuncUtil.killProcess("wlxm"); System.Threading.Thread.Sleep(1000 * 50); string appname = "wlxm"; bool t1 = false; Process[] processes = Process.GetProcessesByName(appname); int a = 0; foreach (Process process in processes) { if (a == 0 && process.ProcessName == appname) { t1 = true; a = 1; break; } } if (!t1) { string appNamec = System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"; WriteLog.WriteLogFile("wlxm位置" + System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"); if (System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe")) { WriteLog.WriteLogFile("wlxm找到文件位置"); Process p = new Process(); p.StartInfo.FileName = appNamec; //启动程序 p.Start(); ks2 = my.GetTimestamp();//关机项重新计时 WriteLog.WriteLogFile("结束打开wlxm"); } } } } if ((js - ks8) > 1000 * 60 * 20) { ks8 = MyFuncUtil.GetTimestamp(); string dir = "C:\\mylog\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + "\\"; if (System.IO.Directory.Exists(dir))//文件夹是否存在 { System.IO.FileInfo[] fis = new System.IO.DirectoryInfo(dir).GetFiles(); int isalive = 0; if (fis != null && fis.Count() > 0) { for (int i1 = 0; i1 < fis.Length; i1++) { TimeSpan span = DateTime.Now.Subtract(fis[i1].LastWriteTime); if (span.TotalMinutes > 30) { isalive++; } } } if (isalive > 5) { WriteLog.WriteLogFile("超过5个模拟器长时间不更新了"); MyFuncUtil.killProcess("wlxm"); string appname = "wlxm"; Process[] processes = Process.GetProcessesByName(appname); int a = 0; bool t1 = false; foreach (Process process in processes) { if (a == 0 && process.ProcessName == appname) { t1 = true; a = 1; break; } } if (!t1) { string appNamec = System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"; WriteLog.WriteLogFile("wlxm位置" + System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe"); if (System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\program\\wlxm.exe")) { WriteLog.WriteLogFile("wlxm找到文件位置"); Process p = new Process(); p.StartInfo.FileName = appNamec; //启动程序 p.Start(); ks2 = my.GetTimestamp();//关机项重新计时 WriteLog.WriteLogFile("结束打开wlxm"); } } } } } if ((js - ks9) > 1000 * 60 * 20) { ks9 = MyFuncUtil.GetTimestamp(); string dir = "d:\\mylog\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + "\\"; if (System.IO.Directory.Exists(dir))//文件夹是否存在 { System.IO.FileInfo[] fis = new System.IO.DirectoryInfo(dir).GetFiles(); int isalive = 0; if (fis != null && fis.Count() > 0) { for (int i1 = 0; i1 < fis.Length; i1++) { TimeSpan span = DateTime.Now.Subtract(fis[i1].LastWriteTime); if (span.TotalMinutes > 30) { isalive++; } } } if (isalive > 0) { WriteLog.WriteLogFile("wlsh长时间不更新了"); MyFuncUtil.killProcess("wlsh"); string appname = "wlsh"; Process[] processes = Process.GetProcessesByName(appname); int a = 0; bool t1 = false; foreach (Process process in processes) { if (a == 0 && process.ProcessName == appname) { t1 = true; a = 1; break; } } if (!t1) { string appNamec = System.Windows.Forms.Application.StartupPath + "\\wlsh.exe"; WriteLog.WriteLogFile("wlsh位置" + System.Windows.Forms.Application.StartupPath + "\\wlsh.exe"); if (System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\wlsh.exe")) { WriteLog.WriteLogFile("wlsh找到文件位置"); Process p = new Process(); p.StartInfo.FileName = appNamec; //启动程序 p.Start(); ks2 = my.GetTimestamp();//关机项重新计时 WriteLog.WriteLogFile("结束打开wlsh"); } } } } } } }