示例#1
0
        public async Task <NexusApiClient.GetModFilesResponse> GetModFiles(string GameName, long ModId)
        {
            _logger.Log(LogLevel.Information, $"{GameName} {ModId}");
            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await _sql.GetModFiles(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await NexusApiClient.Get(Request.Headers["apikey"].FirstOrDefault());

                result = await api.GetModFiles(game, ModId, false);

                await _sql.AddNexusModFiles(game, ModId, DateTime.UtcNow, result);

                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }
            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
示例#2
0
        public async Task UpdateNexusCacheRSS()
        {
            using var _ = _logger.BeginScope("Nexus Update via RSS");
            _logger.Log(LogLevel.Information, "Starting");

            var results = await NexusUpdatesFeeds.GetUpdates();

            NexusApiClient client  = null;
            long           updated = 0;

            foreach (var result in results)
            {
                try
                {
                    var purgedMods =
                        await _sql.DeleteNexusModFilesUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                    var purgedFiles =
                        await _sql.DeleteNexusModInfosUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                    var totalPurged = purgedFiles + purgedMods;
                    if (totalPurged > 0)
                    {
                        _logger.Log(LogLevel.Information, $"Purged {totalPurged} cache items {result.Game} {result.ModId} {result.TimeStamp}");
                    }

                    if (await _sql.GetNexusModInfoString(result.Game, result.ModId) != null)
                    {
                        continue;
                    }

                    // Lazily create the client
                    client ??= await NexusApiClient.Get();

                    // Cache the info
                    var files = await client.GetModFiles(result.Game, result.ModId, false);

                    await _sql.AddNexusModFiles(result.Game, result.ModId, result.TimeStamp, files);

                    var modInfo = await client.GetModInfo(result.Game, result.ModId, useCache : false);

                    await _sql.AddNexusModInfo(result.Game, result.ModId, result.TimeStamp, modInfo);

                    updated++;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Failed Nexus update for {result.Game} - {result.ModId} - {result.TimeStamp}");
                }
            }

            if (updated > 0)
            {
                _logger.Log(LogLevel.Information, $"Primed {updated} nexus cache entries");
            }

            _globalInformation.LastNexusSyncUTC = DateTime.UtcNow;
        }
示例#3
0
        public async Task <NexusApiClient.GetModFilesResponse> GetModFiles(string GameName, long ModId)
        {
            //_logger.Log(LogLevel.Information, $"{GameName} {ModId}");
            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await _sql.GetModFiles(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await GetClient();

                var permission = HTMLInterface.GetUploadPermissions(game, ModId);
                try
                {
                    result = await api.GetModFiles(game, ModId, false);
                }
                catch (HttpException ex)
                {
                    if (ex.Code == 403)
                    {
                        result = new NexusApiClient.GetModFilesResponse {
                            files = new List <NexusFileInfo>()
                        }
                    }
                    ;
                    else
                    {
                        throw;
                    }
                }

                var date = result.files.Select(f => f.uploaded_time).OrderByDescending(o => o).FirstOrDefault();
                date = date == default ? DateTime.UtcNow : date;
                await _sql.AddNexusModFiles(game, ModId, date, result);

                await _sql.SetNexusPermission(game, ModId, await permission);

                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }
            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
示例#4
0
        public static async Task <long> UpdateNexusCacheFast(SqlService sql)
        {
            var results = await NexusUpdatesFeeds.GetUpdates();

            NexusApiClient client  = null;
            long           updated = 0;

            foreach (var result in results)
            {
                var purgedMods = await sql.DeleteNexusModFilesUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                var purgedFiles = await sql.DeleteNexusModInfosUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                var totalPurged = purgedFiles + purgedMods;
                if (totalPurged > 0)
                {
                    Utils.Log($"Purged {totalPurged} cache items");
                }

                if (await sql.GetNexusModInfoString(result.Game, result.ModId) != null)
                {
                    continue;
                }

                // Lazily create the client
                client ??= await NexusApiClient.Get();

                // Cache the info
                var files = await client.GetModFiles(result.Game, result.ModId, false);

                await sql.AddNexusModFiles(result.Game, result.ModId, result.TimeStamp, files);

                var modInfo = await client.GetModInfo(result.Game, result.ModId);

                await sql.AddNexusModInfo(result.Game, result.ModId, result.TimeStamp, modInfo);

                updated++;
            }

            if (updated > 0)
            {
                Utils.Log($"Primed {updated} nexus cache entries");
            }

            LastNexusSync = DateTime.Now;
            return(updated);
        }