Пример #1
0
 public async Task <StoredGuild> InsertGuildAsync(StoredGuild guild, int profileId)
 {
     return(await this.cache.InsertIfMissingAsync(
                guild,
                this.GetFromDatabase(guild.Name, profileId, guild.Realm),
                this.Store(),
                this.GetKey(guild.Name, profileId, guild.RealmId)));
 }
Пример #2
0
        public async Task PlayerStoreTest()
        {
            const string         connectionString = "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=GuildTools;Integrated Security=True";
            KeyedResourceManager manager          = new KeyedResourceManager();

            BlizzardApiSecrets blizzardSecrets = new BlizzardApiSecrets()
            {
                ClientId     = this.config.GetValue <string>("BlizzardApiSecrets:ClientId"),
                ClientSecret = this.config.GetValue <string>("BlizzardApiSecrets:ClientSecret")
            };

            IMemoryCache      memoryCache = new MemoryCache(new MemoryCacheOptions());
            GuildToolsContext context     = new GuildToolsContext(SqlServerDbContextOptionsExtensions.UseSqlServer(new DbContextOptionsBuilder(), connectionString).Options as DbContextOptions);

            HttpClient              client          = new HttpClient();
            IDataRepository         repo            = new DataRepository(context);
            IBlizzardService        blizzardService = new BlizzardService(repo, this.config, client);
            PerRequestCallThrottler throttler       = new PerRequestCallThrottler(TimeSpan.FromSeconds(1));
            IGuildService           guildService    = new GuildService(blizzardService, throttler);

            int profileId = 1;

            GameRegion region = new GameRegion()
            {
                Id         = 1,
                RegionName = "US"
            };

            StoredRealm realm = context.StoredRealms.Include(a => a.Region).First();
            StoredGuild guild = context.StoredGuilds.First();

            PlayerStoreByValue playerStore = new PlayerStoreByValue(guildService, memoryCache, context, manager);

            DateTime initial = DateTime.Now;

            var realms = await playerStore.GetPlayerAsync("Kromp", realm, guild, profileId);

            DateTime second       = DateTime.Now;
            TimeSpan sinceInitial = second - initial;

            var realms2 = await playerStore.GetPlayerAsync("Kromp", realm, guild, profileId);

            DateTime third       = DateTime.Now;
            TimeSpan sinceSecond = third - second;

            var realms3 = await playerStore.GetPlayerAsync("Kromp", realm, guild, profileId);

            DateTime fourth     = DateTime.Now;
            TimeSpan sinceThird = fourth - third;

            int x = 42;
        }
Пример #3
0
        private Func <Task <CacheResult <StoredPlayer> > > GetFromSource(string name, StoredRealm realm, StoredGuild guild, int profileId)
        {
            return(async() =>
            {
                var result = await this.guildService.GetSinglePlayerAsync(
                    BlizzardUtilities.GetBlizzardRegionFromEfRegion((GameRegionEnum)realm.Region.Id),
                    realm.Slug,
                    name);

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

                return new CacheResult <StoredPlayer>()
                {
                    Found = true,
                    Result = new StoredPlayer()
                    {
                        Name = result.PlayerName,
                        RealmId = realm.Id,
                        ProfileId = profileId,
                        GuildId = guild.Id,
                        Level = result.Level,
                        Class = result.Class
                    }
                };
            });
        }
Пример #4
0
 public async Task <StoredPlayer> GetPlayerAsync(string playerName, StoredRealm realm, StoredGuild guild, int profileId)
 {
     return(await this.cache.GetOrCacheAsync(
                this.GetFromDatabase(playerName, realm.Id, profileId),
                this.GetFromSource(playerName, realm, guild, profileId),
                this.Store(),
                this.GetKey(playerName, realm.Name, profileId)));
 }