Пример #1
0
        /// <summary>
        /// Imports cards from S3 jsons
        /// - Imports for a single page
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        public void ImportCards(int page, int pageSize)
        {
            LambdaLogger.Log($"Entering: ImportCards({page}, {pageSize})");

            try
            {
                //Retrieving import entries
                var importCardList = new List <ImportCardDto>();

                var ioCards = JsonConvert.DeserializeObject <List <ImportCardDto> >(S3Helper.GetFile(new S3GetFileRequest
                {
                    FilePath = $"Imports/CardImports/{page}.json"
                }).Result.FileContent);

                importCardList.AddRange(ioCards);

                //Building dao entries
                var cardList = new List <Card>();

                LambdaLogger.Log($"Saving Card List: { JsonConvert.SerializeObject(importCardList) }");

                var tcgService = ServiceFactory.GetService <TCGService>();

                int i = 0;
                foreach (var ioCard in importCardList.Where(x => x.Border == null))
                {
                    if (ioCard != null)
                    {
                        var newCard       = ioCard.Map(ioCard);
                        var floatIdString = $"{page}.{i}";

                        newCard.FloatId = float.Parse(floatIdString);

                        //tcgService.AddTCGDetails(newCard);

                        newCard.Tags = String.Join(" // ", TranslateCardText(newCard.CardText));

                        cardList.Add(newCard);
                    }

                    i++;
                }

                LambdaLogger.Log($"About to add TCG Price: { JsonConvert.SerializeObject(cardList.Where(x => x.TCGProductId != 0)) }");

                //tcgService.AddTCGPrice(cardList);

                SvcContext.Repository
                .Cards
                .Save(cardList);
            }
            catch (Exception exp)
            {
                LambdaLogger.Log($"Error: { exp }");
                throw;
            }

            LambdaLogger.Log($"Leaving: ImportCards({page}, {pageSize})");
        }
Пример #2
0
        public byte[] GetThumbnailImage(Guid _fileGuid, string _extension)
        {
            string bucketName = Config.GetSettingValue("S3Bucket_Images");
            string folderName = Config.GetSettingValue("S3MediaRootFolder");

            string filename = ImageProcessingHelper.GetPath(_fileGuid, folderName, _extension, true);

            var s3 = S3Helper.GetS3();

            return(S3Helper.GetFile(s3, bucketName, filename));
        }
Пример #3
0
        /// <summary>
        /// Imports cards from S3 jsons
        /// - Imports for a single page
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        public void ImportCards(int page, int pageSize)
        {
            LambdaLogger.Log($"Entering: ImportCards({page}, {pageSize})");

            try
            {
                //Retrieving import entries
                var importCardList = new List <ImportCardDto>();

                var ioCards = JsonConvert.DeserializeObject <List <ImportCardDto> >(S3Helper.GetFile(new S3GetFileRequest
                {
                    FilePath = $"Imports/CardImports/{page}.json"
                }).Result.FileContent);

                importCardList.AddRange(ioCards);

                //Building dao entries
                var cardList = new List <Card>();

                LambdaLogger.Log($"Saving Card List: { JsonConvert.SerializeObject(importCardList) }");

                int i = 0;
                foreach (var ioCard in importCardList)
                {
                    if (ioCard != null)
                    {
                        var newCard       = ioCard.Map(ioCard);
                        var floatIdString = $"{page}.{i}";

                        newCard.FloatId = float.Parse(floatIdString);

                        SvcContext.Repository
                        .Cards
                        .Save(new List <Card>()
                        {
                            newCard
                        });
                    }

                    i++;
                }
            }
            catch (Exception exp)
            {
                LambdaLogger.Log($"Error: { exp }");
                throw;
            }

            LambdaLogger.Log($"Leaving: ImportCards({page}, {pageSize})");
        }
Пример #4
0
        public ImportService()
        {
            Dictionary = new KeywordDictionary();

            var s3Response = S3Helper.GetFile(new S3GetFileRequest()
            {
                FilePath = MTGServiceConstants.KeywordDictionaryFilepath
            }).Result;

            if (s3Response.IsSuccess)
            {
                Dictionary = JsonConvert.DeserializeObject <KeywordDictionary>(s3Response.FileContent);
            }
        }
Пример #5
0
        public async Task <string> GetToken()
        {
            LambdaLogger.Log($"Entering: GetToken()");

            string response = string.Empty;

            try
            {
                S3GetFileResponse S3Response = await S3Helper.GetFile(new S3GetFileRequest
                {
                    FilePath = MTGServiceConstants.AuthenticateJsonFilepath
                });

                if (S3Response.IsSuccess)
                {
                    if (string.IsNullOrEmpty(S3Response.FileContent))
                    {
                        throw new Exception("S3 Response content is null or empty! ya bish!");
                    }

                    AuthenticateDto authenticateDto = JsonConvert.DeserializeObject <AuthenticateDto>(S3Response.FileContent);

                    if (authenticateDto == null)
                    {
                        throw new Exception("S3 Authenticate response content could not be deserialized!");
                    }

                    response = authenticateDto.AccessToken;
                }
            }
            catch (Exception exp)
            {
                LambdaLogger.Log($"Error: {exp}");
                throw;
            }

            LambdaLogger.Log($"Leaving: GetToken({response})");

            return(response);
        }
Пример #6
0
        public async Task ScryImportCards(ScryCardImportRequest input)
        {
            LambdaLogger.Log($"Entering: ScryImportCards({ JsonConvert.SerializeObject(input) })");

            try
            {
                bool importAll     = input.import_all;
                bool importPrices  = input.import_prices;
                bool containsNames = input.names.Count > 0;
                int  cardStart     = 0;
                int  cardEnd       = 20723;

                if (input.card_end != 0)
                {
                    cardStart = input.card_start;
                    cardEnd   = input.card_end;
                }

                var TCGService = ServiceFactory.GetService <TCGService>();

                var scryCards = JsonConvert.DeserializeObject <List <ScryCardDto> >(S3Helper.GetFile(new S3GetFileRequest
                {
                    FilePath = $"Imports/ScryImports/scryfall-oracle-cards.json"
                }).Result.FileContent);

                var cardList = new List <Card>();

                if (importAll)
                {
                    int i = 0;
                    scryCards = scryCards.Where(x => x.legalities != null && x.legalities["commander"] == "legal").ToList();

                    foreach (var scryCard in scryCards)
                    {
                        if (scryCard != null)
                        {
                            var newCard = scryCard.Map(scryCard);

                            if (!string.IsNullOrWhiteSpace(newCard.CardText))
                            {
                                newCard.Tags = String.Join(" // ", TranslateCardText(newCard.CardText));
                            }

                            if (!string.IsNullOrWhiteSpace(newCard.BackCardText))
                            {
                                var keywords = newCard.Tags
                                               .Split(" // ")
                                               .ToList();

                                keywords.AddRange(TranslateCardText(newCard.BackCardText));

                                newCard.Tags = String.Join(" // ", keywords);
                            }

                            LambdaLogger.Log($"Adding new card: { JsonConvert.SerializeObject(newCard) }");

                            cardList.Add(newCard);

                            if (cardList.Count == 25 || scryCard == scryCards.Last())
                            {
                                if (importPrices)
                                {
                                    await TCGService.AddTCGPrice(cardList);
                                }

                                LambdaLogger.Log($"Card List to save: { JsonConvert.SerializeObject(cardList) }");

                                await SvcContext.Repository
                                .Cards
                                .SaveAsync(cardList);

                                cardList.Clear();
                            }
                        }

                        i++;
                    }
                }
                else if (containsNames)
                {
                    scryCards = scryCards.Where(x => x.legalities != null && x.legalities["commander"] == "legal").ToList();

                    var names = input.names;

                    foreach (var name in names)
                    {
                        var scryCard = scryCards.Where(x => x.Name == name)
                                       .FirstOrDefault();

                        var newCard = scryCard.Map(scryCard);

                        cardList.Add(newCard);
                    }

                    if (importPrices)
                    {
                        await TCGService.AddTCGPrice(cardList);
                    }

                    LambdaLogger.Log($"Card List to save: { JsonConvert.SerializeObject(cardList) }");

                    await SvcContext.Repository
                    .Cards
                    .SaveAsync(cardList);
                }
                else
                {
                    scryCards = scryCards.Where(x => x.legalities != null && x.legalities["commander"] == "legal").ToList();

                    for (int i = cardStart; i <= cardEnd; i++)
                    {
                        var scryCard = scryCards[i];
                        var newCard  = scryCard.Map(scryCard);

                        if (!string.IsNullOrWhiteSpace(newCard.CardText))
                        {
                            newCard.Tags = String.Join(" // ", TranslateCardText(newCard.CardText));
                        }

                        if (!string.IsNullOrWhiteSpace(newCard.BackCardText))
                        {
                            var keywords = newCard.Tags
                                           .ToList();

                            keywords.AddRange(String.Join(" // ", TranslateCardText(newCard.BackCardText)));

                            newCard.Tags = String.Join(" // ", keywords);
                        }

                        LambdaLogger.Log($"Adding new card: { JsonConvert.SerializeObject(newCard) }");

                        cardList.Add(newCard);

                        if (cardList.Count == 25 || i == cardEnd)
                        {
                            if (importPrices)
                            {
                                await TCGService.AddTCGPrice(cardList);
                            }

                            LambdaLogger.Log($"Card List to save: { JsonConvert.SerializeObject(cardList) }");

                            await SvcContext.Repository
                            .Cards
                            .SaveAsync(cardList);

                            cardList.Clear();
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                LambdaLogger.Log($"Error: { exp }");
            }

            LambdaLogger.Log($"Leaving: ScryImportCards({ JsonConvert.SerializeObject(input) })");
        }