public LogTestBase(Level logLevel, ILogDataVerifier verifier) { this.verifier = verifier; LogLevel = logLevel; var timeToUse = new DateTime(2014, 12, 14, 16, 18, 20, 0, DateTimeKind.Utc); Time = new TimeProviderMock(timeToUse); timeSetter = new TimeSetter(Time); this.verifier.ClearLogData(); }
public void TimeSetterScopeTest() { var timeProviderMock = new TimeProviderMock(); DateTime mockTime; using (var timeSetter = new TimeSetter(timeProviderMock)) { mockTime = TimeProvider.UtcNow; } var expectedTime = new DateTime(2010, 1, 1); Assert.AreEqual(expectedTime, mockTime); Assert.AreNotEqual(expectedTime, TimeProvider.UtcNow); }
private void initConfig() { JToken cfg = config["TaskList"].Where(p => p["taskName"].ToString() == name()).ToArray()[0]["taskInfo"]; auctionStateColl = cfg["auctionStateColl"].ToString(); batchSize = int.Parse(cfg["batchSize"].ToString()); batchInterval = int.Parse(cfg["batchInterval"].ToString()); root = cfg["root"].ToString(); timeSetter = TimeConst.getTimeSetter(root); // db info localDbConnInfo = Config.localDbConnInfo; blockDbConnInfo = Config.blockDbConnInfo; // initSuccFlag = true; }
private JArray format(JArray res) { TimeSetter timeSetter = TimeConst.getTimeSetter(".test"); return(new JArray() { res.Select(p => { string fulldomain = p["fulldomain"].ToString(); if (fulldomain.EndsWith(".test")) { JObject jo = (JObject)p; long starttime = long.Parse(jo["startTime"]["blocktime"].ToString()); jo.Remove("ttl"); jo.Add("ttl", starttime + timeSetter.ONE_YEAR_SECONDS); return jo; } return p; }) }); }
private JArray format(JArray res) { if (res == null || res.Count == 0) { return(new JArray() { }); } return(new JArray() { res.Select(p => { JObject jo = (JObject)p; string fulldoamin = p["fulldomain"].ToString(); TimeSetter timeSetter = TimeConst.getTimeSetter(fulldoamin.Substring(fulldoamin.LastIndexOf("."))); if (fulldoamin.EndsWith(".test")) { long starttime = long.Parse(jo["startTime"]["blocktime"].ToString()); jo.Remove("ttl"); jo.Add("ttl", starttime + timeSetter.ONE_YEAR_SECONDS); } long st = long.Parse(jo["startTime"]["blocktime"].ToString()); long ed = long.Parse(jo["endTime"]["blocktime"].ToString()); if (ed > 0) { jo.Remove("lastTime"); return jo; } string auctionState = p["auctionState"].ToString(); long expireSeconds = 0; if (auctionState == "0201") { expireSeconds = st + timeSetter.THREE_DAY_SECONDS; } else if (auctionState == "0301") { expireSeconds = st + timeSetter.FIVE_DAY_SECONDS; } else if (auctionState == "0401") { long lt = long.Parse(jo["lastTime"]["blocktime"].ToString()); if (st + timeSetter.TWO_DAY_SECONDS >= lt) { expireSeconds = st + timeSetter.THREE_DAY_SECONDS; } else { expireSeconds = st + timeSetter.FIVE_DAY_SECONDS; } } if (expireSeconds > 0) { // 预计结束时间 JObject ep = (JObject)jo["endTime"]; long blocktime = long.Parse(ep["blocktime"].ToString()); long endBlockTime = blocktime + expireSeconds; ep.Remove("blocktime"); jo.Remove("endTime"); ep.Add("blocktime", endBlockTime); jo.Add("endTime", ep); // jo.Remove("lastTime"); } string value = jo["maxPrice"].ToString(); value = NumberDecimalHelper.formatDecimal(value); jo.Remove("maxPrice"); jo.Add("maxPrice", value); return jo; }) }); }
private JArray format(JArray res, bool isSearch = false) { if (res == null || res.Count == 0) { return(new JArray() { }); } long nowtime = TimeHelper.GetTimeStamp(); return(new JArray() { res.Select(p => { JObject jo = (JObject)p; // 格式转换 string value = jo["maxPrice"].ToString(); value = NumberDecimalHelper.formatDecimal(value); jo.Remove("maxPrice"); jo.Add("maxPrice", value); // 获取ttl string fulldoamin = p["fulldomain"].ToString(); long ttl = 0; if (isSearch) { var rr = getDomainInfo(fulldoamin); if (rr != null && rr.Count > 0) { if (p["auctionState"].ToString() == "0401" || p["auctionState"].ToString() == "0601") { JObject resJo = new JObject() { { "auctionId", p["auctionId"] }, { "fulldomain", p["fulldomain"] }, { "owner", rr[0]["owner"] }, { "ttl", rr[0]["TTL"] } }; string price; if (hasNNfixedSelling(p["fulldomain"].ToString(), long.Parse(p["startTime"]["blockindex"].ToString()), out price)) { resJo.Remove("auctionState"); resJo.Add("auctionState", "0901"); resJo.Add("price", price); return resJo; } resJo.Add("price", "0"); return resJo; /* * return new JObject() { * {"auctionId", p["auctionId"] }, * {"fulldomain", p["fulldomain"] }, * {"owner", rr[0]["owner"] }, * {"ttl", rr[0]["TTL"] } * }; */ } ttl = long.Parse(rr[0]["TTL"].ToString()); jo.Remove("ttl"); jo.Add("ttl", ttl); if (ttl > nowtime) { // 过期域名续约后状态需更新为0401 jo.Remove("auctionState"); jo.Add("auctionState", "0401"); } } } // 触发结束 long now = TimeHelper.GetTimeStamp(); long st = long.Parse(jo["startTime"]["blocktime"].ToString()); long ed = long.Parse(jo["endTime"]["blocktime"].ToString()); if (ed > 0) { jo.Remove("lastTime"); if (now >= ed && now <= ttl) { jo.Remove("auctionState"); jo.Add("auctionState", "0401"); } return jo; } // 计算预计结束时间 TimeSetter timeSetter = TimeConst.getTimeSetter(fulldoamin.Substring(fulldoamin.LastIndexOf("."))); string auctionState = p["auctionState"].ToString(); long expireSeconds = 0; if (auctionState == "0201") { expireSeconds = st + timeSetter.THREE_DAY_SECONDS; } else if (auctionState == "0301") { expireSeconds = st + timeSetter.FIVE_DAY_SECONDS; } else if (auctionState == "0401") { long lt = long.Parse(jo["lastTime"]["blocktime"].ToString()); if (st + timeSetter.TWO_DAY_SECONDS >= lt) { expireSeconds = st + timeSetter.THREE_DAY_SECONDS; } else { expireSeconds = st + timeSetter.FIVE_DAY_SECONDS; } } if (expireSeconds > 0) { JObject ep = (JObject)jo["endTime"]; long blocktime = long.Parse(ep["blocktime"].ToString()); long endBlockTime = blocktime + expireSeconds; ep.Remove("blocktime"); jo.Remove("endTime"); ep.Add("blocktime", endBlockTime); jo.Add("endTime", ep); // jo.Remove("lastTime"); } if (now >= expireSeconds && now <= ttl && auctionState == "0601") { jo.Remove("auctionState"); jo.Add("auctionState", "0401"); } return jo; }) }); }