Exemplo n.º 1
0
        private static async Task InsertSeedData(NewsFeedContext context)
        {
            if (context.NewsFeedProviders.Any())
            {
                return;
            }

            List <NewsFeedProvider> lstNewsFeedProviders = new List <NewsFeedProvider>()
            {
                new NewsFeedProvider()
                {
                    Name       = "ABC News",
                    RssFeedURL = "https://abcnews.go.com/abcnews/topstories"
                },
                new NewsFeedProvider()
                {
                    Name       = "BBC News",
                    RssFeedURL = "http://feeds.bbci.co.uk/news/world/rss.xml"
                },
                new NewsFeedProvider()
                {
                    Name       = "CNN",
                    RssFeedURL = "http://rss.cnn.com/rss/edition.rss"
                },
                new NewsFeedProvider()
                {
                    Name       = "Times of India",
                    RssFeedURL = "https://timesofindia.indiatimes.com/rssfeedstopstories.cms"
                },
            };

            context.AddRange(lstNewsFeedProviders);
            await context.SaveChangesAsync();
        }
        private void SetUpClient()
        {
            var builder = new WebHostBuilder()
                          .UseStartup <Startup>()
                          .ConfigureServices(services =>
            {
                var context = new NewsFeedContext(new DbContextOptionsBuilder <NewsFeedContext>()
                                                  .UseSqlite("DataSource=:memory:")
                                                  .EnableSensitiveDataLogging()
                                                  .Options);

                services.RemoveAll(typeof(NewsFeedContext));
                services.AddSingleton(context);

                context.Database.OpenConnection();
                context.Database.EnsureCreated();

                context.SaveChanges();

                // Clear local context cache
                foreach (var entity in context.ChangeTracker.Entries().ToList())
                {
                    entity.State = EntityState.Detached;
                }
            });

            _server = new TestServer(builder);

            Client = _server.CreateClient();
        }
Exemplo n.º 3
0
        internal object getNewsFeeds(bool?onlySubscribed, int?providerId)
        {
            WebClient wclient = new WebClient();

            NewsFeedContext         db           = new NewsFeedContext();
            List <NewsFeedProvider> lstProviders = new List <NewsFeedProvider>();

            if (providerId > 0)
            {
                //if onlySubscribed and provider id both present, provider id will be given preference
                lstProviders = db.NewsFeedProviders.Where(prov => prov.Id == providerId).ToList();
            }
            else if (onlySubscribed == true)
            {
                lstProviders = db.NewsFeedProviders.Where(prov => prov.isSubscribed == true).ToList();
            }
            else
            {
                lstProviders = db.NewsFeedProviders.ToList();
            }

            List <NewsItem> allNewsItems = new List <NewsItem>();

            foreach (var provider in lstProviders)
            {
                string RSSData = wclient.DownloadString(provider.RssFeedURL);

                XDocument  xml   = XDocument.Parse(RSSData);
                XNamespace media = XNamespace.Get("http://search.yahoo.com/mrss/");

                try
                {
                    var RSSFeedData = (from x in xml.Descendants("item")
                                       select new NewsItem
                    {
                        ThumbnailURL = x.Element(media + "thumbnail") != null ? x.Element(media + "thumbnail").Attribute("url").Value : "http://via.placeholder.com/100x100",
                        Title = ((string)x.Element("title")),
                        Link = ((string)x.Element("link")),
                        Description = ((string)x.Element("description")),
                        PubDate = ((DateTime)x.Element("pubDate")),
                        Category = ((string)x.Element("category")),
                        Provider = provider.Name,
                        ProviderId = provider.Id
                    });
                    allNewsItems.AddRange(RSSFeedData);
                }
                catch (Exception e)
                {
                    //It should notify the developer that some of the rss feeds parsing is failing.

                    // Handeling the specific provider in try catch so that, if our parsing fail for one of the provider
                    // it should not affect the whole endpoint and will continue respond the data of otehr providers
                }
            }
            return(allNewsItems.OrderByDescending(news => news.PubDate));
        }
Exemplo n.º 4
0
        public object Put(int id, bool subscribe)
        {
            NewsFeedContext  db       = new NewsFeedContext();
            NewsFeedProvider provider = db.NewsFeedProviders.Where(prov => prov.Id == id).Single();

            provider.isSubscribed = subscribe;
            db.SaveChanges();

            return(db.NewsFeedProviders);
        }
Exemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, NewsFeedContext newsFeed)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseStatusCodePages();

            //newsFeed.Seed();

            app.UseHttpsRedirection();
            app.UseMvc();
        }
        public static void Initialize(NewsFeedContext context)
        {
            // context.Database.EnsureDeleted();
            context.Database.EnsureCreated();


            //Look for any News.
            if (context.News.Any())
            {
                return;   // DB has been seeded
            }

            var user1 = new UserInfo {
                UserEmail = "*****@*****.**", UserName = "******"
            };

            var students = new News[]
            {
                new News {
                    Message = "I hope you will have nice experience. All the best :)", DateCreated = DateTime.Now, UserInfo = user1
                },
                new News {
                    Message = "Identity server with External Google Identity System using OIDC.", DateCreated = DateTime.Now, UserInfo = user1
                },
                new News {
                    Message = "Login before posting news items and mark your identity in the News Feed world.", DateCreated = DateTime.Now, UserInfo = user1
                },
                new News {
                    Message = "These posts are in datecreated order.!!", DateCreated = DateTime.Now, UserInfo = user1
                },
                new News {
                    Message = "This is message from system administrator. Click my name below and send me an email.", DateCreated = DateTime.Now, UserInfo = user1
                },
                new News {
                    Message = "Welcome to the Judges!!", DateCreated = DateTime.Now, UserInfo = user1
                },
            };

            foreach (News s in students)
            {
                context.News.Add(s);
            }
            context.SaveChanges();
        }
Exemplo n.º 7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, NewsFeedContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            context.Database.Migrate();

            app.UseCors("AllowAngularLocalHost");

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Exemplo n.º 8
0
 public NewsFeedController(NewsFeedContext context)
 {
     this._context = context;
 }
Exemplo n.º 9
0
 public GenericRepository(NewsFeedContext _context)
 {
     this._context = _context;
     table         = _context.Set <T>();
 }
Exemplo n.º 10
0
 public GenericRepository()
 {
     this._context = new NewsFeedContext();
     table         = _context.Set <T>();
 }
Exemplo n.º 11
0
 public CategoryRepository(NewsFeedContext context)
 {
     _context = context;
 }
Exemplo n.º 12
0
 public GenericRepository(NewsFeedContext context, ILoggerFactory loggerFactory)
 {
     _context       = context;
     _loggerFactory = loggerFactory;
 }
Exemplo n.º 13
0
 public CommentsRepository()
 {
     this._context = new NewsFeedContext();
 }
Exemplo n.º 14
0
 public UserService(NewsFeedContext context) : base(context)
 {
 }
 public NewsFeedService(NewsFeedContext newsFeedContext, IMemoryCache memoryCache)
 {
     _newsFeedContext = newsFeedContext;
     _memoryCache     = memoryCache;
 }
Exemplo n.º 16
0
 public NewsFeedRepository(NewsFeedContext context)
 {
     this.context = context;
 }
Exemplo n.º 17
0
        public object Get()
        {
            NewsFeedContext db = new NewsFeedContext();

            return(db.NewsFeedProviders);
        }
Exemplo n.º 18
0
 public FeedService(NewsFeedContext context) : base(context)
 {
 }
Exemplo n.º 19
0
 public BaseService(NewsFeedContext context)
 {
     _context = context;
 }
Exemplo n.º 20
0
 public PostService(NewsFeedContext context) : base(context)
 {
 }