/// <summary> /// 奖金池录入 /// </summary> /// <param name="gameName"></param> /// <param name="info"></param> /// <returns></returns> public bool BonusPoolStart(string gameName, OpenDataInfo info) { bool bol = true; string tablename = Lottery.CrawGetters.InitConfigInfo.MongoSettings["BonusPoolTableName"].ToString(); string content = KaSon.FrameWork.Common.JSON.JsonHelper.Serialize(info); BsonDocument bson = new BsonDocument(); bson.Add("GameCode", info.GameCode); bson.Add("IssuseNumber", info.IssuseNumber); bson.Add("Content", content); // new BsonDocument { { "GameCode", info.GameCode }, { "Age", 20 } } var fileName = string.Format("{0}_{1}.json", info.GameCode, info.IssuseNumber); // this.WriteLog(string.Format("已成功采集到{0}第{1}期奖池数据,开始写入文件{2}", info.GameCode, info.IssuseNumber, fileName)); var coll = mDB.GetCollection <BsonDocument>(tablename); //var options = new UpdateOptions { IsUpsert = true }; var mFilter = MongoDB.Driver.Builders <MongoDB.Bson.BsonDocument> .Filter.Eq("GameCode", info.GameCode) & Builders <BsonDocument> .Filter.Eq("IssuseNumber", info.IssuseNumber); // var mUpdateDocument =Builders<MongoDB.Bson.BsonDocument>.Update.Set("Content", content); var count = coll.Find(mFilter).CountDocuments(); try { if (count > 0) { //Thread.Sleep(2000); } else { coll.DeleteMany(mFilter); coll.InsertOne(bson); } try { BonusPoolManager bm = new BonusPoolManager(content); bm.UpdateBonusPool_SZC(info.GameCode, info.IssuseNumber); } catch (Exception) { bol = false; } } catch (Exception) { bol = false; } return(bol); }
private EntityModel.Enum.BonusPoolResult CrawStart(string gameCode, Func <string, OpenDataInfo, bool> fn) { // bool bol = true; try { // if (BeStop) // { // WriteLog("------------------------BeStop------------------------------" + gameCode); // return; // } // //// // //var info11 = OpenDataGetter.CreateInstance("aicaipiao").GetOpenData(gameCode, ""); // //// // this.WriteLog(string.Format("CollectBonusPool 开始--> 查询{0}奖期奖池 ", gameCode)); // int timeSpan = ServiceHelper.GetAutoDoCollectBonusPoolInterval(); // this.WriteLog(string.Format("{0}毫秒后开始自动执行奖池数据采集", timeSpan)); //timer = ServiceHelper.ExcuteByTimer(timeSpan, () => //{ // this.WriteLog("倒计时完成。自动执行奖池数据采集"); string tablename = InitConfigInfo.MongoSettings["BonusPoolTableName"].ToString(); try { if (gameCode != "SSQ" && gameCode != "DLT") { return(BonusPoolResult.NoGameCode); } //开始取奖池 int maxRepeatTimes = 5; string value = InitConfigInfo.BonusPoolSetting["CollectBonusPool_InterfaceType_" + gameCode].ToString(); string[] interfaceTypeArray = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);// ServiceHelper.GetCollectBonusPoolInterfaceTypeArray(gameCode); var info = new OpenDataInfo(); var i = 0; var currentTimes = 0; while (true) { try { if (Interlocked.Read(ref BeStop) != 0) { break; } if (currentTimes >= maxRepeatTimes) { break; } var t = interfaceTypeArray[i]; //this.WriteLog("使用采集接口 " + t + " 第 " + currentTimes + " 次"); info = OpenDataGetter.CreateInstance(t).GetOpenData(gameCode, ""); //this.WriteLog(string.Format("已采集到奖池信息,{0}第{1}期", info.GameCode, info.IssuseNumber)); if (info != null && !string.IsNullOrEmpty(info.IssuseNumber) && info.GameCode == gameCode) { break; } if (i >= interfaceTypeArray.Length - 1) { i = 0; } else { i++; } currentTimes++; } catch (Exception ex) { currentTimes++; this.WriteError("采集奖池数据异常 " + ex.ToString()); } } if (info.GradeList.Count == 0) { this.WriteLog("奖池采集完成,但未获取到奖池信息,请手工处理"); return(BonusPoolResult.CompleteNoData); } var bol = fn(gameCode, info); if (!bol) { this.WriteError("数据库同步异常 "); return(BonusPoolResult.Fail); } ; } catch (Exception ex) { this.WriteError("异常 " + ex.ToString()); } // }); } catch (Exception ex) { this.WriteError("异常 " + ex.ToString()); return(BonusPoolResult.Error); } return(BonusPoolResult.Success); }