Ejemplo n.º 1
0
        public void CheckPackageFutureAndPast(PackageFutureAndPast package, PackageFutureAndPast packageFutureAndPast)
        {
            int count = package.Future.Count;

            for (int i = 0; i < count; i++)
            {
                JsonCard cardFirst  = package.Future[i];
                JsonCard cardSecond = packageFutureAndPast.Future[i];
                Assert.AreEqual(cardFirst.Temperature, cardSecond.Temperature);
                Assert.AreEqual(cardFirst.Humidity, cardSecond.Humidity);
                Assert.AreEqual(cardFirst.Date, cardSecond.Date);
                Assert.AreEqual(cardFirst.WindDirection, cardSecond.WindDirection);
                Assert.AreEqual(cardFirst.Description, cardSecond.Description);
            }
            count = package.Past.Count;
            for (int i = 0; i < count; i++)
            {
                JsonCard cardFirst  = package.Past[i];
                JsonCard cardSecond = packageFutureAndPast.Past[i];
                Assert.AreEqual(cardFirst.Temperature, cardSecond.Temperature);
                Assert.AreEqual(cardFirst.Humidity, cardSecond.Humidity);
                Assert.AreEqual(cardFirst.Date, cardSecond.Date);
                Assert.AreEqual(cardFirst.WindDirection, cardSecond.WindDirection);
                Assert.AreEqual(cardFirst.Description, cardSecond.Description);
            }
        }
        public static PackageFutureAndPast CreateEachDayCards(List <JsonCard> forecastCards, List <JsonCard> historyCards)
        {
            PackageFutureAndPast package             = new PackageFutureAndPast();
            int             countDays                = 5;
            DateTime        present                  = DateTime.Now;
            List <JsonCard> listOfFutureAndPastCards = new List <JsonCard>();

            listOfFutureAndPastCards = forecastCards.Concat(historyCards).ToList();
            for (var counter = 0; counter < countDays; counter++)
            {
                JsonCard card = CreateDayCard(listOfFutureAndPastCards.Where(x =>
                                                                             x.Date == (present.AddDays(counter + 1).Day + "." + present.Month))
                                              .ToList());
                if (card != null)
                {
                    package.Future.Add(card);
                }
                card = CreateDayCard(listOfFutureAndPastCards.Where(x =>
                                                                    x.Date == (present.AddDays(-counter - 1).Day + "." + present.Month))
                                     .ToList());
                if (card != null)
                {
                    package.Past.Add(card);
                }
            }
            return(package);
        }
        public static JsonCard CreateDayCard(List <JsonCard> listCards)
        {
            if (listCards.Count != 0)
            {
                JsonCard day = new JsonCard();
                day.Date          = listCards[0].Date;
                day.Description   = listCards[0].Description;
                day.WindDirection = listCards[0].WindDirection;
                int maxCountWindDirection = 1;
                int maxCountDescription   = 1;
                int count = 0;
                foreach (var card in listCards)
                {
                    day.Humidity    += card.Humidity / listCards.Count;
                    day.Temperature += card.Temperature / listCards.Count;

                    count = listCards.Where(x => x.WindDirection == card.WindDirection).ToList().Count;
                    if (count > maxCountWindDirection)
                    {
                        day.WindDirection     = card.WindDirection;
                        maxCountWindDirection = count;
                    }
                    count = listCards.Where(x => x.Description == card.Description).ToList().Count;
                    if (count > maxCountDescription)
                    {
                        day.Description     = card.Description;
                        maxCountDescription = count;
                    }
                }
                return(day);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public void JsonCardTestMonsterFireSpell()
        {
            var card = new JsonCard();

            card.Id     = "6";
            card.Name   = "FireSpell";
            card.Damage = 12;
            card.ConvertToCard();

            Assert.AreEqual(card.category, Category.Spell);
            Assert.AreEqual(card.elementType, Element.Fire);
        }
Ejemplo n.º 5
0
        public void JsonCardTestMonsterWaterSpell()
        {
            var card = new JsonCard();

            card.Id     = "5";
            card.Name   = "WaterSpell";
            card.Damage = 35;
            card.ConvertToCard();

            Assert.AreEqual(card.category, Category.Spell);
            Assert.AreEqual(card.elementType, Element.Water);
        }
Ejemplo n.º 6
0
        public void JsonCardTestMonsterRegularSpell()
        {
            var card = new JsonCard();

            card.Id     = "4";
            card.Name   = "RegularSpell";
            card.Damage = 30;
            card.ConvertToCard();

            Assert.AreEqual(card.category, Category.Spell);
            Assert.AreEqual(card.elementType, Element.Normal);
        }
Ejemplo n.º 7
0
        public void JsonCardTestMonsterWaterWizzard()
        {
            var card = new JsonCard();

            card.Id     = "3";
            card.Name   = "WaterWizzard";
            card.Damage = 30;
            card.ConvertToCard();

            Assert.AreEqual(card.category, Category.Monster);
            Assert.AreEqual(card.elementType, Element.Water);
            Assert.AreEqual(card.race, Race.Wizzard);
        }
Ejemplo n.º 8
0
        public void JsonCardTestMonsterKraken()
        {
            var card = new JsonCard();

            card.Id     = "3";
            card.Name   = "Kraken";
            card.Damage = 25;
            card.ConvertToCard();

            Assert.AreEqual(card.category, Category.Monster);
            Assert.AreEqual(card.elementType, Element.Normal);
            Assert.AreEqual(card.race, Race.Kraken);
        }
Ejemplo n.º 9
0
        public void JsonCardTestMonsterFireDragon()
        {
            var card = new JsonCard();

            card.Id     = "1";
            card.Name   = "FireDragon";
            card.Damage = 20;
            card.ConvertToCard();

            Assert.AreEqual(card.category, Category.Monster);
            Assert.AreEqual(card.elementType, Element.Fire);
            Assert.AreEqual(card.race, Race.Dragon);
        }
Ejemplo n.º 10
0
        public Card(JsonCard jc)
        {
            Id   = jc.Id;
            Name = jc.Name;
            CardType pType;

            if (Enum.TryParse(jc.Type, true, out pType))
            {
                Type = pType;
            }
            CardSet pSet;

            if (Enum.TryParse(jc.Set, true, out pSet))
            {
                Set = pSet;
            }
            IsCollectible = jc.Collectible;
        }
Ejemplo n.º 11
0
        private void LinkSides(JsonCard jsonCard)
        {
            Guid?sideAUuid = jsonCard.OtherFaceIds?.FirstOrDefault();

            if (sideAUuid != null && sideAUuid != default(Guid) && jsonCard.Side != null && jsonCard.Side != "a")
            {
                var mainSide = db.Printings
                               .Where(p => p.UUID == sideAUuid)
                               .OrderBy(p => p.MultiverseId)
                               .FirstOrDefault()?.Card;

                var altCard = db.Cards.Local
                              .Where(c => c.Name == jsonCard.CockatriceName)
                              .Single();

                altCard.MainSide = mainSide;
            }
        }
Ejemplo n.º 12
0
        private UpsertResult <Printing> UpsertPrinting(JsonCard printing)
        {
            var card = this.UpsertCard(printing);

            if (card.ObjectsToRemove.Count > 0)
            {
                db.RemoveRange(card.ObjectsToRemove);
            }

            if (card.ObjectsToAdd.Count > 0)
            {
                db.AddRange(card.ObjectsToAdd);
            }

            var result = new UpsertResult <Printing>();

            if (!printing.Identifiers.MultiverseId.HasValue)
            {
                return(result);
            }

            var dbPrinting = db.Printings.Local
                             .Where(p => p.MultiverseId == printing.Identifiers.MultiverseId.Value && p.Side == printing.Side)
                             .FirstOrDefault();

            if (dbPrinting == null)
            {
                dbPrinting = new Printing()
                {
                    MultiverseId = printing.Identifiers.MultiverseId.Value,
                    Side         = printing.Side
                };

                result.ObjectsToAdd.Add(dbPrinting);
            }

            dbPrinting.UUID            = printing.UUID;
            dbPrinting.FlavorText      = printing.FlavorText;
            dbPrinting.CollectorNumber = printing.Number;

            dbPrinting.Artist    = UpsertSimpleLookup(db.Artists, printing.Artist);
            dbPrinting.Watermark = UpsertSimpleLookup(db.Watermarks, printing.Watermark);
            dbPrinting.Frame     = UpsertSimpleLookup(db.Frames, printing.FrameVersion);
            dbPrinting.Rarity    = UpsertSimpleLookup(db.Rarities, printing.Rarity);
            dbPrinting.Border    = UpsertSimpleLookup(db.Borders, printing.BorderColor);

            if (printing.Prices?.Paper != null)
            {
                var pricingUpsert = UpsertPricing(dbPrinting, printing.Prices.Paper, false);
                result.Merge(pricingUpsert);
            }

            if (printing.Prices?.PaperFoil != null)
            {
                var pricingUpsert = UpsertPricing(dbPrinting, printing.Prices.PaperFoil, true);
                result.Merge(pricingUpsert);
            }

            dbPrinting.Card = card.MainObject;

            result.MainObject = dbPrinting;

            return(result);
        }
Ejemplo n.º 13
0
        private UpsertResult <Card> UpsertCard(JsonCard printing)
        {
            var result = new UpsertResult <Card>();

            var dbCard = db.Cards.Local
                         .Where(c => c.Name == printing.CockatriceName)
                         .SingleOrDefault();

            if (dbCard == null)
            {
                dbCard = new Card()
                {
                    Name = printing.CockatriceName
                };

                result.ObjectsToAdd.Add(dbCard);
            }

            dbCard.CockatriceName = printing.Name;
            dbCard.ManaCost       = printing.ManaCost;
            dbCard.CMC            = printing.ConvertedManaCost;
            dbCard.TypeLine       = printing.Type;
            dbCard.OracleText     = printing.Text ?? string.Empty;
            dbCard.Power          = printing.Power;
            dbCard.Toughness      = printing.Toughness;
            dbCard.Loyalty        = printing.Loyalty;
            dbCard.EDHRECRank     = printing.EDHRECRank;

            printing.Types = printing.Types.ConvertAll(t => t.ToLower());

            if (dbCard.Colors.Select(t => t.Color.Symbol).Except(printing.Colors).Any() ||
                printing.Colors.Except(dbCard.Colors.Select(t => t.Color.Symbol)).Any())
            {
                result.ObjectsToRemove.AddRange(dbCard.Colors);

                var colors     = db.Colors.Where(c => printing.Colors.Contains(c.Symbol));
                var cardColors = new List <CardColor>();
                foreach (var color in colors)
                {
                    cardColors.Add(new CardColor()
                    {
                        Card  = dbCard,
                        Color = color
                    });
                }

                result.ObjectsToAdd.AddRange(cardColors);
            }

            if (printing.Types.Contains("land") && !printing.Supertypes.Contains("Basic"))
            {
                if (printing.Text.Contains("plains", StringComparison.CurrentCultureIgnoreCase) && !printing.ColorIdentity.Contains("W"))
                {
                    printing.ColorIdentity.Add("W");
                }

                if (printing.Text.Contains("island", StringComparison.CurrentCultureIgnoreCase) && !printing.ColorIdentity.Contains("U"))
                {
                    printing.ColorIdentity.Add("U");
                }

                if (printing.Text.Contains("swamp", StringComparison.CurrentCultureIgnoreCase) && !printing.ColorIdentity.Contains("B"))
                {
                    printing.ColorIdentity.Add("B");
                }

                if (printing.Text.Contains("mountain", StringComparison.CurrentCultureIgnoreCase) && !printing.ColorIdentity.Contains("R"))
                {
                    printing.ColorIdentity.Add("R");
                }

                if (printing.Text.Contains("forest", StringComparison.CurrentCultureIgnoreCase) && !printing.ColorIdentity.Contains("G"))
                {
                    printing.ColorIdentity.Add("G");
                }
            }

            if (dbCard.ColorIdentity.Select(t => t.Color.Symbol).Except(printing.ColorIdentity).Any() ||
                printing.ColorIdentity.Except(dbCard.ColorIdentity.Select(t => t.Color.Symbol)).Any())
            {
                result.ObjectsToRemove.AddRange(dbCard.ColorIdentity);

                var colors            = db.Colors.Where(c => printing.ColorIdentity.Contains(c.Symbol));
                var cardColorIdentity = new List <CardColorIdentity>();
                foreach (var color in colors)
                {
                    cardColorIdentity.Add(new CardColorIdentity()
                    {
                        Card  = dbCard,
                        Color = color
                    });
                }

                result.ObjectsToAdd.AddRange(cardColorIdentity);
            }

            if (dbCard.Supertypes.Select(t => t.Supertype.Name).Except(printing.Supertypes).Any() ||
                printing.Supertypes.Except(dbCard.Supertypes.Select(t => t.Supertype.Name)).Any())
            {
                result.ObjectsToRemove.AddRange(dbCard.Supertypes);

                var supertypes     = db.Supertypes.Where(t => printing.Supertypes.Contains(t.Name));
                var cardSupertypes = new List <CardSupertype>();
                foreach (var supertype in supertypes)
                {
                    cardSupertypes.Add(new CardSupertype()
                    {
                        Card      = dbCard,
                        Supertype = supertype
                    });
                }

                result.ObjectsToAdd.AddRange(cardSupertypes);
            }

            if (dbCard.Types.Select(t => t.CardType.Name).Except(printing.Types).Any() ||
                printing.Types.Except(dbCard.Types.Select(t => t.CardType.Name)).Any())
            {
                result.ObjectsToRemove.AddRange(dbCard.Types);

                var cardTypes     = db.CardTypes.Where(t => printing.Types.Contains(t.Name));
                var cardCardTypes = new List <CardCardType>();
                foreach (var cardType in cardTypes)
                {
                    cardCardTypes.Add(new CardCardType()
                    {
                        Card     = dbCard,
                        CardType = cardType
                    });
                }

                result.ObjectsToAdd.AddRange(cardCardTypes);
            }

            if (dbCard.Subtypes.Select(t => t.Subtype.Name).Except(printing.Subtypes).Any() ||
                printing.Subtypes.Except(dbCard.Subtypes.Select(t => t.Subtype.Name)).Any())
            {
                result.ObjectsToRemove.AddRange(dbCard.Subtypes);

                var subtypes     = db.Subtypes.Where(t => printing.Subtypes.Contains(t.Name));
                var cardSubtypes = new List <CardSubtype>();
                foreach (var subtype in subtypes)
                {
                    cardSubtypes.Add(new CardSubtype()
                    {
                        Card    = dbCard,
                        Subtype = subtype
                    });
                }

                result.ObjectsToAdd.AddRange(cardSubtypes);
            }

            var keywords = printing.Keywords.Select(k => k.ToLower());

            if (dbCard.Keywords.Select(k => k.Keyword.Name.ToLower()).Except(keywords).Any() ||
                keywords.Except(dbCard.Keywords.Select(k => k.Keyword.Name.ToLower())).Any())
            {
                result.ObjectsToRemove.AddRange(dbCard.Keywords);

                var dbKeywords   = db.Keywords.Where(k => printing.Keywords.Contains(k.Name));
                var cardKeywords = new List <CardKeyword>();
                foreach (var keyword in dbKeywords)
                {
                    cardKeywords.Add(new CardKeyword()
                    {
                        Card    = dbCard,
                        Keyword = keyword
                    });
                }

                result.ObjectsToAdd.AddRange(cardKeywords);
            }

            dbCard.Layout = UpsertSimpleLookup(db.Layouts, printing.Layout);

            var legalityUpsert = legalityHelper.UpsertLegalities(dbCard, printing.Legalities, printing.LeadershipSkills);

            dbCard.Legalities = legalityUpsert.MainObject;
            result.Merge(legalityUpsert);

            dbCard.Side = printing.Side;
            if (printing.Side == null || printing.Side == "a")
            {
                dbCard.MainSide = null;
            }

            result.MainObject = dbCard;

            return(result);
        }
Ejemplo n.º 14
0
 public PopularityCard(HearthDb.Card dbCard, JsonCard j)
 {
     this.dbCard   = dbCard;
     this.jsonCard = j;
 }