コード例 #1
0
ファイル: ApiTests.cs プロジェクト: jame2408/DDDTW.CoffeeShop
        private async Task <IProductRepository> GetAndRegisterProductRepository(IServiceProvider provider)
        {
            for (int i = 0; i < 10; i++)
            {
                this.products.Add(new Product(new ProductId(i), "name", "desc",
                                              new ProductPrice(i + 10), ProductStatus.Active, DateTimeOffset.Now));
            }

            var saveTasks = new List <Task>();

            this.mongoRepository = (MongoRepositoryBase <Product, ProductId>)provider.GetService <IRepository <Product, ProductId> >();
            var repository = new ProductRepository(this.mongoRepository);

            foreach (var product in this.products)
            {
                saveTasks.Add(repository.Save(product));
            }

            await Task.WhenAll(saveTasks);

            return(repository);
        }
コード例 #2
0
ファイル: Tests.cs プロジェクト: ferhatcandas/TStack.MongoDB
        public void Insert_single_and_multiple_with_generic_repository_and_rule_success()
        {
            var genericPerson = new MongoRepositoryBase <Person, TestConnection, PersonMapper>();

            Person person = new Person("ferhat", "candas", DateTime.Now.AddYears(-15), 2000.52);

            List <PersonAddress> personAddresses = new List <PersonAddress>()
            {
                new PersonAddress("Fatih mah", "a", "Istanbul"),
                new PersonAddress("Kıvanc mah", "b", "Izmir"),
                new PersonAddress("Kemaliye mah", "c", "Trabzon"),
            };


            var personDetail = new PersonDetail("*****@*****.**", "905379106194");

            person.Addresses = personAddresses;

            person.PersonDetail = personDetail;

            genericPerson.Insert(person, x => x.Name == "test" || x.Name == "test2");

            var personData = genericPerson.First(x => x.Id == person.Id, x => x.Name == "test" || x.Name == "test2");

            personData.Name.Should().Be(person.Name);
            personData.Surname.Should().Be(person.Surname);
            personData.BirthDate.ToString("dd MM yyyy HH:mm:ss").Should().Be(person.BirthDate.ToString("dd MM yyyy HH:mm:ss"));
            personData.Salary.Should().Be(person.Salary);
            personData.Id.Should().Be(person.PersonDetail.PersonId);
            personData.PersonDetail.PersonId.Should().Be(person.PersonDetail.PersonId);
            personData.PersonDetail.Phone.Should().Be(person.PersonDetail.Phone);
            personData.PersonDetail.Email.Should().Be(person.PersonDetail.Email);
            personData.Addresses.ForEach(x =>
            {
                x.PersonId.Should().Be(person.Id);
            });
        }
コード例 #3
0
        static void GetLunchPost(Restaurant restaurant)
        {
            var repository = new MongoRepositoryBase <LunchDeal>("mongodb://localhost/LunchBox", "LunchDeals");

//            IWebDriver browser = new ChromeDriver("C:\\chromeDriver\\");
            try
            {
                //Firefox's proxy driver executable is in a folder already
                //  on the host system's PATH environment variable.
                var link = restaurant.link.Split(new[] { ".com" }, StringSplitOptions.None)[1];
                link = "https://m.facebook.com" + link + "posts/";
                browser.Navigate().GoToUrl(link);

                var posts = browser.FindElements(By.CssSelector("#pages_msite_body_contents .story_body_container"));

                foreach (var post in posts)
                {
                    try
                    {
                        var moreButton = post.FindElement(By.LinkText("More"));
                        moreButton.Click();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    IWebElement time = null;
                    IWebElement withoutMoreButton = null;
                    IWebElement imagelocation     = null;
                    IWebElement image             = null;

                    try
                    {
                        time = post.FindElement(By.CssSelector("[data-sigil=\"m-feed-voice-subtitle\"] abbr"));
                        withoutMoreButton = post.FindElement(By.CssSelector("[data-ad-preview=\"message\"] span"));
                        imagelocation     = post.FindElement(By.CssSelector("i.img"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    ReadOnlyCollection <IWebElement> withMoreButtonVisible   = null;
                    ReadOnlyCollection <IWebElement> withMoreButtonInvisible = null;
                    ReadOnlyCollection <IWebElement> dealImage = null;
                    try
                    {
                        withMoreButtonVisible = post.FindElements(By.CssSelector(
                                                                      "#pages_msite_body_contents .story_body_container [data-ad-preview=\"message\"] span[data-sigil=\"expose\"] > p"));
//                        withMoreButtonInvisible = post.FindElements(By.CssSelector(
//                            "#pages_msite_body_contents .story_body_container [data-ad-preview=\"message\"] span[data-sigil=\"expose\"] div.text_exposed_show p"));

                        dealImage = post.FindElements(By.CssSelector(".userContentWrapper .uiScaledImageContainer img"));
                    }
                    catch (Exception ex)
                    {
                    }



                    try
                    {
                        if (Regex.IsMatch(time.Text, @"^\d+"))
                        {
                            if (withoutMoreButton.Text.ToLower().Contains("pietus") ||
                                withoutMoreButton.Text.ToLower().Contains("pietūs") ||
                                withoutMoreButton.Text.ToLower().Contains("pietū") ||
                                withoutMoreButton.Text.ToLower().Contains("dienos") ||
                                withoutMoreButton.Text.ToLower().Contains("pietu") ||
                                withoutMoreButton.Text.ToLower().Contains("pietums") ||
                                withoutMoreButton.Text.ToLower().Contains("sriuba"))
                            {
                                string text = withoutMoreButton.Text;

                                if (withMoreButtonVisible != null)
                                {
                                    foreach (var p in withMoreButtonVisible)
                                    {
                                        text = text + p.Text + Environment.NewLine;
                                    }
                                }

                                var deal = new LunchDeal();
                                deal.Description = text;

                                deal.RestaurantId = restaurant.id;
                                deal.id           = restaurant.id;
                                deal.time         = time.Text;
                                deal.Restaurant   = restaurant;

                                try
                                {
                                    post.Click();
                                    image         = browser.FindElement(By.CssSelector("div[data-full-size-href]"));
                                    deal.ImageUrl = image.GetAttribute("data-full-size-href");
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }

                                try
                                {
                                    repository.UpdateOne(deal);
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                    repository.Insert(deal);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            //            browser.Close();
            //            browser.Dispose();

            Console.WriteLine("Done " + restaurant.name);
//            browser.Close();
//            browser.Dispose();
        }
コード例 #4
0
        //        private IWebDriver browser;
        //        FirefoxProfile profile = new FirefoxProfile();
        //        profile.setPreference("javascript.enabled", false);
        //        IWebDriver browser = new FirefoxDriver(profile);
        //        private static readonly IWebDriver browser = new ChromeDriver("C:\\chromeDriver\\");
        //        private static readonly IWebDriver browser = new ChromeDriver("C:\\chromeDriver\\");

        static void Main(string[] args)
        {
            var repository = new MongoRepositoryBase <Restaurant>("mongodb://localhost/LunchBox", "RestaurantsRaw");

            var builder     = Builders <Restaurant> .Filter;
            var filter      = builder.Exists("id");
            var restourants = repository.GetMany(filter);

            try
            {
                if (restourants.Count == 0)
                {
                    Search("restoranas");
                    Search("kavine");
                    Search("uzeiga");
                    Search("valgykla");
                    Search("picerija");
                    Search("baras");
                    Search("pubas");
                    Search("republicbaras");
                    Search("šašlykinė");
                    Search("užeiga");
                    Search("Coffee");
                    Search("Sotus.vilkas.kaunas");
                    Search("restourant");
                    Search("fast food");
                    Search("fast food restourant");
                    Search("virtuve");
                    Search("virtuvė");
                    Search("grill");
                    Search("Cofee");
                }
                else
                {
                    var restourantTocheck = restourants.First();

                    if (restourants.Count == 0 || restourantTocheck.CreatedAt < DateTime.Now.AddHours(-12))
                    {
                        Search("restoranas");
                        Search("restourant");
                        Search("kavine");
                        Search("uzeiga");
                        Search("valgykla");
                        Search("picerija");
                        Search("baras");
                        Search("pubas");
                        Search("republicbaras");
                        Search("šašlykinė");
                        Search("užeiga");
                        Search("Coffee");
                        Search("Cofee");
                        Search("Sotus.vilkas.kaunas");
                        Search("fast food");
                        Search("fast food restourant");
                        Search("virtuve");
                        Search("virtuvė");
                        Search("grill");
                    }
                }
            }
            catch (Exception ex)
            {
            }

            restourants = repository.GetMany(filter);

            var restourantsToParse = new List <Restaurant>();

            foreach (Restaurant restourant in restourants)
            {
                try
                {
                    if (restourant.location.country.ToLower().Equals("lithuania"))
                    {
                        restourantsToParse.Add(restourant);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            int count = 0;

//            Parallel.ForEach(restourantsToParse, new ParallelOptions { MaxDegreeOfParallelism = 50 }, (restourant) =>
//            {
//                try
//                {
//                    GetLunchPost(restourant);
//                }
//                catch (Exception e)
//                {
//                    Console.WriteLine(e);
//                }
//
//                Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!DONE POPULATING !!!!!!!!!!!!!!");
//            });

//
            foreach (var restourant in restourantsToParse)
            {
                try
                {
                    GetLunchPost(restourant);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                count = count + 1;
                Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!DONE POPULATING !!!!!!!!!!!!!!  COUNT " + count + " From " + restourantsToParse.Count);
            }

            Console.WriteLine("Done");

            browser.Close();
            browser.Dispose();

            Environment.Exit(0);
        }
コード例 #5
0
        static void Search(string query)
        {
            try
            {
                var tokken =
                    "EAAFsGfQAdhoBAIf8OpfB1RTFFvORIXHEQxqp16Oo9BciBiN5iXnwQqauDZCg2cZBUSpc2dXZCiBTfVnoKlynI4QgCHrHvlk46rWhDtk8pk2VZBFn5JhmQ9iPvoCXa4F91ZAWXVFZCG8ReZCZAbYZAD9vsjiMCVaobGZB9l1JldQZCz7CA2XyvgZAK3CJSIBFgjmX3FqGhCFZABr4TkgZDZD";

                var repository = new MongoRepositoryBase <Restaurant>("mongodb://localhost/LunchBox", "RestaurantsRaw");
                var path       =
                    "https://graph.facebook.com/v3.1/search?fields=about,app_links,checkins,cover,description,engagement,hours,id,is_permanently_closed,is_verified,link,location,name,overall_star_rating,parking,payment_options,phone,price_range,rating_count,single_line_address,website,picture{height,url,width},photos&q=" +
                    query + "&type=place&limit=999999&access_token=" + tokken;
                bool searchNext = true;
                while (searchNext)
                {
                    var result = GetProductAsync(path).Result;


                    foreach (var restaurant in result.data)
                    {
                        try
                        {
                            try
                            {
                                repository.UpdateOne(restaurant);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                restaurant.location.PointLocation = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                                    new GeoJson2DGeographicCoordinates(restaurant.location.longitude,
                                                                       restaurant.location.latitude));
                                repository.Insert(restaurant);
                            }


                            Console.WriteLine("INSERTED: " + restaurant.name);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("FAILED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: " + restaurant.name);
                            Console.WriteLine(ex.Message);
                        }
                    }

                    try
                    {
                        path = result.paging.next;
                        Console.WriteLine("Search added for " + path);

                        if (result.paging.next.Length > 0)
                        {
                        }
                        else
                        {
                            searchNext = false;
                        }
                    }
                    catch (Exception e)
                    {
                        searchNext = false;
                    }
                }

                Console.WriteLine("Done ");
            }
            catch (Exception ex)
            {
            }
        }