Example #1
0
        public static void GlobalStartup(TestContext testContext)
        {
            WowExplorer = new WowExplorer(Region.US);

            realms = WowExplorer.GetRealms();
            TestUtil.immortalityGuild = WowExplorer.GetGuild("skullcrusher", "immortality", GuildOptions.GetEverything);
        }
Example #2
0
        public static void GlobalStartup(TestContext testContext)
        {
            WowExplorer = new WowExplorer("us");

            realms = WowExplorer.GetRealms();
            TestUtil.immortalityGuild = WowExplorer.GetGuild("skullcrusher", "immortality", true, true);
        }
Example #3
0
        public static void GlobalStartup(TestContext testContext)
        {
            WowExplorer = new WowExplorer("us");

            realms = WowExplorer.GetRealms();
            TestUtil.immortalityGuild = WowExplorer.GetGuild("skullcrusher", "immortality", true, true);
        }
        public void DoWork()
        {
            using (var repository = _repositoryFactory.Invoke())
            {
                var guildMembers = RetryHelper.WithRetry(() => _wowClient.GetGuild(_configuration.Region, _configuration.Realm, _configuration.Guild, GuildOptions.GetEverything), 3)
                                   .Members
                                   .ToList();
                var characters = GetGuildCharacters(repository, guildMembers)
                                 // ReSharper disable once AccessToDisposedClosure
                                 .Select(data => CreateNewCharacter(repository, data))
                                 // ReSharper disable once AccessToDisposedClosure
                                 .Select(data => EnrichGuildData(repository, data))
                                 .AsParallel()
                                 .WithDegreeOfParallelism(5)
                                 .Select(c => (GetWoWCharacterData(c), c))
                                 .Where <(WowDotNetAPI.Models.Character character, Character)>(data => data.character != null)
                                 .ToList()
                                 .Select(EnrichCharacter)
                                 .ToList();

                repository.SaveChanges();

                characters.Where(c => c.Player == null)
                .ForEach(c =>
                {
                    // ReSharper disable once AccessToDisposedClosure
                    var existingCharacter = repository.Characters
                                            .ToList()
                                            .FirstOrDefault(ec => ec.AchievementPoints == c.AchievementPoints &&
                                                            ec.AchievementsHash == c.AchievementsHash &&
                                                            ec.PetsHash == c.PetsHash &&
                                                            ec.Player != null);

                    // ReSharper disable once AccessToDisposedClosure
                    c.Player = existingCharacter?.Player ?? repository.Players.Create();
                });

                repository.SaveChanges();

                characters.Select(c => c.Player)
                .Distinct()
                .ForEach(player =>
                {
                    var main = player
                               .Characters
                               .Where(c => c.CurrentMembershipState.State == GuildMemberState.Joined)
                               // ReSharper disable once PossibleNullReferenceException
                               .GroupBy(c => c.Rank.Rank)
                               .OrderBy(c => c.Key)
                               .ToList();

                    player.Characters.ForEach(c => c.IsMain = false);

                    if (main.Any() && main.First().Count() == 1)
                    {
                        main.First()
                        .First()
                        .IsMain = true;
                    }
                });

                repository.SaveChanges();

                characters.Where(data => data.CurrentMembershipState.DiscordMessage == null)
                // ReSharper disable once AccessToDisposedClosure
                .Select(data => CreateAndBuildDiscordMessage(repository, data))
                .ForEach(_discordMessageSender.SendMessage);

                repository.SaveChanges();
            }
        }