예제 #1
0
        private IList <FoodResult> FindFood(IList <HtmlNode> foodNodes, IEnumerable <string> names)
        {
            List <FoodResult> result = new List <FoodResult>();

            string     name;
            FoodResult food;

            foreach (var foodNode in foodNodes)
            {
                name = foodNode.InnerText;

                if (IsContains(names, name))
                {
                    food      = new FoodResult();
                    food.Name = Regex.Replace(name.Replace(",-", ""), @"[\d]", string.Empty);

                    food.Price        = ConvertToPrice(foodNode.SelectSingleNode("strong").InnerText);
                    food.ProviderType = ProviderType;

                    result.Add(food);
                }
            }

            return(result);
        }
예제 #2
0
        private IList <FoodResult> ConvertToFoodResult(HtmlDocument doc, string id, IEnumerable <string> names)
        {
            List <FoodResult> result = new List <FoodResult>();

            string     name;
            FoodResult food;
            var        n = GetNode(doc, $@"//*[@id=""{id}""]");

            //n.SelectNodes(@"//*[@id=""{id}""]/div[1]/ul/li[1]/div"
            foreach (var node in n.Descendants("div").Where(d => d.Attributes["class"].Value.Contains("single-food")))
            {
                name = node.SelectSingleNode("strong").InnerText;
                if (IsContains(names, name))
                {
                    food              = new FoodResult();
                    food.Name         = name;
                    food.Price        = ConvertToPrice(node.SelectSingleNode("span[@class='food-price']").InnerText);
                    food.ProviderType = ProviderType;

                    result.Add(food);
                }
            }
            //foreach (var item in collection)
            //{

            //}

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Looks up a particular item tag to see what foods it can be used to produce.
        /// </summary>
        /// <param name="tag">The item tag to look up.</param>
        /// <returns>The foods for which it can be used, or an empty array if it cannot be used
        /// for any foods.</returns>
        public FoodResult[] Lookup(Tag tag)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }
            // Check for existing list
            if (!cache.TryGetValue(tag, out IList <FoodResult> items))
            {
                var seen = HashSetPool <Tag, FoodRecipeCache> .Allocate();

                try {
                    items = new List <FoodResult>();
                    SearchForRecipe(tag, items, seen, 1.0f);
                    cache.Add(tag, items);
                } finally {
                    seen.Recycle();
                }
            }
            // Create a copy of the results
            int n      = items.Count;
            var result = new FoodResult[n];

            if (n > 0)
            {
                items.CopyTo(result, 0);
            }
            return(result);
        }
예제 #4
0
        private IList <FoodResult> FindByDate(HtmlDocument doc, DateTime date, IEnumerable <string> names)
        {
            List <FoodResult> result = new List <FoodResult>();

            FoodResult         food;
            string             name;
            HtmlNodeCollection thCollection;
            bool inDayLoop = false;
            int  inOneDay  = 9;
            int  i         = 1;

            foreach (var node in GetNode(doc, tableXPath).SelectNodes("tr"))
            {
                if (!inDayLoop)
                {
                    thCollection = node.SelectNodes("th");
                    if (thCollection?.Count == 2)
                    {
                        if (IsSameDay(date, thCollection[1].InnerText))
                        {
                            inDayLoop = true;
                        }
                    }
                }
                else
                {
                    name = node.SelectNodes("td")[1].InnerText;
                    if (IsContains(names, name))
                    {
                        food              = new FoodResult();
                        food.Name         = name;
                        food.Price        = ConvertToPrice(node.SelectNodes("td")[2].InnerText);
                        food.ProviderType = ProviderType;

                        result.Add(food);
                    }
                    if (i == inOneDay)
                    {
                        break;
                    }
                    i++;
                }
            }

            return(result);
        }
예제 #5
0
        private IList <FoodResult> ConvertToFoodResult(HtmlDocument doc, HtmlNode tableNode, IEnumerable <string> names)
        {
            List <FoodResult> result = new List <FoodResult>();

            FoodResult food;
            string     name;

            foreach (var row in tableNode.SelectNodes("tr"))
            {
                name = row.SelectSingleNode("td[@class='name']").InnerText;
                if (IsContains(names, name))
                {
                    food              = new FoodResult();
                    food.Name         = name.Split('|')[0];
                    food.Price        = ConvertToPrice(row.SelectSingleNode("td[@class='price']").InnerText);
                    food.ProviderType = ProviderType;

                    result.Add(food);
                }
            }

            return(result);
        }
예제 #6
0
        /// <summary>
        /// Looks up a particular item tag to see what foods it can be used to produce.
        /// </summary>
        /// <param name="tag">The item tag to look up.</param>
        /// <returns>The foods for which it can be used, or an empty array if it cannot be used
        /// for any foods.</returns>
        public FoodResult[] Lookup(Tag tag)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }
            // Check for existing list
            if (!cache.TryGetValue(tag, out IList <FoodResult> items))
            {
                items = new List <FoodResult>();
                SearchForRecipe(tag, items, 1.0f);
                cache.Add(tag, items);
            }
            // Create a copy of the results
            int n      = items.Count;
            var result = new FoodResult[n];

            if (n > 0)
            {
                items.CopyTo(result, 0);
            }
            return(result);
        }