internal async Task <Queue <Charts> > CallUpTheChartAsync(Codes codes) { var start = CodeStorage.LastOrDefault(o => o.Code.StartsWith(codes.Code.Substring(0, 3)) && o.Code.EndsWith(codes.Code.Substring(5)) && string.Compare(o.MaturityMarketCap.Length == 8 ? o.MaturityMarketCap.Substring(2) : o.MaturityMarketCap, codes.MaturityMarketCap.Length == 8 ? codes.MaturityMarketCap.Substring(2) : codes.MaturityMarketCap) < 0).MaturityMarketCap; var queue = new Queue <Charts>(); if (string.IsNullOrEmpty(start) && DateTime.TryParseExact(codes.MaturityMarketCap, ConvertDateTime(codes.MaturityMarketCap.Length), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime date)) { start = Array.Exists(this.codes, o => o.Equals(codes.Code)) ? Temporary.date : date.AddYears(-3).ToString(ConvertDateTime(6)); } if (await client.GetContext(new Catalog.Request.Charts { Code = codes.Code, Start = start.Length == 8 ? start.Substring(2) : start, End = codes.MaturityMarketCap.Length == 8 ? codes.MaturityMarketCap.Substring(2) : codes.MaturityMarketCap }) is IEnumerable <Charts> enumerable) { foreach (var arg in enumerable) { queue.Enqueue(arg); } } return(queue); }
public Hero(int id, double x, double y, CodeStorage codeInventory, EquipmentStorage equipmentInventory) : base(x: x, y: y) { HasCodeChanged = false; HasGearChanged = false; Algorithm = new BehaviourAlgorithm(this); Id = id; CodeInventory = codeInventory; EquipmentInventory = equipmentInventory; Points = 0; baseSpeed = Design.HeroSpeed; baseDamage = Damage; baseHp = Hp; ShootRateLimiter = new RateLimiter(Design.FireCooldown); controls = new Controls(ConsoleKey.Spacebar, ConsoleKey.W, ConsoleKey.S, ConsoleKey.A, ConsoleKey.D); syntheticControls = new Controls(ConsoleKey.Spacebar, ConsoleKey.W, ConsoleKey.S, ConsoleKey.A, ConsoleKey.D); CalculateStatsFromGear(); // Configure a Timer for use heartbeatTimer = new Timer { Interval = 2000 }; heartbeatTimer.Elapsed += new ElapsedEventHandler(CheckAliveness); heartbeatTimer.Enabled = true; IsAlive = true; TimeOfLastHeartbeat = DateTime.Now; }
public static void InitStaticValues() { if (allCards != null || allBuildings != null) { throw new AlhambraException("Reinitializing AlhambraInterface storage."); } allCards = new List <Card>(); allBuildings = new List <Building>(); CardType type = CardType.Blue; foreach (CardType t in Enum.GetValues(typeof(CardType))) { for (int value = Card.MinValue; value <= Card.MaxValue; value++) { allCards.Add(new Card(type, value)); } } CodeStorage cs = new CodeStorage(); cs.InitializeStorage(); allBuildings = cs.GetBuildingList(); }
internal async Task <Queue <Charts> > CallUpTheChartAsync(string code) { if (code.Length == 8 && code.StartsWith("1") && code.EndsWith("000") && code[1].Equals('0')) { code = CodeStorage.First(f => f.MaturityMarketCap.Equals(CodeStorage.Where(o => o.Code.Length == 8 && o.Code.StartsWith(code.Substring(0, 3)) && o.Code.EndsWith(code.Substring(5))).OrderBy(o => o.MaturityMarketCap.Length == 8 ? o.MaturityMarketCap.Substring(2) : o.MaturityMarketCap).First().MaturityMarketCap) && f.Code.StartsWith(code.Substring(0, 3)) && f.Code.EndsWith(code.Substring(5))).Code; } var queue = new Queue <Charts>(); if (await client.GetContext(new Catalog.Request.Charts { Code = code, Start = string.Empty, End = string.Empty }) is IEnumerable <Charts> enumerable) { foreach (var arg in enumerable) { queue.Enqueue(arg); } } return(queue); }
private void SetCache(string key, CodeStorage storage, TimeSpan?absoluteToNow) { var option = new MemoryCacheEntryOptions { Priority = this.CacheItemPriority, AbsoluteExpirationRelativeToNow = absoluteToNow }; this.Cache.Set(key, storage, option); }
/// <summary> /// 校验码发送次数周期持久化,如果接收方和业务标志组合已经存在,则进行覆盖 /// </summary> /// <param name="receiver">接收方</param> /// <param name="bizFlag">业务标志</param> /// <param name="period">周期时间范围</param> /// <returns></returns> public Task <bool> SetPeriod(string receiver, string bizFlag, TimeSpan?period) { var storage = new CodeStorage { Number = 1, }; var key = this.GetPeriodKey(receiver, bizFlag); this.SetCache(key, storage, period); return(Task.FromResult(true)); }
/// <summary> /// 将校验码进行持久化,如果接收方和业务标志组合已经存在,则进行覆盖 /// </summary> /// <param name="receiver">接收方</param> /// <param name="bizFlag">业务标志</param> /// <param name="code">校验码</param> /// <param name="effectiveTime">校验码有效时间范围</param> /// <returns></returns> public Task <bool> SetCode(string receiver, string bizFlag, string code, TimeSpan effectiveTime) { var storage = new CodeStorage { Code = code, Number = 0, StorageTime = DateTime.Now }; var key = this.GetCodeKey(receiver, bizFlag); this.SetCache(key, storage, effectiveTime); return(Task.FromResult(true)); }
async Task CallUpTheCodesAsync(int length) { if (CodeStorage == null) { Length = length; CodeStorage = (await client.GetContext(new Codes { }, length) as List <Codes>)?.ToHashSet(); if (length == 8) { RemainingDay = new HashSet <uint>() { 190910U, 191211U } } ; } else if (Length < length) { foreach (var code in client.GetContext(new Codes { }, length).Result as List <Codes> ) { if (CodeStorage.Add(code) && RemainingDay == null) { Length = length; RemainingDay = new HashSet <uint>() { 190910U, 191211U }; } } } } string ConvertDateTime(int length) { switch (length) { case 6: return(sFormat); case 8: return(lFormat); } return(null); }
private void btnAddRemoveCode_Click(object sender, EventArgs e) { if (_codeEntrySavedIndex == -1) { CodeStorage c = new CodeStorage(); c._code = _codeEntry.LinesNoSpaces; c._name = _codeEntry._name; c._description = _codeEntry._description; BrawlLib.Properties.Settings.Default.Codes.Add(c); _codeEntrySavedIndex = BrawlLib.Properties.Settings.Default.Codes.Count - 1; btnAddRemoveCode.Text = "Forget Code"; } else { BrawlLib.Properties.Settings.Default.Codes.RemoveAt(_codeEntrySavedIndex); _codeEntrySavedIndex = -1; btnAddRemoveCode.Text = "Remember Code"; } }