Exemplo n.º 1
0
        /// <summary>
        /// Search GeneralDish in DB
        /// </summary>
        /// <param name="searchCount"> Max search results </param>
        /// <param name="searchText"> Search text </param>
        /// <returns></returns>
        public List<GeneralDish> SearchGeneralDish(int searchCount = 20, string searchText = null)
        {
            Stopwatch stop = Stopwatch.StartNew();
            var queryCollection = Query.NE("IsDeleted", true);
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<GeneralDish> basicData =
                                            new MongoEntityRepositoryBase<GeneralDish>(restaurantsDb.DB);

                if (searchText != null)
                {
                    var queryLongDesc = Query.Matches("Dish.Name", BsonRegularExpression.Create(new Regex(searchText, RegexOptions.IgnoreCase)));
                    var queryComName = Query.Matches("Dish.OverrideIngredients[0].ComName.LocalizedList.Value", BsonRegularExpression.Create(new Regex(searchText, RegexOptions.IgnoreCase)));
                    var queryCollectionor = Query.Or(queryLongDesc, queryComName);
                    queryCollection = Query.And(
                        queryCollection,
                        queryCollectionor
                    );

                    log.DebugFormat("SearchGeneralDish query exec={0}, searchText={1}, searchCount={2}.", stop.ElapsedMilliseconds, searchText, searchCount);
                }
                var allGeneralDishes = basicData.FindAs(queryCollection, searchCount);

                //List<Ingredient> ingredientsList = allAllIngredients.OrderBy(i => i.USDA_NDB_No).ToList();
                List<GeneralDish> generalDishList = allGeneralDishes.ToList();

                log.DebugFormat("SearchGeneralDish exec={0}, searchText={1}, searchCount={2}.", stop.ElapsedMilliseconds, searchText, searchCount);
                return generalDishList;
            }
        }
Exemplo n.º 2
0
        public DefaultMenuRestaurant GetDefaultMenuRestaurantByName(string restName)
        {
            log.DebugFormat("[GetDefaultMenuRestaurantByName] restName={0}.", restName);
            var queryCollection = Query.NE("IsDeleted", true);
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<DefaultMenuRestaurant> basicData =
                                            new MongoEntityRepositoryBase<DefaultMenuRestaurant>(restaurantsDb.DB);

                if (restName != null)
                {
                    var queryName = Query.Matches("Name", BsonRegularExpression.Create(new Regex(restName, RegexOptions.IgnoreCase)));
                    queryCollection = Query.And(
                        queryCollection,
                        queryName
                    );

                    log.DebugFormat("GetDefaultMenuRestaurantByName restName={0}.", restName);
                }
                var foundDefaultMenuRests = basicData.FindAs(queryCollection);

                //List<Ingredient> ingredientsList = allAllIngredients.OrderBy(i => i.USDA_NDB_No).ToList();
                List<DefaultMenuRestaurant> defaultMenuRestsList = foundDefaultMenuRests.ToList();
                if (defaultMenuRestsList != null && defaultMenuRestsList.Count > 0) return defaultMenuRestsList[0];
                return null;
            }
        }
Exemplo n.º 3
0
        public static string Download(MongoEntityRepositoryBase<RecipeBasicData> mongoRepository, int recipeIndex)
        {
            string recipeId = recipeIdPrefix + recipeIndex;
            RecipeBasicData existingRecipe = mongoRepository.GetSingle(recipeId);
            if (existingRecipe != null)
                return recipeId;

            string url = string.Format(absUrlTemplate, recipeIndex);
            StringBuilder output = new StringBuilder();
            HtmlWeb webGet = new HtmlWeb();
            webGet.UserAgent = "Wget/1.4.0";
            HtmlDocument htmlDoc = webGet.Load(url);
            //webGet.StatusCode == System.Net.HttpStatusCode.OK
            log.InfoFormat("Fetching html at {0}...", url);
            string html = htmlDoc.DocumentNode.InnerHtml;

            RecipeBasicData recipe = new RecipeBasicData()
            {
                Id = recipeId,
                SourceUrl = url,
                RawHtmlResponse = html,
                RippedAt = DateTime.UtcNow
            };

            mongoRepository.Add(recipe);

            return recipeId;
        }
Exemplo n.º 4
0
 public void DeleteOperatorMap(string id)
 {
     log.InfoFormat("[DeleteOperatorMap] id={0}.", id);
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<OperatorMap> basicData =
                       new MongoEntityRepositoryBase<OperatorMap>(restaurantsDb.DB);
         basicData.Delete(ObjectId.Parse(id));
     }
 }
Exemplo n.º 5
0
 public void UpdateDefaultMenuRestaurant(DefaultMenuRestaurant rest)
 {
     log.DebugFormat("[UpdateDefaultMenuRestaurant] CuisineMap={0}.", rest.Name);
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<DefaultMenuRestaurant> basicData =
                       new MongoEntityRepositoryBase<DefaultMenuRestaurant>(restaurantsDb.DB);
         basicData.Update(rest);
     }
 }
Exemplo n.º 6
0
        public void DownloadTest()
        {
            MongoEntityRepositoryBase<RecipeBasicData> mongoRepository = new MongoEntityRepositoryBase<RecipeBasicData>(m_Testdb);
            string recipeId = Matkonela.Download(mongoRepository, 1434);
            Assert.IsNotNull(recipeId);

            RecipeBasicData fetchedRecipe = mongoRepository.GetSingle(recipeId);
            Assert.AreEqual("http://www.matkonela.co.il/Recipes/Recipe1434.aspx", fetchedRecipe.SourceUrl);
            StringAssert.Contains(fetchedRecipe.RawHtmlResponse, "חזה עוף מוקפץ");
        }
 public static void DeleteUserMealProfile(string id)
 {
     log.DebugFormat("[DeleteUserMealProfile] id={0}.", id);
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<UserMealProfile> basicData =
                       new MongoEntityRepositoryBase<UserMealProfile>(restaurantsDb.DB);
         basicData.Delete(ObjectId.Parse(id));
     }
 }
Exemplo n.º 8
0
        public string AddNewOperatorMap(OperatorMap map)
        {
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<OperatorMap> basicData =
                    new MongoEntityRepositoryBase<OperatorMap>(restaurantsDb.DB);

                basicData.Add(map);
                return map.Id.ToString();
            }
        }
Exemplo n.º 9
0
 public void DeleteRestaurantOsm(string id)
 {
     log.DebugFormat("[DeleteRestaurantOsm] id={0}.", id);
     //using (ImportedRestaurants restaurantsDb = new ImportedRestaurants())
     using (FinlandSwedenOSMRestaurants restaurantsDb = new FinlandSwedenOSMRestaurants())
     {
         MongoEntityRepositoryBase<RestaurantOsm> basicData =
                       new MongoEntityRepositoryBase<RestaurantOsm>(restaurantsDb.DB);
         basicData.Delete(ObjectId.Parse(id));
     }
 }
Exemplo n.º 10
0
//=====================================================================================
        public string AddNewDefaultMenuRestaurant(DefaultMenuRestaurant rest)
        {
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<DefaultMenuRestaurant> basicData =
                    new MongoEntityRepositoryBase<DefaultMenuRestaurant>(restaurantsDb.DB);

                basicData.Add(rest);
                return rest.Id.ToString();
            }
        }
Exemplo n.º 11
0
 public DefaultMenuRestaurant GetDefaultMenuRestaurantById(string id)
 {
     log.DebugFormat("[GetDefaultMenuRestaurantById] id={0}.", id);
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<DefaultMenuRestaurant> basicData =
                       new MongoEntityRepositoryBase<DefaultMenuRestaurant>(restaurantsDb.DB);
         var defaultRest = basicData.GetSingle(ObjectId.Parse(id));
         return defaultRest;
     }
 }
Exemplo n.º 12
0
 public List<SpontaneousUserModel> GetAllUsersData(bool withMenu = true)
 {
     log.DebugFormat("[GetAllUsersData].");
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<SpontaneousUserModel> basicData =
                       new MongoEntityRepositoryBase<SpontaneousUserModel>(restaurantsDb.DB);
         var allRestaurants = basicData.GetAll();
         List<SpontaneousUserModel> selected = allRestaurants.ToList();
         return selected;
     }
 }
Exemplo n.º 13
0
 public static List<UserMealProfile> GetAllUserMealProfiles()
 {
     log.DebugFormat("[GetAllUserMealProfiles].");
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<UserMealProfile> basicData =
                       new MongoEntityRepositoryBase<UserMealProfile>(restaurantsDb.DB);
         var allRestaurants = basicData.GetAll();
         List<UserMealProfile> selected = allRestaurants.ToList();
         return selected;
     }
 }
Exemplo n.º 14
0
        public static string AddUserMealProfileToDB(UserMealProfile userMealProfile)
        {
            log.DebugFormat("[AddUserMealProfileToDB] restaurant={0}.", userMealProfile.ToString());
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<UserMealProfile> basicData =
                              new MongoEntityRepositoryBase<UserMealProfile>(restaurantsDb.DB);

                userMealProfile.CreatedAt = DateTime.UtcNow;
                basicData.Add(userMealProfile);
                return userMealProfile.Id.ToString();
            }
        }
Exemplo n.º 15
0
 private static void RipRecipes(int firstRecipeIndex, int lastRecipeIndex)
 {
     List<string> recipeIds = new List<string>(lastRecipeIndex - firstRecipeIndex);
     CrawledRecipes recipesDb = new CrawledRecipes();
     MongoEntityRepositoryBase<RecipeBasicData> recipeRepo = new MongoEntityRepositoryBase<RecipeBasicData>(recipesDb.DB);
     for (int i = firstRecipeIndex; i <= lastRecipeIndex; i++)
     {
         string recipeId = Matkonela.Download(recipeRepo, i);
         recipeIds.Add(recipeId);
     }
     foreach (string recipeId in recipeIds)
     {
         Matkonela.Extract(recipeRepo, recipeId);
     }
 }
Exemplo n.º 16
0
 public SpontaneousUserModel GetUsersDataById(Guid id)
 {
     //if (!string.IsNullOrEmpty(id))
     if (id != null)
     {
         log.DebugFormat("[GetUsersDataById] Id={0}.", id);
         using (CrawledRecipes recipesDb = new CrawledRecipes())
         {
             MongoEntityRepositoryBase<SpontaneousUserModel> basicData =
                 new MongoEntityRepositoryBase<SpontaneousUserModel>(recipesDb.DB);
             var returnValue = basicData.GetSingle(id);
             return returnValue;
         }
     }
     log.ErrorFormat("[GetUsersDataById] Id is null or empty.");
     return null;
 }
Exemplo n.º 17
0
        //[TestMethod]
        public void AddExtendedDataTest()
        {
            //arrange
            var testdb = new MongoDBForTest().DB;
            MongoEntityRepositoryBase<ProductBasicData> basicData = new MongoEntityRepositoryBase<ProductBasicData>(testdb);
            List<ProductBasicData> products = basicData.GetAll().ToList();

            ProductFetcher extendDataFetcher = new ProductFetcher();
            ProductDataExtendedDataBuilder builder = new ProductDataExtendedDataBuilder();

            //act
            foreach (var product in products)
            {
                string crawledHtml = extendDataFetcher.GetProductExtendedData(product);
                product.ExtendedData = builder.Build(crawledHtml);
            }
        }
Exemplo n.º 18
0
        public List<LoadDBStatus> DoLoad()
        {
            MongoEntityRepositoryBase<ProductBasicData> mongoRepository = new MongoEntityRepositoryBase<ProductBasicData>(m_db);

            List<LoadDBStatus> returnValue = new List<LoadDBStatus>();
            log.Info("[DoLoad] started.");
            foreach (var file in m_filesForLoadingToDB)
            {
                LoadDBStatus loadStat = new LoadDBStatus();

                loadStat.File = file;
                try
                {
                    string html = File.ReadAllText(file);
                    ProductBasicDataFetcher fetcher = new ProductBasicDataFetcher(html);
                    var products = fetcher.FetchProducts();
                    foreach (var item in products)
                    {
                        item.Category = file;
                        var producExistInDB = mongoRepository.GetSingle(item.Barcode);
                        if (producExistInDB == null)
                        {
                            log.DebugFormat("Inserts new product to DB ={0}.", item);
                            mongoRepository.Add(item);

                        }
                        else
                        {
                            log.DebugFormat("Updates {0}.", item);
                            mongoRepository.Update(item);
                        }
                    }

                }
                catch (Exception ex)
                {
                    log.ErrorFormat("[DoLoad] Problem on loading file={0}, exception={1}.", file, ex);
                    loadStat.ErrorException = ex;
                }
                returnValue.Add(loadStat);
            }
            return returnValue;
        }
Exemplo n.º 19
0
        public void AddAndGetTest()
        {
            MongoEntityRepositoryBase<RecipeBasicData> mongoRepository = new MongoEntityRepositoryBase<RecipeBasicData>(m_Testdb);

            //arrange
            RecipeBasicData entity = new RecipeBasicData()
            {
                Id = "RecipeId",
                Name = "RecipeName",
                Description = "Description",
                Directions = "Directions",
                Ingredients = new List<Ingredient>(),
                //Images = Image Object,
                Author = "Author",
                SourceUrl = "SourceUrl",
                RawHtmlResponse = "RawHtmlResponse",
                Labels = new List<string> { "Label1", "Label 2" },
                RippedAt = DateTime.UtcNow
            };
            entity.Ingredients.Add(new Ingredient() { Name = "Ingredient 1", Amount = new IncredientAmount() { Amount = 3.0 / 2 } } );
            entity.Ingredients.Add(new Ingredient() { Name = "Ingredient 2", Amount = new IncredientAmount() { Amount = 2 } } );

            //act
            mongoRepository.Add(entity);
            RecipeBasicData fetchedEntity = mongoRepository.GetSingle(entity.Id);

            //assert
            Assert.IsNotNull(fetchedEntity);
            Assert.AreEqual(fetchedEntity.Id, entity.Id);
            Assert.AreEqual(fetchedEntity.Name, entity.Name);
            Assert.AreEqual(fetchedEntity.Description, entity.Description);
            Assert.AreEqual(fetchedEntity.Directions, entity.Directions);
            Assert.AreEqual(fetchedEntity.Ingredients.First().Name, entity.Ingredients.First().Name);
            Assert.AreEqual(fetchedEntity.Ingredients.Last().Name, entity.Ingredients.Last().Name);
            Assert.AreEqual(fetchedEntity.Images, entity.Images);
            Assert.AreEqual(fetchedEntity.Author, entity.Author);
            Assert.AreEqual(fetchedEntity.SourceUrl, entity.SourceUrl);
            Assert.AreEqual(fetchedEntity.RawHtmlResponse, entity.RawHtmlResponse);
            Assert.AreEqual(fetchedEntity.Labels.First(), entity.Labels.First());
            Assert.AreEqual(fetchedEntity.Labels.Last(), entity.Labels.Last());
            Assert.AreEqual(fetchedEntity.Ingredients.First().Amount.Amount, entity.Ingredients.First().Amount.Amount);
            Assert.AreEqual(fetchedEntity.Ingredients.Last().Name, entity.Ingredients.Last().Name);
        }
Exemplo n.º 20
0
        private static void UpdateExtendedData()
        {
            CrawledProducts productsDb = new CrawledProducts();
            MongoEntityRepositoryBase<ProductBasicData> basicData = new MongoEntityRepositoryBase<ProductBasicData>(productsDb.DB);
            List<ProductBasicData> products = basicData.GetAll().ToList();

            log.InfoFormat("Found {0} products for fetching", products.Count);
            //foreach (var item in allFiles)
            //{
            //string html = File.ReadAllText(item);
            //ProductBasicDataFetcher fetcher = new ProductBasicDataFetcher(html);
            ProductFetcher extendDataFetcher = new ProductFetcher();
            ProductDataExtendedDataBuilder builder = new ProductDataExtendedDataBuilder();

            //act
            //products = fetcher.FetchProducts();
            int count = 0;
            foreach (var product in products)
            {
                try
                {
                    if (product.ExtendedData != null)
                        continue;
                    //product.Category = item;
                    string crawledHtml = extendDataFetcher.GetProductExtendedData(product);
                    product.ExtendedData = builder.Build(crawledHtml);
                    basicData.Update(product);
                    count++;
                    int nutritionTableCount = 0;
                    if (product.ExtendedData != null && product.ExtendedData.NutritionTable != null)
                    {
                        nutritionTableCount = product.ExtendedData.NutritionTable.Count;
                        log.InfoFormat("Product fetched = {0} Product Name = {2} nutritionTableCount = {1}.", count, nutritionTableCount, product.ProductName);
                    }
                }
                catch (Exception ex)
                {
                    log.WarnFormat("Problem on updating extended data product={0}, ex={1}.", product, ex);

                }
                System.Threading.Thread.Sleep(400);
            }
        }
Exemplo n.º 21
0
 public static void Update(RestaurantBasicData restaurant)
 {
     log.DebugFormat("[UpdateRestaurant(RestaurantBasicData)] RestaurantBasicData={0}.", restaurant.ToString());
     restaurant.UpdatedAt = DateTime.UtcNow;
     if (restaurant.Image == null)
     {
         RestaurantBasicData previousRest = GetRestaurantBasic.GetById(restaurant.Id.ToString());
         if (previousRest.Image != null)
         {
             restaurant.Image = previousRest.Image;
         }
     }
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<RestaurantBasicData> basicData =
                         new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB);
         basicData.Update(restaurant);
     }
 }
Exemplo n.º 22
0
        public static UserMealProfile GetLastUserMealProfileByUserId(string id)
        {
            log.DebugFormat("[GetUserMealProfileById] id={0}.", id);
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<UserMealProfile> basicData =
                              new MongoEntityRepositoryBase<UserMealProfile>(restaurantsDb.DB);

                var queryCollection = Query.NE("IsDeleted", true);
                var queryUserId = Query.EQ("UserName", id);
                queryCollection = Query.And(
                    queryCollection,
                    queryUserId
                );
                var allUserMealProfiles = basicData.FindAs(queryCollection, 0).OrderByDescending(r => r.CreatedAt).ToList();
                var userMealProfile = allUserMealProfiles.FirstOrDefault();
                //var userMealProfile = basicData.FindAs(queryCollection, 0).OrderByDescending(r => r.CreatedAt).ToList().FirstOrDefault();
                return userMealProfile;
            }
        }
Exemplo n.º 23
0
        public List<RestaurantBasicData> FindAllRestaurantsWithCusine()
        {
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<RestaurantBasicData> basicData =
                                            new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB);

                var queryCollection = Query.NE("IsDeleted", true);
                var queryCuisine = Query.NE("Cuisines", BsonValue.Create(BsonNull.Value));
                queryCollection = Query.And(
                    queryCollection,
                    queryCuisine
                );

                var allRests = basicData.FindAs(queryCollection, 0).OrderBy(r => r.Name).Reverse();
                List<RestaurantBasicData> restaurantsList = allRests.ToList();
                int restsCount = restaurantsList != null ? restaurantsList.Count : 0;
                log.InfoFormat("[FindAllRestauantsWithCusine] count of restaurants with cuisine=[0].", restsCount);
                return restaurantsList;
            }
        }
Exemplo n.º 24
0
 public string AddRestaurantsCompareListToImportedDB(RestaurantsCompareList compareList)
 {
     try
     {
         compareList.CompareDate = DateTime.UtcNow;
         log.InfoFormat("[AddRestaurantsCompareListToImportedDB] compareList.CompareDate={0}, compareList.CompareSource={1}, compareList.Count={2}, compareList.Id={3}.", compareList.CompareDate, compareList.CompareSource, compareList.CompareList.Count, compareList.Id.ToString());
         //using (ImportedRestaurants restaurantsDb = new ImportedRestaurants())
         using (FinlandSwedenOSMRestaurants restaurantsDb = new FinlandSwedenOSMRestaurants())
         {
             MongoEntityRepositoryBase<RestaurantsCompareList> basicData =
                             new MongoEntityRepositoryBase<RestaurantsCompareList>(restaurantsDb.DB);
             basicData.Add(compareList);
             return compareList.Id.ToString();
         }
     }
     catch (Exception e)
     {
         log.ErrorFormat("[AddRestaurantsCompareListToImportedDB] Exception={0}.", e);
         return null;
     }
 }
Exemplo n.º 25
0
 public string AddRestToImportedDB(RestaurantOsm rest)
 {
     try
     {
         log.InfoFormat("[AddRestToImportedDB] rest.Name={0}, rest.Name={0}, rest.NodeReference.id={1}.", rest.Name, rest.NodeReference.id);
         rest.CreatedAt = DateTime.UtcNow;
         //using (ImportedRestaurants restaurantsDb = new ImportedRestaurants())
         using (FinlandSwedenOSMRestaurants restaurantsDb = new FinlandSwedenOSMRestaurants())
         {
             MongoEntityRepositoryBase<RestaurantOsm> basicData =
                             new MongoEntityRepositoryBase<RestaurantOsm>(restaurantsDb.DB);
             basicData.Add(rest);
             return rest.Id.ToString();
         }
     }
     catch (Exception e)
     {
         log.ErrorFormat("[AddRestToImportedDB] Exception={0}.", e);
         return null;
     }
 }
Exemplo n.º 26
0
        public void ExtendedData_PropertyTest()
        {
            //arrange
            var extendedData =  new ProductExtendedData();
            extendedData.AlergensWarnings = "AlergensWarnings";
            List<Nutrition> nutr = new List<Nutrition>();
            nutr.Add(new Nutrition() { Name = "Calcium", Value = "Calcium" });
            nutr.Add(new Nutrition() { Name = "Carbohydrate", Value = "carb" });
            //extendedData.Calcium = "Calcium";
            //extendedData.Carbohydrate = "carb";

            MongoEntityRepositoryBase<ProductBasicData> mongoRepository = new MongoEntityRepositoryBase<ProductBasicData>(m_Testdb);
            ProductBasicData entity = new ProductBasicData()
            {
                ProductId = "1111",
                EffectivePrice = "10",
                Barcode = "121211",
                Description = "SomeDescription",
                ExtendedData = extendedData,
                //Image = "urlToImage",
                ImageSource = "http:\\someDomain.dan",
                inb = "inb",
                iq = "iq",
                pbcatid = "pbcatid",
                ProductName = "productName",
                qty = "2"
            };
            mongoRepository.Add(entity);

            //act
            var fetchedEntity = mongoRepository.GetSingle(entity.Barcode);
            var fetchedExtendedData = fetchedEntity.ExtendedData;
            //assert
            Assert.IsNotNull(fetchedExtendedData);
            Assert.AreEqual(fetchedExtendedData.AlergensWarnings, extendedData.AlergensWarnings);
            Assert.AreEqual(fetchedExtendedData.NutritionTable.First(c=> c.Name == "Calcium").Value , extendedData.NutritionTable.First(c=> c.Name == "Calcium").Value);
            Assert.AreEqual(fetchedExtendedData.NutritionTable.First(c => c.Name == "Carbohydrate").Value, extendedData.NutritionTable.First(c => c.Name == "Carbohydrate").Value);
        }
Exemplo n.º 27
0
        public void AddAndGetTest()
        {
            MongoEntityRepositoryBase<ProductBasicData> mongoRepository = new MongoEntityRepositoryBase<ProductBasicData>(m_Testdb);
            //arrange
            ProductBasicData entity = new ProductBasicData()
            {
                ProductId = "1111",
                EffectivePrice = "10",
                Barcode = "121211",
                Description = "SomeDescription",
                ExtendedData = new ProductExtendedData(),
                //Image = "urlToImage",
                ImageSource = "http:\\someDomain.dan",
                inb = "inb",
                iq = "iq",
                pbcatid = "pbcatid",
                ProductName = "productName",
                qty = "2"
            };

            //act
            mongoRepository.Add(entity);
            var fetchedEntity = mongoRepository.GetSingle(entity.Barcode);

            //assert
            Assert.IsNotNull(fetchedEntity);
            Assert.AreEqual(fetchedEntity.Barcode, entity.Barcode);
            Assert.AreEqual(fetchedEntity.Description, entity.Description);
            Assert.AreEqual(fetchedEntity.EffectivePrice, entity.EffectivePrice);
            Assert.AreEqual(fetchedEntity.Image, entity.Image);
            Assert.AreEqual(fetchedEntity.ImageSource, entity.ImageSource);
            Assert.AreEqual(fetchedEntity.inb, entity.inb);
            Assert.AreEqual(fetchedEntity.iq, entity.iq);
            Assert.AreEqual(fetchedEntity.pbcatid, entity.pbcatid);
            Assert.AreEqual(fetchedEntity.ProductId, entity.ProductId);
            Assert.AreEqual(fetchedEntity.ProductName, entity.ProductName);
            Assert.AreEqual(fetchedEntity.qty, entity.qty);
        }
Exemplo n.º 28
0
        public List<RestaurantBasicData> FindAllRestaurantsByOperator(string operatorName, bool emptyMenu=false)
        {
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<RestaurantBasicData> basicData =
                                            new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB);

                var queryCollection = Query.NE("IsDeleted", true);
                var queryName = Query.Matches("Name", BsonRegularExpression.Create(new Regex(operatorName, RegexOptions.IgnoreCase)));
                //var queryAddres = Query.Matches("Address.City", BsonRegularExpression.Create(new Regex(city, RegexOptions.IgnoreCase)));
                //var queryDescription = Query.Matches("Description", BsonRegularExpression.Create(new Regex(city, RegexOptions.IgnoreCase)));

                IMongoQuery queryMenu = Query.Null;
                if (emptyMenu) queryMenu = Query.NotExists("Menu.MenuParts.3");

                if (queryMenu == null)
                {
                    queryCollection = Query.And(
                        queryCollection,
                        queryName
                    );
                }
                else
                {
                    queryCollection = Query.And(
                           queryCollection,
                           queryName,
                           queryMenu
                       );
                }

                var allRests = basicData.FindAs(queryCollection, 0).OrderBy(r => r.Name).Reverse();
                List<RestaurantBasicData> restaurantsList = allRests.ToList();
                int restsCount = restaurantsList != null ? restaurantsList.Count : 0;
                log.InfoFormat("[FindAllRestaurantsByOperator] count={0}.", restsCount);
                return restaurantsList;
            }
        }
Exemplo n.º 29
0
        public static void Extract(MongoEntityRepositoryBase<RecipeBasicData> mongoRepository, string recipeId)
        {
            RecipeBasicData recipe = mongoRepository.GetSingle(recipeId);
            if (recipe == null || recipe.RawHtmlResponse == null)
                return;

            try
            {
                HtmlDocument htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(recipe.RawHtmlResponse);

                HtmlNode titleNode = htmlDoc.DocumentNode.SelectSingleNode("//span[@class='articletitle']");
                recipe.Name = titleNode.InnerText;

                HtmlNode descriptionNode = htmlDoc.DocumentNode.SelectSingleNode("//meta[@name='description']/@content");
                recipe.Description = descriptionNode.GetAttributeValue("content", null);

                HtmlNode autherNode = htmlDoc.DocumentNode.SelectSingleNode("//a[@id[contains(., 'lnkAuthor')]]");
                recipe.Author = autherNode.InnerText;

                HtmlNode directionsNode = htmlDoc.DocumentNode.SelectSingleNode("//span[@class='ArticleContent' and @id[contains(., 'lblArticle')]]");
                recipe.Directions = directionsNode.InnerHtml;

                HtmlNode ingredientsNode = htmlDoc.DocumentNode.SelectSingleNode("//span[@class='ArticleContent' and @id[contains(., 'lblIngredients')]]");
                recipe.Ingredients = ExtractIngredients(ingredientsNode);

                recipe.NutritionFacts = SumIngredientsNutritionFacts(recipe.Ingredients);

                HtmlNodeCollection tagsNodes = htmlDoc.DocumentNode.SelectNodes("//div[@id[contains(., 'TagsDiv')]]/a");
                recipe.Labels = ExtractLabels(tagsNodes);

                mongoRepository.Update(recipe);
            }
            catch (Exception e)
            {
                log.ErrorFormat("Failed to extract recipe {0}. Failed to load the document. {1}", recipeId, e);
            }
        }
Exemplo n.º 30
0
        public void ExtractTest()
        {
            string recipeId = "Matkonela_1434";

            MongoEntityRepositoryBase<RecipeBasicData> mongoRepository = new MongoEntityRepositoryBase<RecipeBasicData>(m_Testdb);
            Matkonela.Extract(mongoRepository, recipeId);

            RecipeBasicData fetchedRecipe = mongoRepository.GetSingle(recipeId);
            Assert.AreEqual("חזה עוף מוקפץ בצ'ילי ואגוזי קשיו", fetchedRecipe.Name);

            CollectionAssert.AllItemsAreNotNull(fetchedRecipe.Ingredients);
            Ingredient firstIngredient = fetchedRecipe.Ingredients[0];
            Assert.AreEqual("חזה עוף חתוך לקוביות", firstIngredient.Name);
            Assert.AreEqual(800, firstIngredient.Amount.Amount);
            Assert.AreEqual("גרם", firstIngredient.Amount.MeasureUnit);

            Ingredient secondIngredient = fetchedRecipe.Ingredients[1];
            Assert.AreEqual("91", secondIngredient.ProductId);

            Ingredient tenthIngredient = fetchedRecipe.Ingredients[9];
            Assert.AreEqual("קשיו קלוי ענק", tenthIngredient.ProductName);
            Assert.AreEqual(33, tenthIngredient.NutritionFacts.TotalCarbohydrate);
        }