public IEnumerable<CardItem> SelectCards(CardSearchParams parameters) { SortableList cards = new SortableList(new CardItemComparer(parameters.OrderCriteria), 100000); cards.KeepSorted = true; System.Collections.IEnumerable cardNodes = null; // id if(parameters.Ids.Count > 0) { cardNodes = parameters.Ids.Distinct().Where(e => cardNodesById.ContainsKey(e)).Select(id => cardNodesById[id]); } else { StringBuilder xpath = new StringBuilder(); if(parameters.Sets.Count > 0) AddParameter(xpath, "set", parameters.Sets); if(parameters.Types.Count > 0) AddParameter(xpath, "type", parameters.Types); if(parameters.Rarities.Count > 0) AddParameter(xpath, "rarity", parameters.Rarities); if(!string.IsNullOrEmpty(parameters.Characteristics)) { if(xpath.Length > 0) xpath.Append(" and "); xpath.Append("contains(characteristics,'"); xpath.Append(parameters.Characteristics.Trim()); xpath.Append("')"); } if(xpath.Length > 0) { xpath.Insert(0, "["); xpath.Append("]"); } xpath.Insert(0, "item"); cardNodes = cardDatabase.DocumentElement.SelectNodes(xpath.ToString(), cardsNsManager); } foreach(XmlNode cardNode in cardNodes) { XmlNode langNode = langNodesById[cardNode.SelectSingleNode("id").InnerText]; bool valid = true; if(!string.IsNullOrEmpty(parameters.Name)) { if(parameters.NameExact) valid = string.Compare(langNode.SelectSingleNode("name").InnerText, parameters.Name, true) == 0; else valid = langNode.SelectSingleNode("name").InnerText.IndexOf(parameters.Name, StringComparison.OrdinalIgnoreCase) != -1; } if(valid && !string.IsNullOrEmpty(parameters.Text)) { valid = langNode.SelectSingleNode("text").InnerText.IndexOf(parameters.Text, StringComparison.OrdinalIgnoreCase) != -1; } if(valid) { if(parameters.Colors.Count > 0) { List<string> colors = new List<string>(); foreach(XmlNode colorNode in cardNode.SelectNodes("colors/color")) colors.Add(colorNode.InnerText); valid = parameters.Colors.Any(e => colors.Contains(e)); } } if(valid && parameters.Cost.Criteria != CostCriteria.None) { int cost = cardNode.SelectSingleNode("cost").InnerText.Replace("{", "").Replace("}", "").ToCharArray().Sum(c => char.IsNumber(c) ? Convert.ToInt32(c.ToString()) : 1); switch(parameters.Cost.Criteria) { case CostCriteria.EqualTo: valid = cost == parameters.Cost.Value; break; case CostCriteria.LessThan: valid = cost < parameters.Cost.Value; break; case CostCriteria.MoreThan: valid = cost > parameters.Cost.Value; break; } } if(valid) { cards.Add(new CardItem(cardNode, langNode, typesService.GetByCode(cardNode["type"].InnerText))); } } return cards.Cast<CardItem>(); }
/// <summary> /// ICloneable implementation. /// Idem <see cref="ArrayList">ArrayList</see> /// </summary> /// <returns>Cloned object.</returns> public object Clone() { SortableList Clone = new SortableList(_Comparer, _List.Capacity); Clone._List = (ArrayList)_List.Clone(); Clone._AddDuplicates = _AddDuplicates; Clone._IsSorted = _IsSorted; Clone._KeepSorted = _KeepSorted; return Clone; }