Exemplo n.º 1
0
        public async Task <EververseInfocard> GetEververseInfocardAsync(int?week = null)
        {
            using var scope = _scopeFactory.CreateScope();

            var infocardsDB = scope.ServiceProvider.GetRequiredService <IInfocardsDB>();

            int weekNumber = week ?? GetWeekNumber();

            (var resetBegin, var resetEnd) = GetWeeklyResetInterval(weekNumber);

            var eververseItems = await infocardsDB.GetEververseInventoryAsync(resetBegin, resetEnd);

            var imageLink = eververseItems?.InfocardImageURL;

            if (imageLink is null)
            {
                var dataParser = new DataParser(_scopeFactory);

                eververseItems = await dataParser.ParseEververseAsync(weekNumber);

                using var image = await ImageGenerator.GetEververseImageAsync(eververseItems);

                imageLink = await UploadImageAsync(image);

                if (eververseItems.EververseItems.Any())
                {
                    await infocardsDB.AddEververseInventoryAsync(eververseItems with
                    {
                        WeeklyResetBegin = resetBegin,
                        WeeklyResetEnd   = resetEnd,
                        SeasonNumber     = _seasonNumber,
                        InfocardImageURL = imageLink
                    });
                }
            }

            return(new EververseInfocard
            {
                WeekNumber = weekNumber,
                ResetBegin = resetBegin.ToLocalTime(),
                ResetEnd = resetEnd.ToLocalTime(),
                InfocardImageURL = imageLink
            });
        }
Exemplo n.º 2
0
        public async Task <ResourcesInfocard> GetResourcesInfocardAsync()
        {
            using var scope = _scopeFactory.CreateScope();

            var infocardsDB = scope.ServiceProvider.GetRequiredService <IInfocardsDB>();

            (var resetBegin, var resetEnd) = GetDailyResetInterval();

            var resources = await infocardsDB.GetVendorsInventoryAsync(resetBegin, resetEnd);

            var imageLink = resources?.InfocardImageURL;

            if (imageLink is null)
            {
                var dataParser = new DataParser(_scopeFactory);

                resources = await dataParser.ParseResourcesAsync();

                using var image = await ImageGenerator.GetResourcesImageAsync(resources);

                imageLink = await UploadImageAsync(image);

                if (resources.ResourceItems.Any())
                {
                    await infocardsDB.AddVendorsInventoryAsync(resources with
                    {
                        DailyResetBegin  = resetBegin,
                        DailyResetEnd    = resetEnd,
                        SeasonNumber     = _seasonNumber,
                        InfocardImageURL = imageLink
                    });
                }
            }

            return(new ResourcesInfocard
            {
                ResetBegin = resetBegin.ToLocalTime(),
                ResetEnd = resetEnd.ToLocalTime(),
                InfocardImageURL = imageLink
            });
        }
        public async Task <XurInfocard> GetXurInfocardAsync()
        {
            using var scope = _scopeFactory.CreateScope();

            var infocardsDB = scope.ServiceProvider.GetRequiredService <IInfocardsDB>();

            var weekNumber = GetWeekNumber();

            (var resetBegin, var resetEnd) = GetWeeklyResetInterval(weekNumber);

            //var xurItems = await infocardsDB.GetXurInventoryAsync(resetBegin, resetEnd);

            var dataParser = new DataParser(_scopeFactory);

            var xurItems = await dataParser.ParseXurInventoryAsync();

            using var image = await ImageGenerator.GetXurImageAsync(xurItems);

            var imageLink = await UploadImageAsync(image);

            var xurLocation = await dataParser.ParseXurLocationAsync();

            if (!xurItems.XurItems.Any())
            {
                //await infocardsDB.AddXurInventoryAsync(xurItems with
                //{
                //    WeeklyResetBegin = resetBegin,
                //    WeeklyResetEnd = resetEnd,
                //    SeasonNumber = _seasonNumber,
                //    XurLocation = xurLocation,
                //    InfocardImageURL = imageLink
                //});
            }

            return(new XurInfocard
            {
                WeekNumber = weekNumber,
                XurLocation = xurLocation,
                InfocardImageURL = imageLink
            });
        }