private void AddManaCostConditions(GetCardRequest request, List <ScanCondition> conditions) { LambdaLogger.Log($"Entering: AddManaCostConditions({ JsonConvert.SerializeObject(request) })"); var queryList = new List <Single>(); foreach (var manaCost in request.ManaCostFilter) { if (manaCost.Value) { queryList.Add(Single.Parse(manaCost.Key.ToString())); } } if (queryList.Contains(Single.Parse("7"))) { queryList.AddRange(new List <Single> { Single.Parse("8"), Single.Parse("9"), Single.Parse("10"), Single.Parse("11"), Single.Parse("12"), Single.Parse("13"), Single.Parse("14"), Single.Parse("15") }); } LambdaLogger.Log($"Query List: { JsonConvert.SerializeObject(queryList) }"); if (queryList.Any()) { var objects = queryList.Select(x => (object)x).ToArray(); var condition = new ScanCondition("ManaCost", ScanOperator.In, objects); conditions.Add(condition); } }
private void AddSearchConditions(GetCardRequest request, List <ScanCondition> conditions) { if (!string.IsNullOrWhiteSpace(request.TextFilter)) { conditions.Add(new ScanCondition("CardText", ScanOperator.Contains, request.TextFilter)); } else if (!string.IsNullOrWhiteSpace(request.NameFilter)) { //Capitalize first letter & lowercase all other letters for each search term var searchTerms = request.NameFilter .Split(new char[] { ' ' }) .Select(x => !x.Contains('-') ? (char.ToUpper(x[0]) + x.Substring(1).ToLower()) : x) .Select(x => FormatPreposition(x)) .ToList(); searchTerms[0] = !searchTerms[0].Contains('-') ? char.ToUpper(searchTerms[0][0]) + searchTerms[0].Substring(1).ToLower() : searchTerms[0]; conditions.Add(new ScanCondition("Name", ScanOperator.Contains, String.Join(' ', searchTerms.ToArray()))); //addedTerms.Add(char.ToUpper(searchTerm[0]) + searchTerm.Substring(1)); //string formattedTerm = char.ToUpper(searchTerm[0]) + searchTerm.Substring(1); //conditions.Add(new ScanCondition("Name", ScanOperator.Contains, searchTerm)); //conditions.Add(new ScanCondition("Name", ScanOperator.Contains, formattedTerm)); } else if (!string.IsNullOrWhiteSpace(request.KeywordsFilter)) { conditions.Add(new ScanCondition("Tags", ScanOperator.Contains, request.KeywordsFilter)); } }
public IEnumerable <Card> FindFromNameAndColors(GetCardRequest request) { LambdaLogger.Log($"Entering: FindFromNameAndColors({ JsonConvert.SerializeObject(request) }"); var conditions = new List <ScanCondition>(); AddSearchConditions(request, conditions); AddColorConditions(request, conditions); var results = FindAll(conditions); //if (request.ColorFilter.ContainsValue(false)) //{ // var negateColors = request.ColorFilter // .Where(x => x.Value == false) // .Select(x => x.Key) // .ToList(); // foreach (var negateColor in negateColors) // results = results.Where(x => !x.ColorIdentity.Contains(negateColor)).ToList(); //} return(results); }
public IEnumerable <Card> FindFromTextAndColors(GetCardRequest request) { var conditions = new List <ScanCondition>(); AddSearchConditions(request, conditions); AddColorConditions(request, conditions); return(FindAll(conditions)); }
//No content (Colors) public IEnumerable <Card> FindFromColors(GetCardRequest request) { LambdaLogger.Log($"Entering: FindFromColors({ JsonConvert.SerializeObject(request) })"); var conditions = new List <ScanCondition>(); AddColorConditions(request, conditions); return(FindAll(conditions)); }
public IEnumerable <Card> FindFromNameAndManaCost(GetCardRequest request) { LambdaLogger.Log($"Entering: FindFromNameAndManaCost({ JsonConvert.SerializeObject(request) }"); var conditions = new List <ScanCondition>(); AddSearchConditions(request, conditions); AddManaCostConditions(request, conditions); return(FindAll(conditions)); }
public IEnumerable <Card> FindFromTextAndManaCostAndColorsAndBaseType(GetCardRequest request) { LambdaLogger.Log($"Entering: FindFromTextAndManaCostAndColorsAndBaseType({ JsonConvert.SerializeObject(request) })"); var conditions = new List <ScanCondition>(); AddSearchConditions(request, conditions); AddManaCostConditions(request, conditions); AddColorConditions(request, conditions); AddBaseTypeConditions(request, conditions); return(FindAll(conditions)); }
private void AddBaseTypeConditions(GetCardRequest request, List <ScanCondition> conditions) { LambdaLogger.Log($"Entering: AddBaseTypeConditions({ JsonConvert.SerializeObject(request) })"); var queryList = new List <string>(); foreach (var baseType in request.BaseTypeFilter) { if (baseType.Value) { queryList.Add(baseType.Key); } } if (queryList.Contains("Creature")) { queryList.Add("Artifact Creature"); queryList.Add("Enchantment Creature"); queryList.Add("Enchantment Artifact Creature"); } else { if (queryList.Contains("Artifact")) { queryList.Add("Artifact Creature"); } if (queryList.Contains("Enchantment")) { queryList.Add("Enchantment Creature"); } } if (queryList.Contains("Planeswalker")) { queryList.Add("Legendary Planeswalker"); } LambdaLogger.Log($"Query List: { JsonConvert.SerializeObject(queryList) }"); if (queryList.Any()) { var objects = queryList.Select(x => (object)x).ToArray(); var condition = new ScanCondition("BaseType", ScanOperator.In, objects); conditions.Add(condition); } }
private void AddColorConditions(GetCardRequest request, List <ScanCondition> conditions) { List <string> containsList = new List <string>(); List <string> excludeList = new List <string>(); foreach (var keypair in request.ColorFilter) { if (keypair.Value == null) { //Doesn't matter } else if (keypair.Value.Value) //True { containsList.Add(keypair.Key); } else if (!keypair.Value.Value) //False { excludeList.Add(keypair.Key); } } foreach (var colorCondition in containsList) { conditions.Add(new ScanCondition("ColorIdentity", ScanOperator.Contains, colorCondition)); } //Doesn't work well for what I'm trying to do. Better to just negate them in memory on the other side //foreach(var negateCondition in excludeList) //{ // conditions.Add(new ScanCondition("ColorIdentity", ScanOperator.NotContains, negateCondition)); //} //if (containsList.Any()) // conditions.Add(new ScanCondition("ColorIdentity", ScanOperator.Contains, containsList.ToArray())); //if (excludeList.Any()) // conditions.Add(new ScanCondition("ColorIdentity", ScanOperator.NotContains, excludeList.ToArray())); }
public async Task TestPatchCard() { var assignment = CreateAssignmentNew(); var assignmentId = await AssignmentUtils.CreateAssignment(assignment); var cardPatch = new CardPatch(); cardPatch.Add("label", "New Label"); var patchCardRequest = new PatchCardRequest(cardPatch, assignmentId, AssignmentUtils.ROOT_SEQUENCE_ID, CARD_ID); await SkyManager.ApiClient.ExecuteRequestAsync(patchCardRequest); //TODO: If we wanted to do a full integration test, we could get the card and make sure the label has updated var getCardRequest = new GetCardRequest(assignmentId, AssignmentUtils.ROOT_SEQUENCE_ID, CARD_ID); var getCardResponse = await SkyManager.ApiClient.ExecuteRequestAsync(getCardRequest); var returnedCard = getCardResponse.Content; Assert.Equal(SkyManager.IntegrationId, returnedCard.UpdatedBy); Assert.NotNull(returnedCard.Updated); await AssignmentUtils.DeleteAssignment(assignmentId); }
private void AddColorConditions(GetCardRequest request, List <ScanCondition> conditions) { List <string> containsList = new List <string>(); List <string> excludeList = new List <string>(); foreach (var keypair in request.ColorFilter) { if (keypair.Value == null) { //Doesn't matter } else if (keypair.Value.Value) //True { containsList.Add(keypair.Key); } else if (!keypair.Value.Value) //False { excludeList.Add(keypair.Key); } } foreach (var colorCondition in containsList) { conditions.Add(new ScanCondition("ColorIdentity", ScanOperator.Contains, colorCondition)); } foreach (var excludeColorCondition in excludeList) { conditions.Add(new ScanCondition("ColorIdentity", ScanOperator.Contains, excludeColorCondition)); } //if (containsList.Any()) // conditions.Add(new ScanCondition("ColorIdentity", ScanOperator.Contains, containsList.ToArray())); //if (excludeList.Any()) // conditions.Add(new ScanCondition("ColorIdentity", ScanOperator.NotContains, excludeList.ToArray())); }
public async Task TestGetCard() { var assignment = CreateAssignmentNew(); var assignmentId = await AssignmentUtils.CreateAssignment(assignment); var getCardRequest = new GetCardRequest(assignmentId, AssignmentUtils.ROOT_SEQUENCE_ID, CARD_ID); var getCardResponse = await SkyManager.ApiClient.ExecuteRequestAsync(getCardRequest); var returnedCard = getCardResponse.Content; Assert.Equal(returnedCard.Id, CARD_ID); Assert.Equal(returnedCard.AssignmentId, assignmentId); Assert.Equal(returnedCard.CreatedBy, SkyManager.IntegrationId); Assert.NotNull(returnedCard.Created); Assert.NotNull(returnedCard.Footer); Assert.NotNull(returnedCard.Header); Assert.False(returnedCard.HideLabel); Assert.Equal(returnedCard.IntegrationId, SkyManager.IntegrationId); Assert.False(returnedCard.IsDone); Assert.False(returnedCard.Locked); Assert.False(returnedCard.Required); Assert.NotNull(returnedCard.Notes); Assert.NotNull(returnedCard.Label); Assert.NotNull(returnedCard.Revision); Assert.Equal(AssignmentUtils.ROOT_SEQUENCE_ID, returnedCard.SequenceId); Assert.Equal(1, returnedCard.Size); Assert.False(returnedCard.Subdued); Assert.Empty(returnedCard.Tags); Assert.NotNull(returnedCard.TemplateId); Assert.Equal(1, returnedCard.Position); Assert.False(returnedCard.Selectable); await AssignmentUtils.DeleteAssignment(assignmentId); }
public void TestGetCardRequest() { var getCardRequest = new GetCardRequest(); getCardRequest.Init(new StringReader("GCR0520000000000001000131207102355876523456803021402220217")); Assert.AreEqual(0, getCardRequest.AcquirerId.Value); Assert.AreEqual(0, getCardRequest.TargetAid.Value); Assert.AreEqual(1000, getCardRequest.TransactionAmount.Value); Assert.AreEqual("131207102355", getCardRequest.TransactionDateTime.Value.ToString("yyMMddHHmmss")); Assert.AreEqual("8765234568", getCardRequest.TableVersion.Value); Assert.AreEqual(3, getCardRequest.AidEntryReferences.Count); Assert.AreEqual(2, getCardRequest.AidEntryReferences[0].AcquirerId.Value); Assert.AreEqual(14, getCardRequest.AidEntryReferences[0].RecordIndex.Value); Assert.AreEqual(2, getCardRequest.AidEntryReferences[1].AcquirerId.Value); Assert.AreEqual(22, getCardRequest.AidEntryReferences[1].RecordIndex.Value); Assert.AreEqual(2, getCardRequest.AidEntryReferences[2].AcquirerId.Value); Assert.AreEqual(17, getCardRequest.AidEntryReferences[2].RecordIndex.Value); Assert.IsNull(getCardRequest.ContactlessOn.Value); }
public IEnumerable <Card> FindFromTextAndColors(GetCardRequest request) { var conditions = new List <ScanCondition>(); AddSearchConditions(request, conditions); AddColorConditions(request, conditions); var results = FindAll(conditions); //if (request.ColorFilter.ContainsValue(false)) //{ // var negateColors = request.ColorFilter // .Where(x => x.Value == false) // .Select(x => x.Key) // .ToList(); // foreach (var negateColor in negateColors) // results = results.Where(x => !x.ColorIdentity.Contains(negateColor)).ToList(); //} return(results); }
private void AddBaseTypeConditions(GetCardRequest request, List <ScanCondition> conditions) { LambdaLogger.Log($"Entering: AddBaseTypeConditions({ JsonConvert.SerializeObject(request) })"); var queryList = new List <string>(); foreach (var baseType in request.BaseTypeFilter) { if (baseType.Value) { queryList.Add(baseType.Key); } } LambdaLogger.Log($"Query List: { JsonConvert.SerializeObject(queryList) }"); if (queryList.Any()) { var objects = queryList.Select(x => (object)x).ToArray(); var condition = new ScanCondition("BaseType", ScanOperator.In, objects); conditions.Add(condition); } }
/// <summary> /// Gets cards by request /// - NameFilter: Searches against name /// - TextFilter: Searches against the card text /// - ColorFilter: Searches filters based on color /// </summary> /// <param name="request"></param> /// <returns></returns> public List <Card> GetCardsFromRequest(GetCardRequest request) { LambdaLogger.Log($"Entering: FindFromRequest({ JsonConvert.SerializeObject(request) })"); var response = new List <Card>(); try { if (!string.IsNullOrWhiteSpace(request.NameFilter)) { LambdaLogger.Log($"Name Filter: { request.NameFilter }"); if (request.ManaCostFilter != null && request.ColorFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndManaCostAndColorsAndBaseType(request) .ToList(); } else if (request.ManaCostFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndManaCostAndBaseType(request) .ToList(); } else if (request.ManaCostFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndManaCostAndColors(request) .ToList(); } else if (request.BaseTypeFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndBaseTypeAndColors(request) .ToList(); } else if (request.ManaCostFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndManaCost(request) .ToList(); } else if (request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndColors(request) .ToList(); } else if (request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndBaseType(request) .ToList(); } else { response = SvcContext.Repository .Cards .FindFromName(request.NameFilter) .ToList(); } } else if (!string.IsNullOrWhiteSpace(request.TextFilter)) { LambdaLogger.Log($"Text Filter: { request.TextFilter }"); if (request.ManaCostFilter != null && request.ColorFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndManaCostAndColorsAndBaseType(request) .ToList(); } else if (request.ManaCostFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndManaCostAndBaseType(request) .ToList(); } else if (request.ManaCostFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndManaCostAndColors(request) .ToList(); } else if (request.BaseTypeFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndBaseTypeAndColors(request) .ToList(); } else if (request.ManaCostFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndManaCost(request) .ToList(); } else if (request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndColors(request) .ToList(); } else if (request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndBaseType(request) .ToList(); } else { response = SvcContext.Repository .Cards .FindFromText(request.TextFilter) .ToList(); } } else if (!string.IsNullOrWhiteSpace(request.KeywordsFilter)) { throw new NotImplementedException("Keyword filter not supported yet"); } else { LambdaLogger.Log($"No search bar content: { JsonConvert.SerializeObject(request) }"); if (request.ManaCostFilter != null && request.ColorFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromManaCostAndBaseTypeAndColors(request) .ToList(); } else if (request.ManaCostFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromManaCostAndColors(request) .ToList(); } else if (request.ManaCostFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromManaCostAndBaseType(request) .ToList(); } else if (request.BaseTypeFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromBaseTypeAndColors(request) .ToList(); } else if (request.ManaCostFilter != null) { response = SvcContext.Repository .Cards .FindFromManaCost(request) .ToList(); } else if (request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromBaseType(request) .ToList(); } else if (request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromColors(request) .ToList(); } } } catch (Exception exp) { LambdaLogger.Log($"Error: { exp }"); throw; } LambdaLogger.Log($"Leaving: FindFromRequest({ JsonConvert.SerializeObject(response) })"); return(response.Where(c => !string.IsNullOrWhiteSpace(c.ImageUrl)) .GroupBy(c => c.CardText) .Select(g => g.First()) .ToList()); }
/// <summary> /// Gets cards by request /// - NameFilter: Searches against name /// - TextFilter: Searches against the card text /// - ColorFilter: Searches filters based on color /// </summary> /// <param name="request"></param> /// <returns></returns> public List <Card> GetCardsFromRequest(GetCardRequest request) { LambdaLogger.Log($"Entering: FindFromRequest({ JsonConvert.SerializeObject(request) })"); var response = new List <Card>(); try { if (!string.IsNullOrWhiteSpace(request.NameFilter)) { LambdaLogger.Log($"Name Filter: { request.NameFilter }"); if (request.ManaCostFilter != null && request.ColorFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndManaCostAndColorsAndBaseType(request) .ToList(); } else if (request.ManaCostFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndManaCostAndBaseType(request) .ToList(); } else if (request.ManaCostFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndManaCostAndColors(request) .ToList(); } else if (request.BaseTypeFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndBaseTypeAndColors(request) .ToList(); } else if (request.ManaCostFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndManaCost(request) .ToList(); } else if (request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndColors(request) .ToList(); } else if (request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromNameAndBaseType(request) .ToList(); } else { response = SvcContext.Repository .Cards .FindFromName(request.NameFilter) .ToList(); } } else if (!string.IsNullOrWhiteSpace(request.TextFilter)) { LambdaLogger.Log($"Text Filter: { request.TextFilter }"); if (request.ManaCostFilter != null && request.ColorFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndManaCostAndColorsAndBaseType(request) .ToList(); } else if (request.ManaCostFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndManaCostAndBaseType(request) .ToList(); } else if (request.ManaCostFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndManaCostAndColors(request) .ToList(); } else if (request.BaseTypeFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndBaseTypeAndColors(request) .ToList(); } else if (request.ManaCostFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndManaCost(request) .ToList(); } else if (request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndColors(request) .ToList(); } else if (request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromTextAndBaseType(request) .ToList(); } else { response = SvcContext.Repository .Cards .FindFromText(request.TextFilter) .ToList(); } } else if (!string.IsNullOrWhiteSpace(request.KeywordsFilter)) { response = SvcContext.Repository .Cards .FindFromKeywordAndManaCostAndColorsAndBaseType(request) .ToList(); } else { LambdaLogger.Log($"No search bar content: { JsonConvert.SerializeObject(request) }"); if (request.ManaCostFilter != null && request.ColorFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromManaCostAndBaseTypeAndColors(request) .ToList(); } else if (request.ManaCostFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromManaCostAndColors(request) .ToList(); } else if (request.ManaCostFilter != null && request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromManaCostAndBaseType(request) .ToList(); } else if (request.BaseTypeFilter != null && request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromBaseTypeAndColors(request) .ToList(); } else if (request.ManaCostFilter != null) { response = SvcContext.Repository .Cards .FindFromManaCost(request) .ToList(); } else if (request.BaseTypeFilter != null) { response = SvcContext.Repository .Cards .FindFromBaseType(request) .ToList(); } else if (request.ColorFilter != null) { response = SvcContext.Repository .Cards .FindFromColors(request) .ToList(); } } } catch (Exception exp) { LambdaLogger.Log($"Error: { exp }"); throw; } LambdaLogger.Log($"Leaving: FindFromRequest({ JsonConvert.SerializeObject(response) })"); return(response); //if (request.IncludePrice) //{ // var tcgService = ServiceFactory.GetService<TCGService>(); // List<TCGSearchFilter> filters = new List<TCGSearchFilter>(); // filters.Add(new TCGSearchFilter() { name = "ProductName", values = cardList.Select(x => x.Name).ToList() }); // TCGSearchRequest tcgRequest = new TCGSearchRequest // { // filters = filters // }; // var tcgResponse = tcgService.Search(tcgRequest).Result; // if (tcgResponse.success) // { // LambdaLogger.Log($"TCG Response Results: { JsonConvert.SerializeObject(tcgResponse) }"); // } // else // LambdaLogger.Log($"Request Failure for TCG Search: { JsonConvert.SerializeObject(tcgRequest) }"); //} }