public string BuscarCarta(string NomeCarta) { CardService service = new CardService(); //var xpto = service.Where(x => x.Name, "Fog").All(); service = service.Where(x => x.Name, NomeCarta); var result = service.All(); if (result.IsSuccess && result.Value.Count > 0) { return("Sua Carta é " + result.Value[0].Name + " ela é uma carta do tipo " + result.Value[0].SubTypes + " Seu custo de mana é " + result.Value[0].ManaCost + " seus efeitos são " + result.Value[0].Text); } else { return("Carta não identificada"); } //var dto = new CardDto() // { // Name = NomeCarta // }; // Card Model = new Card(dto); }
public static void Main(string[] args) { Task t1 = Task.Factory.StartNew(() => { Console.WriteLine("test"); CardService cardService = new CardService(); cardService.Where(c => c.Name, "Karn"); var result = cardService.All(); MtgApiManager.Lib.Model.Card[] array = result.Value.ToArray(); for (int i = 0; i < array.Length; i++) { Console.WriteLine(array[i].Name + "\n" + array[i].Text); Console.WriteLine(array[i].ImageUrl); } Console.ReadKey(); }); t1.Wait(); }
public void AllTest() { var cards = new List <CardDto>() { new CardDto() { Artist = "artist1", Border = "border1", Cmc = 111, Colors = new string[] { "blue", "pink" }, Flavor = "flavor1", ForeignNames = new ForeignNameDto[] { new ForeignNameDto() { Language = "english", MultiverseId = 222, Name = "name2" } }, Hand = 222, Id = "12345", ImageUrl = new System.Uri("http://fake/url"), Layout = "layout1", Legalities = new LegalityDto[] { new LegalityDto() { Format = "format2", LegalityName = "legality name 2" } }, Life = 333, Loyalty = "loyalty", ManaCost = "500", MultiverseId = 444, Name = "name1", Names = new string[] { "name2", "name3" }, Number = "600", OriginalText = "original text", OriginalType = "original type", Power = "9000", Printings = new string[] { "printing1", "printing2" }, Rarity = "rare", ReleaseDate = "2010, 1, 1", Reserved = true, Rulings = new RulingDto[] { new RulingDto() { Date = "2010, 2, 2", Text = "text2" } }, Set = "set1", SetName = "set name 1", Source = "source", Starter = true, SubTypes = new string[] { "subtype1", "subtype2" }, SuperTypes = new string[] { "supertype1", "supertype2" }, Text = "text3", Timeshifted = false, Toughness = "tough", Type = "type2", Types = new string[] { "type1", "type2" }, Variations = new int[] { 1, 2, 3 }, Watermark = "watermark" }, new CardDto() { Artist = "artist1", Border = "border1", Cmc = 111, Colors = new string[] { "blue", "pink" }, Flavor = "flavor1", ForeignNames = new ForeignNameDto[] { new ForeignNameDto() { Language = "english", MultiverseId = 222, Name = "name2" } }, Hand = 222, Id = "12345", ImageUrl = new System.Uri("http://fake/url"), Layout = "layout1", Legalities = new LegalityDto[] { new LegalityDto() { Format = "format2", LegalityName = "legality name 2" } }, Life = 333, Loyalty = "loyalty", ManaCost = "500", MultiverseId = 444, Name = "name1", Names = new string[] { "name2", "name3" }, Number = "600", OriginalText = "original text", OriginalType = "original type", Power = "9000", Printings = new string[] { "printing1", "printing2" }, Rarity = "rare", ReleaseDate = "2010, 1, 1", Reserved = true, Rulings = new RulingDto[] { new RulingDto() { Date = "2010, 2, 2", Text = "text2" } }, Set = "set1", SetName = "set name 1", Source = "source", Starter = true, SubTypes = new string[] { "subtype1", "subtype2" }, SuperTypes = new string[] { "supertype1", "supertype2" }, Text = "text3", Timeshifted = false, Toughness = "tough", Type = "type2", Types = new string[] { "type1", "type2" }, Variations = new int[] { 1, 2, 3 }, Watermark = "watermark" } }; // Test the All method. var moqAdapter = new Mock <IMtgApiServiceAdapter>(); moqAdapter .SetupSequence(x => x.WebGetAsync <RootCardListDto>(It.IsAny <Uri>())) .Throws <ArgumentNullException>() .Throws(new MtgApiException <BadRequestException>("bad request")) .Throws(new MtgApiException <ForbiddenException>("forbidden")) .Throws(new MtgApiException <InternalServerErrorException>("server error")) .Throws(new MtgApiException <NotFoundException>("not found")) .Throws(new MtgApiException <ServiceUnavailableException>("unavailable")) .Throws <Exception>() .ReturnsAsync(new RootCardListDto() { Cards = cards }); var service = new CardService(moqAdapter.Object, ApiVersion.V1_0, false); service = service.Where(x => x.Name, "name1"); var result = service.All(); Assert.False(result.IsSuccess); Assert.Equal("Value cannot be null.", result.Exception.Message); result = service.All(); Assert.False(result.IsSuccess); Assert.Equal("bad request", result.Exception.Message); result = service.All(); Assert.False(result.IsSuccess); Assert.Equal("forbidden", result.Exception.Message); result = service.All(); Assert.False(result.IsSuccess); Assert.Equal("server error", result.Exception.Message); result = service.All(); Assert.False(result.IsSuccess); Assert.Equal("not found", result.Exception.Message); result = service.All(); Assert.False(result.IsSuccess); Assert.Equal("unavailable", result.Exception.Message); result = service.All(); Assert.False(result.IsSuccess); Assert.IsType <Exception>(result.Exception); result = service.All(); Assert.True(result.IsSuccess); Assert.Null(result.Exception); Assert.NotNull(result.Value); }
private static void AnalyzeCardRelationships() { var sb = new StringBuilder(); string outputFile = "LoadCardRelationships.cs"; foreach (var card in service.All().Where(x => x.CardType == CardType.Hero || x.CardType == CardType.Ally || x.CardType == CardType.Attachment || x.CardType == CardType.Event)) { var decks = card.Decks.Count; if (decks < 5) { continue; } Console.WriteLine("{0} ({1}) is found in {2} decks", card.Title, card.CardSet.Abbreviation, decks); var relationshipMap = new Dictionary <string, uint>(); var threshold = (int)Math.Truncate(decks * .67); foreach (var deck in card.Decks) { foreach (var otherCard in service.All().Where(x => x.Id != card.Id && x.Decks.Contains(deck))) { if (!relationshipMap.ContainsKey(otherCard.Id)) { relationshipMap.Add(otherCard.Id, 1); } else { relationshipMap[otherCard.Id] += 1; } } } foreach (var pair in relationshipMap.Where(x => x.Value >= threshold)) { var otherCard = service.Find(pair.Key); if (otherCard == null) { continue; } var leftTitle = !string.IsNullOrEmpty(card.NormalizedTitle) ? card.NormalizedTitle : card.Title; var rightTitle = !string.IsNullOrEmpty(otherCard.NormalizedTitle) ? otherCard.NormalizedTitle : otherCard.Title; sb.AppendLine(string.Format("AddRelationship(\"{0}\", \"{1}\", \"{2}\", \"{3}\");", leftTitle, card.CardSet.Abbreviation, rightTitle, otherCard.CardSet.Abbreviation)); //Console.WriteLine(" {0} is related to {1}", card.Title, service.Find(pair.Key).Title); } } System.IO.File.WriteAllText(outputFile, sb.ToString()); }
public ActionResult Get(string name) { var result = new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet }; switch (name) { case "Cards": result.Data = _cardService.All().Select(x => new SimpleCard(x)).ToList(); break; case "PlayerCards": result.Data = _cardService.All().Where(x => IsPlayerCard(x)).Select(y => new SimpleCard(y)).ToList(); break; case "Scenarios": var scenarios = new List <SimpleScenario>(); foreach (var group in _cardService.ScenarioGroups()) { foreach (var item in group.Scenarios) { var scenario = new SimpleScenario() { Title = item.Title, Number = (uint)item.Number }; foreach (var quest in item.QuestCards.Select(x => x.Quest)) { scenario.QuestCards.Add(new SimpleCard(quest)); } foreach (var card in item.ScenarioCards) { scenario.ScenarioCards.Add(new SimpleScenarioCard() { EncounterSet = card.EncounterSet, Title = card.Title, NormalQuantity = (uint)card.NormalQuantity, EasyQuantity = (uint)card.EasyQuantity, NightmareQuantity = (uint)card.NightmareQuantity }); } scenarios.Add(scenario); } } result.Data = scenarios; break; case "CardSets": result.Data = _cardService.CardSets().Select(x => new SimpleCardSet { Name = x.Name, Cycle = x.Cycle, SetType = x.SetType.ToString() }).ToList(); break; case "EncounterSets": result.Data = _cardService.EncounterSetNames; break; default: if (!string.IsNullOrEmpty(name)) { result.Data = "Unknown record type: " + name; } else { result.Data = "Undefined record type"; } break; } return(result); //return "This is a test of the API: " + name; }