예제 #1
0
        private void mapProduct(string productName)
        {
            mapping mapping = new mapping();

            mapping.originalname = productName;
            database.mappings.Add(mapping);
            Console.WriteLine("new mapping created for product with name {0}", productName);
            mappings.Add(mapping);
        }
예제 #2
0
        private void mapIngredient(string ingredientName)
        {
            mapping mapping = new mapping();

            mapping.originalname = ingredientName;
            mapping.isingredient = true;
            database.mappings.Add(mapping);
            Console.WriteLine("new mapping created for ingredient with name {0}", ingredientName);
            mappings.Add(mapping);
        }
예제 #3
0
        private string GetMappedValue(string value, bool isIngredient)
        {
            mapping mapping = mappings.SingleOrDefault(i => i.originalname.ToLower() == value.Trim().ToLower() && i.mappedto != string.Empty && i.isingredient == isIngredient);

            if (mapping != null && mapping.mappedto != "" && mapping.mappedto != null)
            {
                return(mapping.mappedto);
            }
            return(value);
        }
예제 #4
0
        protected ingredient GetMappedIngredient(string ingredientName)
        {
            mapping mapping = database.mappings.SingleOrDefault(i => i.originalname == ingredientName && i.isingredient && i.mappedto != null);

            if (mapping != null)
            {
                return(database.ingredients.SingleOrDefault(i => i.name == mapping.mappedto));
            }
            return(null);
        }
예제 #5
0
        /**
         * Parse a given Order file for unknown ingredient or product names. If there is no prior mapping for them, add the name to the mapping table.
         */
        public void ParseMappingFromOrderFile(string filePath)
        {
            List <string> allLineInMapping = File.ReadAllLines(filePath).ToList();

            allLineInMapping.RemoveRange(0, 5); // Remove the header.

            foreach (string line in allLineInMapping)
            {
                string[] partCollection = line.Split(';');

                if (partCollection.Length <= 1)
                {
                    // Skip empty lines or lines with a comment.
                    continue;
                }
                if (partCollection.Length != 23)
                {
                    throw new InvalidDataException("Unexpected number of columns, a non-order table has been passed to the mapping function.");
                }

                string productName         = partCollection[10].ToString().Trim();
                string extraIngredientList = partCollection[16].ToString().Trim();

                if (productName.Length > 0)
                {
                    // If the product already exists, or there is a mapping for it already, no need to map it again.
                    product product         = products.SingleOrDefault(i => i.name == productName);
                    mapping existingMapping = mappings.SingleOrDefault(i => i.originalname == productName && i.isingredient == false);
                    if (product == null && existingMapping == null)
                    {
                        mapProduct(productName);
                    }
                }

                if (extraIngredientList.Length > 0)
                {
                    string[] ingredientNameCollection = extraIngredientList.Split(',');
                    foreach (string ingredientName in ingredientNameCollection)
                    {
                        string ingredientNameFormatted = ingredientName.Trim();

                        // If the ingredient already exists, or there is a mapping for it already, no need to map it again.
                        ingredient ingredient      = ingredients.SingleOrDefault(i => i.name == ingredientNameFormatted);
                        mapping    existingMapping = mappings.SingleOrDefault(i => i.originalname == ingredientNameFormatted && i.isingredient == true);
                        if (ingredient == null && existingMapping == null)
                        {
                            mapIngredient(ingredientNameFormatted);
                        }
                    }
                }
            }

            database.SaveChanges();
        }
        private void CreateMappingForIngredient(string ingredientName)
        {
            mapping mapping = new mapping();

            mapping.originalname = ingredientName;
            mapping.isingredient = true;

            database.mappings.Add(mapping);

            database.SaveChanges();
        }