Beispiel #1
0
        private Func <Task <CacheResult <StoredRealm> > > GetFromSource(string name, EfEnums.GameRegionEnum region)
        {
            return(async() =>
            {
                var result = await this.guildService.GetRealmAsync(name, BlizzardUtilities.GetBlizzardRegionFromEfRegion(region));

                if (result == null)
                {
                    return new CacheResult <StoredRealm>()
                    {
                        Found = false
                    };
                }

                return new CacheResult <StoredRealm>()
                {
                    Found = true,
                    Result = new StoredRealm()
                    {
                        RegionId = (int)region,
                        Name = result.Name,
                        Slug = result.Slug
                    }
                };
            });
        }
Beispiel #2
0
 public async Task <StoredRealm> GetRealmAsync(string name, EfEnums.GameRegionEnum region)
 {
     return(await this.cache.GetOrCacheAsync(
                this.GetFromDatabase(name, region),
                this.GetFromSource(name, region),
                this.Store(),
                this.GetKey(name, region)));
 }
Beispiel #3
0
 private Func <Task <StoredRealm> > GetFromDatabase(string name, EfEnums.GameRegionEnum region)
 {
     return(async() =>
     {
         return await this.context.StoredRealms
         .Include(r => r.Region)
         .SingleOrDefaultAsync(x => x.Slug == BlizzardService.BuildRealmSlug(name) &&
                               x.RegionId == (int)region);
     });
 }
Beispiel #4
0
        public async Task <IEnumerable <Realm> > GetRealms(EfEnums.GameRegionEnum region)
        {
            return(await this.cache.GetOrCacheAsync(async() =>
            {
                var json = await this.blizzardService.GetRealmsByRegionAsync(BlizzardUtilities.GetBlizzardRegionFromEfRegion(region));

                return RealmParsing.GetRealms(json);
            },
                                                    () => this.GetKey(region)));
        }
Beispiel #5
0
        private Func <string> GetKey(string name, EfEnums.GameRegionEnum region)
        {
            return(() =>
            {
                var realmKey = Keyifier.GetGuildKey(name);
                var regionKey = Keyifier.GetRegionKey(region);

                return Keyifier.GetKey("realmbyvalues", new List <string>()
                {
                    realmKey, regionKey
                });
            });
        }
Beispiel #6
0
        public async Task <int> CreateGuildProfileAsync(
            string creatorId,
            string profileName,
            GuildSlim guild,
            EfModels.StoredBlizzardModels.StoredRealm realm,
            EfEnums.GameRegionEnum region,
            bool isPublic)
        {
            using (var transaction = await this.context.Database.BeginTransactionAsync())
            {
                var newProfile = new EF.Models.GuildProfile()
                {
                    CreatorId   = creatorId,
                    ProfileName = profileName,
                    RealmId     = realm.Id,
                    IsPublic    = isPublic
                };

                this.context.GuildProfile.Add(newProfile);

                await this.context.SaveChangesAsync();

                EfModels.StoredBlizzardModels.StoredGuild storedGuild = new EfModels.StoredBlizzardModels.StoredGuild()
                {
                    Name      = guild.Name,
                    RealmId   = realm.Id,
                    ProfileId = newProfile.Id
                };

                this.context.StoredGuilds.Add(storedGuild);
                newProfile.CreatorGuild = storedGuild;

                if (!isPublic)
                {
                    this.context.User_GuildProfilePermissions.Add(new EF.Models.User_GuildProfilePermissions()
                    {
                        PermissionLevelId = (int)EF.Models.Enums.GuildProfilePermissionLevel.Admin,
                        ProfileId         = newProfile.Id,
                        UserId            = creatorId
                    });
                }

                await this.context.SaveChangesAsync();

                transaction.Commit();

                return(newProfile.Id);
            }
        }
Beispiel #7
0
        private async Task <IEnumerable <EfBlizzardModels.StoredPlayer> > GetOrInsertProfileGuildMembers(int profileId, EfBlizzardModels.StoredGuild guild, EfBlizzardModels.StoredRealm realm, EfEnums.GameRegionEnum region)
        {
            var members = await this.guildMemberCache.GetMembers(region, realm.Name, guild.Name);

            var realmNames = members.Select(x => x.PlayerRealmName).Distinct();

            var realmsTasks = realmNames.Select(async x => await this.realmStoreByValues.GetRealmAsync(x, region));
            await Task.WhenAll(realmsTasks);

            var realms = realmsTasks.Select(x => x.Result);

            var newPlayers = await this.dataRepo.InsertGuildPlayersIfNeededAsync(members.Select(x =>
                                                                                                new EfBlizzardModels.StoredPlayer()
            {
                Name      = x.PlayerName,
                Class     = x.Class,
                Level     = x.Level,
                GuildId   = guild.Id,
                RealmId   = realms.SingleOrDefault(y => y.Name == x.PlayerRealmName).Id,
                ProfileId = profileId
            }),
                                                                                 profileId,
                                                                                 guild.Id);

            return(newPlayers);
        }