public static object Get(string url, string cmd, string method, object args) { var retryCount = 5; while (0 < retryCount) { retryCount--; LOGGER.Log(string.Format("调用NodeService 还剩余{0}次", retryCount)); var json = string.Empty; var context = new { CMD = cmd, Method = method, Args = args }; try { json = Convertor.FromObjectToJson(context); var httpdownloader = new HTTP(); var resString = httpdownloader.Post(url, Encoding.UTF8, json); var res = Convertor.FromJsonToDict2(resString)["RES"]; return(res); } catch (Exception e) { LOGGER.Log(string.Format("调用NodeService的时候,发生异常:{0} {1}", e.Message, DateTime.Now)); LOGGER.Log(string.Format("参数:", args)); //var db = DataStorage.GetInstance(DBType.MongoDB); //db.Save(new { Args = Convertor.FromObjectToDictionary(args), CreateTime = DateTime.Now, Message = e.Message }, "Exception", "StockService"); LOGGER.Beep(); Thread.Sleep(new TimeSpan(0, 5, 0)); } } return(null); }
/// <summary> /// 不断更新最新的新闻 /// </summary> public void SyncStockNews() { var startTime = DateTime.Now;///开始运行时间 Console.Title = "同花顺财经要闻 更新进程 启动时间:" + startTime; var exe = StockTaskExecutor.CreateInstance(); while (true) { try { if (CONST.IsSafeUpdateTime(1)) { exe.GetNewsListCJYW(DateTime.Now.ToShortDateString()); ///非交易时间 if (DateTime.Now.Hour < 6 || DateTime.Now.Hour > 23) ///6点前,23点后 { exe.GetNewsListCJYW(DateTime.Now.AddDays(-1).ToShortDateString()); exe.GetNewsListCJYW(DateTime.Now.AddDays(-2).ToShortDateString()); exe.GetNewsListCJYW(DateTime.Now.AddDays(-3).ToShortDateString()); exe.GetNewsListCJYW(DateTime.Now.AddDays(-4).ToShortDateString()); exe.GetNewsListCJYW(DateTime.Now.AddDays(-5).ToShortDateString()); exe.GetNewsListCJYW(DateTime.Now.AddDays(-6).ToShortDateString()); exe.GetNewsListCJYW(DateTime.Now.AddDays(-7).ToShortDateString()); ThreadManager.Pause(hours: 1); ///凌晨一小时更新一次 } else { ThreadManager.Pause(minutes: 10); ///10分钟更新一次新闻 } } else { exe.GetNewsListCJYW(DateTime.Now.ToShortDateString()); ///交易时间 ThreadManager.Pause(minutes: 3); ///3分钟更新一次新闻 } LOGGER.Log(string.Format("自动新闻更新 已运行时间 {0}", DateTime.Now - startTime)); } catch (Exception e) { LOGGER.Log(string.Format("异常:{0}", e.Message)); LOGGER.Log(string.Format("位置:{0}", e.StackTrace)); LOGGER.Beep(); ThreadManager.Pause(minutes: 1); ///停一分钟 } } }