Ejemplo n.º 1
0
        private static void ImportVenus(string section, string[] categories, string keyword)
        {
            using (var dbContext = new DistrictsInTownModelContainer())
            {
                int chunkSize = 50;
                int offset = 0;

                ForesquareVenueResult result;
                do
                {
                    result = ExploreVenues(offset, chunkSize, "Berlin, DE", section, categories, keyword).Result;
                    offset += chunkSize;

                    WriteVenues(result.Venues);

                    foreach (var venue in result.Venues)
                        AddVenueToDatabase(dbContext, venue);

                    try
                    {
                        dbContext.SaveChanges();
                    }
                    catch (Exception error)
                    {

                    }

                    Console.WriteLine("Total results: {0}", result.TotalResults);
                }
                while (offset < result.TotalResults);
            }
        }
        /// <summary>
        ///     Gets a collection with object of type <see cref="Place" /> filtered by keywords.
        /// </summary>
        /// <param name="keyword">A list of keywords to narrow the result.</param>
        /// <returns>A collection of <see cref="Place" /> items.</returns>
        public IEnumerable<Place> Get(IList<string> keyword)
        {
            if (!keyword.Any())
            {
                return Enumerable.Empty<Place>();
            }

            using (var container = new DistrictsInTownModelContainer())
            {
                return ToPlaceList(container.Places.Where(p => keyword.Contains(p.Keyword)));
            }
        }
Ejemplo n.º 3
0
        private static void AddVenueToDatabase(DistrictsInTownModelContainer dbContext, ForesquareVenue venue)
        {
            if (String.IsNullOrEmpty(venue.ZipCode))
                return;

            dbContext.Places.Add(new Places
            {
                Location = DbGeography.FromText(String.Format("POINT ({0} {1})", venue.Longitude, venue.Latitude)),
                Keyword = venue.Keyword,
                Score = venue.Score,
                Source = venue.Source,
                Zip = venue.ZipCode
            });
        }
Ejemplo n.º 4
0
        private void AddArticlesToDB(DistrictsInTownModelContainer dbContext, KeyValuePair<string, List<News>> district, decimal min, decimal max)
        {
            dbContext.Places.RemoveRange(dbContext.Places.Where(p => p.Source.StartsWith("ipool_")));
            foreach (var news in district.Value)
            {

                dbContext.Places.Add(new Places
                {
                    Location = DbGeography.FromText(district.Key),
                    Keyword = "popular",
                    Score = (double) news.GetScore(min, max),
                    Source = "ipool_" + news.ID,
                    Zip = Program.PLZ.ContainsKey(district.Key) ? Program.PLZ[district.Key] : "10409"
                });
            }
        }
        /// <summary>
        ///     Saves <see cref="Place" /> items with new zip codes.
        /// </summary>
        /// <param name="places">The <see cref="Place" /> items that should be saved.</param>
        public void This(IEnumerable<Place> places)
        {
            using (var container = new DistrictsInTownModelContainer())
            {
                foreach (var place in places)
                {
                    var placeToUpdate = container.Places.SingleOrDefault(p => p.Source == place.Source);

                    if (placeToUpdate == null)
                    {
                        continue;
                    }

                    placeToUpdate.Zip = place.ZipCode;
                }

                container.SaveChanges();
            }
        }
Ejemplo n.º 6
0
        public void Save(Dictionary<string, List<News>> news)
        {
            decimal min = news.Min(n => n.Value.Min(m => m.RawScore));
            decimal max = news.Max(n => n.Value.Max(m => m.RawScore));

            using (var dbContext = new DistrictsInTownModelContainer())
            {
                foreach (var district in news)
                    AddArticlesToDB(dbContext, district, min, max);

                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception error)
                {
                    Console.WriteLine(error.StackTrace);
                }

                Console.WriteLine("Total results: {0}", news.Sum(n => n.Value.Count));
            }
        }
        /// <summary>
        ///     Gets a collection with all available objects of type <see cref="Place" />.
        /// </summary>
        /// <returns>A collection of <see cref="Place" /> items.</returns>
        public IEnumerable<Place> Get()
        {
            var container = new DistrictsInTownModelContainer();

            return ToPlaceList(container.Places);
        }