public override void Run() { string strsql = "exec usp_rims_wx_notifydoctor @cxlb=2"; DataTable dt = GlobalInstanceManager <GlobalSqlManager> .Intance.GetDataTable(this.Cur_Job.dbtype, this.Cur_Job.dbstring, strsql); if (dt == null || dt.Rows.Count <= 0) { return; } var list = dt.AsEnumerable().GroupBy(a => new { ysdm = a["ysdm"].ToString(), ysmc = a["ysmc"].ToString(), idNo = a["wxsbh"].ToString(), idType = a["wxklx"].ToString(), content = a["txnr"].ToString() }). Select(a => new { ysdm = a.Key.ysdm, ysmc = a.Key.ysmc, idNo = a.Key.idNo, idType = a.Key.idType, content = a.Key.content, list = a.ToList() }); foreach (var item in list) { FszyyWeChatMessage msg = new FszyyWeChatMessage(); msg.url = ""; msg.content = item.content; msg.idNo = item.idNo; msg.idType = item.idType; string result = this.PostRequest(JsonConvert.SerializeObject(msg)); Log4netUtil.Info("作业【" + this.Cur_Job.name + "】返回值:" + result); FszyyWeChatResult fr = JsonConvert.DeserializeObject <FszyyWeChatResult>(result); if (fr != null && fr.code == "0") { strsql = "exec usp_rims_wx_notifydoctor @cxlb=1,@txxh='" + string.Join(",", item.list.Select(a => a["xh"].ToString())) + "'"; DataTable redt = GlobalInstanceManager <GlobalSqlManager> .Intance.GetDataTable(this.Cur_Job.dbtype, this.Cur_Job.dbstring, strsql); } } }
static void Main(string[] args) { HandleLog.WriteServerLog += (log) => { Log4netUtil.Info(log); Console.WriteLine(log); }; var url = "http://+:9999"; var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup <Startup>() .UseUrls(url) .Build(); using (host) { host.Run(); Console.WriteLine("Running on {0}", url); Console.WriteLine("Press enter to exit"); Console.ReadKey(); } }
public virtual string WebRequest() { try { string requestxml = !this.Cur_Job.isdbpara?this.Cur_Job.requestxml: GlobalInstanceManager <GlobalSqlManager> .Intance.GetDataTable(0, this.Cur_Job.targetdbstring, this.Cur_Job.requestxml).Rows[0][0].ToString(); Log4netUtil.Info("作业【" + this.Cur_Job.name + "】Run入参:" + requestxml); string userid = this.Cur_Job.isencode ? SecurityHelper.DESEnCode(this.Cur_Job.CloudUserId, this.Cur_Job.Key) : this.Cur_Job.CloudUserId; string password = this.Cur_Job.isencode ? SecurityHelper.DESEnCode(this.Cur_Job.CloudUserPassword, this.Cur_Job.Key) : this.Cur_Job.CloudUserPassword; string xml = this.Cur_Job.isencode ? SecurityHelper.DESEnCode(requestxml, this.Cur_Job.Key) : requestxml; string retxml = ""; using (WebReference.NetHisWebService websrv = new WebReference.NetHisWebService()) { websrv.Url = this.Cur_Job.weburl; retxml = websrv.nethis_common_business(userid, password, this.Cur_Job.businesscode, xml); } Log4netUtil.Info("作业【" + this.Cur_Job.name + "】Run出参:" + retxml); return(retxml); } catch (Exception ex) { Log4netUtil.Error("作业【" + this.Cur_Job.name + "】WebRequest发生异常:" + ex.Message, ex); return(""); } }
public override string PostRequest(string body) { string result = ""; try { Dictionary <string, string> header = new Dictionary <string, string>(); // header.Add("Content-Type", "application/x-www-form-urlencoded"); header.Add("Authorization", "Basic c21zc2VydmVyLWFwaTpiYTVjOTYzNjkxYjM5ZjlkZWQwZDI2OGZkMWI5ZTNkYjgyYTI1M2RlZmMx"); string hresult = GlobalWebRequestHelper.HttpPostRequestWithHeader(this.Cur_Job.tokenweburl, "", "json", "x-www-form-urlencoded", header); Log4netUtil.Info("作业【" + this.Cur_Job.name + "】获取token值:" + hresult); HaToken token = JsonConvert.DeserializeObject <HaToken>(hresult); if (token != null && !string.IsNullOrEmpty(token.access_token)) { header.Clear(); //header.Add("Content-Type", "application/json"); header.Add("Authorization", token.token_type + " " + token.access_token); result = GlobalWebRequestHelper.HttpPostRequestWithHeader(this.Cur_Job.weburl, body, "json", "json", header); } } catch (Exception ex) { Log4netUtil.Error("作业【" + this.Cur_Job.name + "】PostRequest推送异常:" + ex.Message + "|参数:" + body, ex); } return(result); }
public override void Run() { string strsql = "exec usp_rims_sms_notifypat @cxlb=0"; DataTable dt = GlobalInstanceManager <GlobalSqlManager> .Intance.GetDataTable(this.Cur_Job.dbtype, this.Cur_Job.dbstring, strsql); if (dt == null || dt.Rows.Count <= 0) { return; } var list = dt.AsEnumerable().GroupBy(a => new { lxdh = a["lxdh"].ToString() }). Select(a => new { lxdh = a.Key.lxdh, list = a.ToList() }); foreach (var item in list) { HaSmsMessage msg = new HaSmsMessage(); SendPara para = new SendPara(); para.recive = new List <string>(); para.contentMap.content = "请合理安排到院治疗时间,厦门弘爱康复医院关心您! 注意:因疫情防控需要,厦门弘爱康复医院治疗中心(综合楼3楼)实行封闭管理,长期门诊康复治疗患者持15天内核酸报告进入治疗。家属陪护谢绝入内,感谢您的支持和理解,祝您早日康复!"; para.recive.Add(item.lxdh); msg.alermMsgInfo.Add(para); string result = this.PostRequest(JsonConvert.SerializeObject(msg)); Log4netUtil.Info("作业【" + this.Cur_Job.name + "】返回值" + result); HaResult r = JsonConvert.DeserializeObject <HaResult>(result); if (r != null && r.code == "0") { strsql = "exec usp_rims_sms_notifypat @cxlb=1,@txxh='" + string.Join(",", item.list.Select(a => a["xh"].ToString())) + "'"; DataTable redt = GlobalInstanceManager <GlobalSqlManager> .Intance.GetDataTable(this.Cur_Job.dbtype, this.Cur_Job.dbstring, strsql); } } }
public static void Init() { var builder = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("appsettings.json", false); var configuration = builder.Build(); //加载配置到全局 GlobalConfig.ConnetionString = configuration.GetValue <string>("DBConfig:ConnetionString"); GlobalConfig.NatPort = configuration.GetValue <int>("ServerConfig:NatPort"); GlobalConfig.ServerPort = configuration.GetValue <int>("ServerConfig:ServerPort"); GlobalConfig.DefaultUrl = configuration.GetValue <string>("ServerConfig:DefaultUrl"); GlobalConfig.RegRoleId = configuration.GetValue <string>("ServerConfig:RegRoleId"); Repository = LogManager.CreateRepository("NETCoreRepository"); XmlConfigurator.Configure(Repository, new FileInfo("log4net.config")); Log4netUtil.LogRepository = Repository;//类库中定义的静态变量 HandleLog.WriteLog += (log, isPrint) => { if (isPrint) { Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,ffff} {log}"); } Log4netUtil.Info(log); }; Task.Run(() => { while (true) { //更新假在线的主机 using var bll = new ClientBll(); var res = bll.UpdateOfflineClient(); HandleLog.WriteLine(res.Message, false); Thread.Sleep(60000); } }); var appSettingSetion = configuration.GetSection("AppSettingConfig"); var appSettingConfig = appSettingSetion.Get <AppSettingConfig>(); IocUnity.AddSingleton <AppSettingConfig>(appSettingConfig); //var setion = configuration.GetSection("SimpleSocketConfig"); //var simpleConfig = setion.Get<SimpleSocketConfig>(); //IocUnity.AddSingleton<SimpleSocketConfig>(simpleConfig); var loggerSection = configuration.GetSection("LogConfig"); var logConfig = loggerSection.Get <LogConfig>(); logConfig.LogBaseDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, logConfig.LogBaseDir); IocUnity.AddSingleton <LogConfig>(logConfig); InitAppSetting(); InitLog(); }
public void Start() { //TODO Console.WriteLine放在线程里会阻塞 放在主线程待测试是否阻塞 HandleLog.WriteLog += (log, isPrint) => { if (isPrint) { Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,ffff} {log}"); } Log4netUtil.Info(log); }; Task.Run(() => { try { Repository = LogManager.CreateRepository("NETCoreRepository"); XmlConfigurator.Configure(Repository, new FileInfo("log4net.config")); Log4netUtil.LogRepository = Repository;//类库中定义的静态变量 //加载映射列表 var maps = GetMapList(Secret); while (!maps.Result && maps.Status == -1) { maps = GetMapList(Secret); //请求失败5s后重新请求 HandleLog.WriteLine($"请求获取映射列表失败!5s后重新请求!"); Thread.Sleep(5000); } MapList = maps.Data ?? new List <Map>(); //连接服务器 ConnectNatServer(); //开启重连线程 reConnectThread = new Thread(ReConnect) { IsBackground = true }; reConnectThread.Start(); //开启心跳线程 heartThread = new Thread(SendHeart) { IsBackground = true }; heartThread.Start(); } catch (Exception ex) { HandleLog.WriteLine($"{ex}"); } }); }
public virtual void ExcuteDataBaseBulk(DataTable dt) { if (dt != null && dt.Rows.Count > 0) { int dbtype = this.Cur_Job.targetdbtype; string connstring = this.Cur_Job.targetdbstring; string createtmp = this.Cur_Job.createtmp; string tmpname = this.Cur_Job.tmpname; string strsql = this.Cur_Job.targetsql; GlobalInstanceManager <GlobalSqlManager> .Intance.BulkDb(dbtype, connstring, createtmp, tmpname, strsql, dt); } else { Log4netUtil.Info("作业【" + this.Cur_Job.name + "】接口无返回数据"); } }
public override void Run() { string strsql = "exec usp_rims_wx_notifypatient"; DataTable dt = GlobalInstanceManager <GlobalSqlManager> .Intance.GetDataTable(this.Cur_Job.dbtype, this.Cur_Job.dbstring, strsql); if (dt == null || dt.Rows.Count <= 0) { return; } var list = dt.AsEnumerable().GroupBy(a => new { patid = a["patid"].ToString(), yydm = a["yydm"].ToString(), xtbz = a["xtbz"].ToString(), idNo = a["wxsbh"].ToString(), idType = a["wxklx"].ToString(), hzxm = a["hzxm"].ToString() }).Select(a => new { hzxm = a.Key.hzxm, patid = a.Key.patid, yydm = a.Key.yydm, xtbz = a.Key.xtbz, idNo = a.Key.idNo, idType = a.Key.idType, list = a.ToList() }); foreach (var item in list) { FszyyWeChatMessage msg = new FszyyWeChatMessage(); string content = "您好," + item.hzxm + ":您有新治疗需要预约,点击此消息,即可进入预约界面"; //msg.url = "https://wx.fshtcm.com.cn/pat-web/s/oauth/authorize?entry=rims&client=wx"; msg.url = string.Format("http://rims.fshtcm.com.cn/medicalAppointments/orderRecod?PATIENTID={0}&HOSPITALCODE={1}&XTBZ={2}", item.patid, item.yydm, item.xtbz); msg.content = content; msg.idNo = item.idNo; msg.idType = item.idType; string result = this.PostRequest(JsonConvert.SerializeObject(msg)); Log4netUtil.Info("作业【" + this.Cur_Job.name + "】返回值:" + result); FszyyWeChatResult fr = JsonConvert.DeserializeObject <FszyyWeChatResult>(result); if (fr != null && fr.code == "0") { strsql = "exec usp_rims_wx_notifypatient @cxlb=1,@txxh='" + string.Join(",", item.list.Select(a => a["xh"].ToString())) + "'"; DataTable redt = GlobalInstanceManager <GlobalSqlManager> .Intance.GetDataTable(this.Cur_Job.dbtype, this.Cur_Job.dbstring, strsql); } } }
private void Init() { try { GlobalInstanceManager <FollowMainWinHelper> .Intance = new FollowMainWinHelper(this); this.LoadConsole(); Log4netUtil.IsLog = AppSetting.Default.islog; GlobalInstanceManager <SchedulerManager> .Intance.InitTask(); this.LoadJobInfo(); this.SetJobBaseInfo(); Log4netUtil.Info("初始化加载完成"); Tools.FlushMemory(); } catch (Exception ex) { Log4netUtil.Error("初始化发生异常:" + ex.Message, ex); } }
public void Start() { HandleLog.WriteLog += (log, isPrint) => { if (isPrint) { Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,ffff} {log}"); } Log4netUtil.Info(log); }; Task.Run(() => { try { Repository = LogManager.CreateRepository("NETCoreRepository"); XmlConfigurator.Configure(Repository, new FileInfo("log4net.config")); Log4netUtil.LogRepository = Repository;//类库中定义的静态变量 //连接服务器 ConnectNatServer(); //开启重连线程 reConnectThread = new Thread(ReConnect) { IsBackground = true }; reConnectThread.Start(); //开启心跳线程 heartThread = new Thread(SendHeart) { IsBackground = true }; heartThread.Start(); } catch (Exception ex) { HandleLog.WriteLine($"Start Error:{ex}"); } }); }
public static HttpResponseMessage Request(string method, string url, string postData = null, Dictionary <string, string> headers = null, string contentType = null, int timeout = 60, Encoding encoding = null) { HttpResponseMessage result = new HttpResponseMessage(); HttpClient client = null; try { if (url.StartsWith("https")) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; } //反向代理手动设置cookies client = new HttpClient(new HttpClientHandler() { UseCookies = false }); if (headers != null) { if (DefaultRequestHeadersKeys == null) { DefaultRequestHeadersKeys = client.DefaultRequestHeaders.GetType().GetProperties().Select(s => s.Name).ToList(); } foreach (KeyValuePair <string, string> header in headers) { try { if (DefaultRequestHeadersKeys.Contains(header.Key)) { continue; } client.DefaultRequestHeaders.Add(header.Key, header.Value); //Console.WriteLine($"正确添加的header:{header.Key}"); } catch { //Console.WriteLine($"错误添加的header:{header.Key}"); } } } if (timeout > 0) { client.Timeout = new TimeSpan(0, 0, timeout); } using (HttpContent content = new StringContent(postData ?? "", encoding ?? Encoding.UTF8)) { if (!string.IsNullOrEmpty(contentType)) { content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType); } //先不释放 switch (method.ToUpper()) { case "POST": result = client.PostAsync(url, content).Result; break; case "GET": result = client.GetAsync(url).Result; break; case "PUT": result = client.PutAsync(url, content).Result; break; case "DELETE": result = client.DeleteAsync(url).Result; break; case "OPTIONS": result.StatusCode = HttpStatusCode.NoContent; result.Content = new StringContent(""); break; } } Log4netUtil.Info($"请求地址:{url}{Environment.NewLine}请求参数:{postData}{Environment.NewLine}返回结果:{result.ToString()}"); } catch (Exception ex) { Log4netUtil.Error("Api接口出错了", ex.InnerException ?? ex); Console.WriteLine($"Api接口出错了:{ex.InnerException ?? ex}"); } finally { client.Dispose(); } return(result); }
static object lockLog = new object();//日志锁 public static void Init() { var builder = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("appsettings.json", false); var configuration = builder.Build(); //加载配置到全局 GlobalConfig.ConnetionString = configuration.GetValue <string>("DBConfig:ConnetionString"); GlobalConfig.NatPort = configuration.GetValue <int>("ServerConfig:NatPort"); GlobalConfig.ServerPort = configuration.GetValue <int>("ServerConfig:ServerPort"); GlobalConfig.DefaultUrl = configuration.GetValue <string>("ServerConfig:DefaultUrl"); GlobalConfig.RegRoleId = configuration.GetValue <string>("ServerConfig:RegRoleId"); var repository = LogManager.CreateRepository("NETCoreRepository"); XmlConfigurator.Configure(repository, new FileInfo("log4net.config")); Log4netUtil.LogRepository = repository;//类库中定义的静态变量 LogHelper.WriteLog += (level, log, isPrint) => { lock (lockLog) { switch (level) { case LogLevel.Debug: Log4netUtil.Debug(log); break; case LogLevel.Information: Console.ForegroundColor = ConsoleColor.Green; Log4netUtil.Info(log); break; case LogLevel.Warning: Console.ForegroundColor = ConsoleColor.Yellow; Log4netUtil.Warn(log); break; case LogLevel.Error: Console.ForegroundColor = ConsoleColor.Red; Log4netUtil.Error(log); break; case LogLevel.Critical: Console.ForegroundColor = ConsoleColor.DarkRed; Log4netUtil.Fatal(log); break; default: Console.ForegroundColor = ConsoleColor.Green; Log4netUtil.Info(log); break; } if (isPrint) { Console.Write(LogHelper.GetString(level)); Console.ResetColor(); Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,ffff} {log}"); } } }; Task.Run(() => { while (true) { //更新假在线的主机 var bll = new ClientBll(); var res = bll.UpdateOfflineClient(); LogHelper.Info(res.Message, false); Thread.Sleep(60000); } }); var appSettingSetion = configuration.GetSection("AppSettingConfig"); var appSettingConfig = appSettingSetion.Get <AppSettingConfig>(); AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; }
void tableSynchDAO_OutputInfo(string info, eOutputType outputType) { OutputRunInfo(rtxtOutput, info, outputType); Log4netUtil.Info(info); }
void grabPerformer_OutputInfo(string info) { OutputRunInfo(rtxtOutput, info); Log4netUtil.Info(info); }
static object lockLog = new object();//日志锁 public static void Start() { Task.Run(() => { try { //初始化配置 var builder = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("appsettings.json", false); var configuration = builder.Build(); Secret = configuration.GetValue <string>("Secret"); ServerUrl = configuration.GetValue <string>("ServerUrl"); ServerPort = configuration.GetValue <int>("ServerPort"); NatPort = configuration.GetValue <int>("NatPort"); var repository = LogManager.CreateRepository("NETCoreRepository"); XmlConfigurator.Configure(repository, new FileInfo("log4net.config")); Log4netUtil.LogRepository = repository;//类库中定义的静态变量 LogHelper.WriteLog += (level, log, isPrint) => { lock (lockLog) { switch (level) { case LogLevel.Debug: Log4netUtil.Debug(log); break; case LogLevel.Information: Console.ForegroundColor = ConsoleColor.Green; Log4netUtil.Info(log); break; case LogLevel.Warning: Console.ForegroundColor = ConsoleColor.Yellow; Log4netUtil.Warn(log); break; case LogLevel.Error: Console.ForegroundColor = ConsoleColor.Red; Log4netUtil.Error(log); break; case LogLevel.Critical: Console.ForegroundColor = ConsoleColor.DarkRed; Log4netUtil.Fatal(log); break; default: Console.ForegroundColor = ConsoleColor.Green; Log4netUtil.Info(log); break; } if (isPrint) { Console.Write(LogHelper.GetString(level)); Console.ResetColor(); Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss,ffff} {log}"); } } }; //连接服务器 ConnectNatServer(); //开启重连线程 reConnectThread = new Thread(ReConnect) { IsBackground = true }; reConnectThread.Start(); //开启心跳线程 heartThread = new Thread(SendHeart) { IsBackground = true }; heartThread.Start(); } catch (Exception ex) { LogHelper.Info($"Start Error:{ex}"); } }); }