/// <summary>
        /// Populates every ConverterMapping in each Section with potential cards from the converterSets
        /// </summary>
        /// <param name="converterSets">List of all ConverterSets. Only those with flag IncludeInSearches will be used.</param>
        public void PopulateConverterMappings(Dictionary <Guid, ConverterSet> converterSets)
        {
            Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > > normalizedConverterCards = ConverterMapping.NormalizeConverterCards(converterSets.Values);

            foreach (ConverterSection converterSection in this.ConverterSections)
            {
                foreach (ConverterMapping converterMapping in converterSection.SectionMappings)
                {
                    converterMapping.PopulateWithPotentialCards(normalizedConverterCards);
                }

                // Try matching each incorrectly formatted line, and assume a quantity of 1
                List <string> linesWithoutQuantityButMatchingName = new List <string>();
                foreach (string incorrectlyFormattedLine in converterSection.IncorrectlyFormattedLines)
                {
                    if (!string.IsNullOrWhiteSpace(incorrectlyFormattedLine))
                    {
                        ConverterMapping cm = new ConverterMapping(incorrectlyFormattedLine, string.Empty, 1);
                        cm.PopulateWithPotentialCards(normalizedConverterCards);
                        if (cm.PotentialOCTGNCards.Count > 0)
                        {
                            converterSection.AddConverterMapping(cm);
                            linesWithoutQuantityButMatchingName.Add(incorrectlyFormattedLine);
                        }
                    }
                }

                // Incorrectly formatted lines which were found to match a card name should be removed from incorrect list.
                foreach (string line in linesWithoutQuantityButMatchingName)
                {
                    converterSection.RemoveIncorrectlyFormattedLine(line);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the InlineDialogPage_ChooseAnotherCardVM class.
        /// </summary>
        /// <param name="converterMapping">The Converter Mapping which contains the parsed card name to match to</param>
        /// <param name="converterGame">The Converter Game to be used when searching for another card</param>
        public InlineDialogPage_ChooseAnotherCardVM(ConverterMapping converterMapping, ConverterGame converterGame)
        {
            if (converterGame == null)
            {
                throw new ArgumentNullException("converterGame");
            }

            this._ConverterGame = converterGame;
            this.ConverterMapping = converterMapping;
        }
 /// <summary>
 /// Adds the converterMapping to the list of SectionMappings
 /// </summary>
 /// <param name="converterMapping">The ConverterMapping to add</param>
 /// <returns>True if mapping was successfully added, False if not added</returns>
 public bool AddConverterMapping(ConverterMapping converterMapping)
 {
     if (!this._SectionMappings.Contains(converterMapping))
     {
         this._SectionMappings.Add(converterMapping);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a Name that has been normalized.  This means all funny characters,
        /// punctuation, white space, capitalization, has been removed or sanitized.
        /// </summary>
        /// <param name="name">The name of the Card or Set etc to normalize</param>
        /// <returns></returns>
        private static string NormalizeName(string name)
        {
            // Remove extra whitespace
            name = name.Trim();

            // Remove all Diacritics from names for comparison
            name = ConverterMapping.RemoveDiacritics(name);

            // Replace all characters specifically designated to aid in comparison
            foreach (dynamic replacementChar in replacementChars)
            {
                name = name.Replace(replacementChar.Actual, replacementChar.Normalized);
            }

            return(name.ToLowerInvariant());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a Dictionary who's Keys are the normalized first name of the Card, and who's Values are all of the matching ConverterCard/ConverterSet Tuples.
        /// </summary>
        /// <param name="converterSets">The ConverterSets to look through to build the normalized ConverterCard Dictionary</param>
        /// <returns>a Dictionary who's Keys are the normalized first name of the Card, and who's Values are all of the matching ConverterCard/ConverterSet Tuples.</returns>
        public static Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > > NormalizeConverterCards(IEnumerable <ConverterSet> converterSets)
        {
            Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > > normalizedConverterCards = new Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > >();

            foreach (ConverterSet converterSet in converterSets)
            {
                if (converterSet.IncludeInSearches)
                {
                    foreach (ConverterCard converterCard in converterSet.ConverterCards)
                    {
                        string normalizedFirstName = ConverterMapping.NormalizeName(converterCard.Name.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).First());
                        if (!normalizedConverterCards.ContainsKey(normalizedFirstName))
                        {
                            normalizedConverterCards.Add(normalizedFirstName, new List <Tuple <ConverterCard, ConverterSet> >());
                        }

                        normalizedConverterCards[normalizedFirstName].Add(new Tuple <ConverterCard, ConverterSet>(converterCard, converterSet));
                    }
                }
            }
            return(normalizedConverterCards);
        }
 /// <summary>
 /// Removes the converterMapping from the SectionMappings list of mappings.
 /// </summary>
 /// <param name="converterMapping">The ConverterMapping to remove</param>
 /// <returns>True if mapping was successfully removed, False if not removed</returns>
 public bool RemoveConverterMapping(ConverterMapping converterMapping)
 {
     return(this._SectionMappings.Remove(converterMapping));
 }
        private static void VerifyConverterMappingsAreIdentical(ConverterMapping converterMapping, ConverterMapping otherConverterMapping)
        {
            Assert.AreEqual(converterMapping.CardName, otherConverterMapping.CardName);
            if (!string.IsNullOrWhiteSpace(converterMapping.CardSet) && !string.IsNullOrWhiteSpace(otherConverterMapping.CardSet))
            {
                Assert.AreEqual(converterMapping.CardSet, otherConverterMapping.CardSet);
            }
            Assert.AreEqual(converterMapping.Quantity, otherConverterMapping.Quantity);
            if (converterMapping.SelectedOCTGNCard != null)
            {
                VerifyConverterCardsAreIdentical(converterMapping.SelectedOCTGNCard, otherConverterMapping.SelectedOCTGNCard);
            }
            Assert.AreEqual(converterMapping.PotentialOCTGNCards.Count, otherConverterMapping.PotentialOCTGNCards.Count);

            foreach(ConverterCard potentialConverterCard in converterMapping.PotentialOCTGNCards)
            {
                ConverterCard otherPotentialConverterCard = otherConverterMapping.PotentialOCTGNCards.First(poc => poc.CardID == potentialConverterCard.CardID);
                VerifyConverterCardsAreIdentical(potentialConverterCard, otherPotentialConverterCard);
            }

            Assert.AreEqual(converterMapping.CardName, otherConverterMapping.CardName);
        }
        /// <summary>
        /// Populates every ConverterMapping in each Section with potential cards from the converterSets
        /// </summary>
        /// <param name="converterSets">List of all ConverterSets. Only those with flag IncludeInSearches will be used.</param>
        public void PopulateConverterMappings(Dictionary<Guid, ConverterSet> converterSets)
        {
            Dictionary<string, List<Tuple<ConverterCard, ConverterSet>>> normalizedConverterCards = ConverterMapping.NormalizeConverterCards(converterSets.Values);

            foreach (ConverterSection converterSection in this.ConverterSections)
            {
                foreach (ConverterMapping converterMapping in converterSection.SectionMappings)
                {
                    converterMapping.PopulateWithPotentialCards(normalizedConverterCards);
                }

                // Try matching each incorrectly formatted line, and assume a quantity of 1
                List<string> linesWithoutQuantityButMatchingName = new List<string>();
                foreach (string incorrectlyFormattedLine in converterSection.IncorrectlyFormattedLines)
                {
                    if (!string.IsNullOrWhiteSpace(incorrectlyFormattedLine))
                    {
                        ConverterMapping cm = new ConverterMapping(incorrectlyFormattedLine, string.Empty, 1);
                        cm.PopulateWithPotentialCards(normalizedConverterCards);
                        if (cm.PotentialOCTGNCards.Count > 0)
                        {
                            converterSection.AddConverterMapping(cm);
                            linesWithoutQuantityButMatchingName.Add(incorrectlyFormattedLine);
                        }
                    }
                }
                
                // Incorrectly formatted lines which were found to match a card name should be removed from incorrect list.
                foreach(string line in linesWithoutQuantityButMatchingName)
                {
                    converterSection.RemoveIncorrectlyFormattedLine(line);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Searches through all converterSets for Cards which potentially match this CardName/CardSet.
        /// Each potential card is added as a potential Card.
        /// </summary>
        /// <param name="converterCardDictionary">
        /// A Dictionary of ConverterCards which are potential matches, where the Key is the normalized first name
        /// of the card and the value is a collection of all corresponding ConverterCards-ConverterSet tuples.  Only sets which are
        /// included in searches should be in this.</param>
        public void PopulateWithPotentialCards(Dictionary <string, List <Tuple <ConverterCard, ConverterSet> > > converterCardDictionary)//(Dictionary<Guid, ConverterSet> converterSets)
        {
            // Some cards have 2+ names, so create an array of all the names in order
            List <string> converterMappingNames =
                (from string mappingName in this.CardName.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                 select ConverterMapping.NormalizeName(mappingName)).ToList();

            if (converterCardDictionary.ContainsKey(converterMappingNames.First()))
            {
                foreach (Tuple <ConverterCard, ConverterSet> converterCardAndSet in converterCardDictionary[converterMappingNames.First()])
                {
                    ConverterCard converterCard = converterCardAndSet.Item1;

                    List <string> converterCardNames =
                        (from string cardName in converterCard.Name.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                         select ConverterMapping.NormalizeName(cardName)).ToList();
                    int numIndexToCompare = Math.Min(converterMappingNames.Count, converterCardNames.Count);

                    // Compare all names.  If one card has less names than the other, then just compare indexes where
                    // both names are present because sometimes another format only includes the first name
                    bool isNameMatch = true;
                    for (int i = 0; i < numIndexToCompare; i++)
                    {
                        if (!converterCardNames[i].Equals(converterMappingNames[i]))
                        {
                            isNameMatch = false;
                            break;
                        }
                    }

                    bool isSetMatch = true;
                    if (isNameMatch && !string.IsNullOrWhiteSpace(this.CardSet))
                    {
                        ConverterSet converterSet = converterCardAndSet.Item2;

                        // LoTR - Pay attention to Set
                        if (converterSet.OctgnSet.GameId == ConvertEngine.Game.LoTR.GameGuidStatic)
                        {
                            string converterCardSet    = converterCard.Set;
                            string converterMappingSet = this.CardSet;

                            // Some sources omit 'The Hobbit - ' in the set name, so remove it from the comparison
                            if (converterCardSet.StartsWith("The Hobbit", StringComparison.InvariantCultureIgnoreCase))
                            {
                                converterCardSet = converterCardSet.Substring(13);
                            }
                            if (converterMappingSet.StartsWith("The Hobbit", StringComparison.InvariantCultureIgnoreCase))
                            {
                                converterMappingSet = converterMappingSet.Substring(13);
                            }

                            // Some sources omit 'The ' in the set name, so remove it from the comparison
                            if (converterCardSet.StartsWith("The ", StringComparison.InvariantCultureIgnoreCase))
                            {
                                converterCardSet = converterCardSet.Substring(4);
                            }
                            if (converterMappingSet.StartsWith("The ", StringComparison.InvariantCultureIgnoreCase))
                            {
                                converterMappingSet = converterMappingSet.Substring(4);
                            }

                            // Remove all Diacritics from names for comparison
                            converterCardSet    = ConverterMapping.NormalizeName(converterCardSet);
                            converterMappingSet = ConverterMapping.NormalizeName(converterMappingSet);

                            if (!converterCardSet.Equals(converterMappingSet))
                            {
                                isSetMatch = false;
                            }
                        }
                    }

                    if (isNameMatch && isSetMatch)
                    {
                        this.AddPotentialOCTGNCard(converterCard);
                    }
                }
            }
        }
 /// <summary>
 /// Removes the converterMapping from the SectionMappings list of mappings.
 /// </summary>
 /// <param name="converterMapping">The ConverterMapping to remove</param>
 /// <returns>True if mapping was successfully removed, False if not removed</returns>
 public bool RemoveConverterMapping(ConverterMapping converterMapping)
 {
     return this._SectionMappings.Remove(converterMapping);
 }
 /// <summary>
 /// Adds the converterMapping to the list of SectionMappings
 /// </summary>
 /// <param name="converterMapping">The ConverterMapping to add</param>
 /// <returns>True if mapping was successfully added, False if not added</returns>
 public bool AddConverterMapping(ConverterMapping converterMapping)
 {
     if (!this._SectionMappings.Contains(converterMapping))
     {
         this._SectionMappings.Add(converterMapping);
         return true;
     }
     else
     {
         return false;
     }
 }