Example #1
0
        public async Task TestRealmsGetter()
        {
            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")
            };

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

            IDataRepository  repo            = new DataRepository(context);
            IBlizzardService blizzardService = new BlizzardService(repo, this.config, client);

            RealmsCache cache = new RealmsCache(blizzardService, memoryCache, dbCache, manager);

            DateTime initial = DateTime.Now;

            var realms = await cache.GetRealms(EF.Models.Enums.GameRegionEnum.US);

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

            var realms2 = await cache.GetRealms(EF.Models.Enums.GameRegionEnum.US);

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

            int x = 42;
        }
Example #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;
        }
Example #3
0
        public async Task CachedStoredValueTest()
        {
            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);

            RealmStoreByValues store = new RealmStoreByValues(guildService, memoryCache, context, manager);

            DateTime initial = DateTime.Now;

            var realms = await store.GetRealmAsync("Burning Blade", EF.Models.Enums.GameRegionEnum.US);

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

            var realms2 = await store.GetRealmAsync("Burning Blade", EF.Models.Enums.GameRegionEnum.US);

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

            var realms3 = await store.GetRealmAsync("Akama", EF.Models.Enums.GameRegionEnum.US);

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

            int x = 42;
        }
Example #4
0
        public BlizzardService(IDataRepository dataRepository, IConfiguration configuration, HttpClient client)
        {
            this.client   = client;
            this.dataRepo = dataRepository;

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

            this.regionAccessTokens = new Dictionary <BlizzardRegion, string>();

            var usKeyTask = this.dataRepo.GetStoredValueAsync(this.AccessTokenCacheKeys[BlizzardRegion.US]);
            var euKeyTask = this.dataRepo.GetStoredValueAsync(this.AccessTokenCacheKeys[BlizzardRegion.EU]);

            Task.WaitAll(usKeyTask, euKeyTask);

            this.regionAccessTokens[BlizzardRegion.US] = usKeyTask.Result ?? string.Empty;
            this.regionAccessTokens[BlizzardRegion.EU] = euKeyTask.Result ?? string.Empty;
        }