예제 #1
0
        public async Task CacheBlock(List <string> IDs)
        {
            _Logger.LogInformation($"Caching {IDs.Count} characters");

            int blockSize = 20;

            for (int i = 0; i < IDs.Count; i += blockSize)
            {
                int           count = Math.Min(blockSize, IDs.Count - i);
                List <string> block = IDs.GetRange(i, count);

                CensusQuery query = _Census.Create("character");
                foreach (string ID in block)
                {
                    query.Where("character_id").Equals(ID);
                }
                query.AddResolve("outfit");
                query.AddResolve("outfit", "online_status");
                query.ShowFields("character_id", "name", "faction_id", "outfit", "online_status");

                List <JToken> tokens = (await query.GetListAsync()).ToList();
                foreach (JToken token in tokens)
                {
                    Character?c = _ParseCharacter(token);
                    if (c != null)
                    {
                        _Cache.TryAdd(c.ID, c);
                    }
                }

                //_Logger.LogInformation($"Cached {i}/{IDs.Count} characters");
            }
            _Logger.LogInformation($"Cached all characters");
        }
예제 #2
0
        private async Task <Character?> _GetCharacterFromCensus(string ID, bool retry)
        {
            CensusQuery query = _Census.Create("character");

            query.Where("character_id").Equals(ID);
            query.AddResolve("outfit", "online_status");
            query.ShowFields("character_id", "name", "faction_id", "outfit", "online_status");

            try {
                JToken result = await query.GetAsync();

                Character?player = _ParseCharacter(result);

                return(player);
            } catch (CensusConnectionException ex) {
                if (retry == true)
                {
                    _Logger.LogWarning("Retrying {Char} from API", ID);
                    return(await _GetCharacterFromCensus(ID, false));
                }
                else
                {
                    _Logger.LogError(ex, "Failed to get {0} from API", ID);
                    throw ex;
                }
            }
        }