Ejemplo n.º 1
0
        public async Task <CharacterInformation> ForEachPlog_GetInformation(ClanMember plog)
        {
            var start = DateTime.UtcNow;

            var tasks = new Task[]
            {
                _bladeAndSoulService.GetBladeAndSoulCharacter(plog.Name),
                _bladeAndSoulService.GetBladeAndSoulCharacterAbilities(plog.Name),
                _bladeAndSoulService.GetBladeAndSoulItemsAsync(plog.Name)
            };

            await Task.WhenAll(tasks);

            var character = ((Task <BladeAndSoulCharacter>)tasks[0]).Result;
            var stats     = ((Task <AbilitiesResult>)tasks[1]).Result;
            var items     = ((Task <BladeAndSoulItems>)tasks[2]).Result;

            if (character == null || stats == null || items == null)
            {
                // Try again later?
                return(null);
            }

            var isInClan = "Ploggystyle".Equals(character.Clan, StringComparison.OrdinalIgnoreCase);

            if (!isInClan && plog.Active)
            {
                await _webhookService.ExecuteInactivePlogWebhook($"{plog.Name} ({plog.RealName})");

                plog.Active = false;
                return(new CharacterInformation
                {
                    Plog = plog
                });
            }

            if (!plog.Active)
            {
                // Don't process
                return(null);
            }

            var end = DateTime.UtcNow;
            await _loggingService.LogAsync($"Processing time for {plog.Name}: {(end - start).TotalMilliseconds}");

            return(new CharacterInformation
            {
                Plog = plog,
                Character = character,
                AbilitiesResult = stats,
                Items = items
            });
        }