コード例 #1
0
ファイル: Program.cs プロジェクト: bambidarra/FeedReader
        static void Main(string[] args)
        {
            DB = DataBase.GetInstance();

            while (true)
            {
                foreach (var f in DB.Feeds.Where(i => i.LastChecked.AddMinutes(15) < DateTime.Now).AsParallel())
                {
                    try
                    {
                        foreach (var fi in FeedParser.Parse(new Uri(f.Url)))
                        {
                            try
                            {
                                FeedReader.Models.FeedItem nFeedItem = new FeedReader.Models.FeedItem
                                {
                                    FeedID = f.ID,
                                    Created = fi.PublicationDate,
                                    Description = PrepareString(fi.Description),
                                    Title = PrepareString(fi.Title),
                                    Url = fi.Link.ToString()
                                };

                                if (!DB.FeedItems.Any(i => i.Url == nFeedItem.Url && i.FeedID == f.ID))
                                {
                                    DB.FeedItems.InsertOnSubmit(nFeedItem);
                                    Console.WriteLine("{0}: {1}", f.Title, nFeedItem.Title);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Error occurred inserting {0}.", fi.Title.TrimEnd('.'));
                                Console.WriteLine(e);
                            }
                        }

                        f.LastChecked = DateTime.Now;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to download or parse {0}.", f.Title);
                        Console.WriteLine(e);
                    }
                }

                try
                {
                    DB.SubmitChanges();
                    Thread.Sleep(30 * 1000);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error inserting feeds:");
                    Console.WriteLine(e.Message);
                    Thread.Sleep(10 * 1000);
                }

                DB.ClearInternalCache();
            }
        }
コード例 #2
0
ファイル: User.cs プロジェクト: bambidarra/FeedReader
        public static bool LogIn()
        {
            if (DB == null) DB = DataBase.GetInstance();
            if (!CurrentController.Session.AsEnumerable().Any(i => i.Key == "UserInfo" && i.Value.GetType() == typeof(Models.User))) return false;
            Models.User userInfo = (Models.User)CurrentController.Session["UserInfo"];

            Models.User user = DB.Users.FirstOrDefault(u => u.Email == userInfo.Email);
            if (user == null || user.PasswordHash != userInfo.PasswordHash) return IsLoggedIn = false;

            CurrentController.Session["UserInfo"] = Info = user;
            return true;
        }
コード例 #3
0
 public ActionResult Open(int? id)
 {
     if (!id.HasValue || !UserInfo.LogIn()) return RedirectToAction("Login", "User");
     this.DB = DataBase.GetInstance();
     this.DB.ClearInternalCache();
     FeedItem feedItem = this.DB.FeedItems.FirstOrDefault(i => i.ID == id.Value);
     if (feedItem == null) return RedirectToAction("Login", "User");
     UserFeedItem ufi = UserInfo.Info.UserFeedItems.FirstOrDefault(i => i.FeedItemID == id.Value);
     if (ufi != null) ufi.Read = true;
     else this.DB.UserFeedItems.InsertOnSubmit(new UserFeedItem { FeedItemID = id.Value, UserID = UserInfo.Info.ID, Read = true });
     this.DB.SubmitChanges();
     return Redirect(feedItem.Url);
 }
コード例 #4
0
        public ActionResult RegisterSubmit(string email, string password, string passwordAgain)
        {
            List<string> errors;
            if (Validator.IsValidUser(email, password, passwordAgain, out errors))
            {
                DB = DataBase.GetInstance();
                DB.Users.InsertOnSubmit(new Models.User { Email = email, PasswordHash = Classes.UserInfo.HashPassword(password), Registered = DateTime.Now });
                DB.SubmitChanges();
                UserInfo.LogIn(email, password);
            }

            return RedirectToAction("Index", "Home");
        }
コード例 #5
0
        public ActionResult View(int? page)
        {
            if (!UserInfo.LogIn()) return RedirectToAction("Login", "User");
            if (page <= 0) page = null;
            this.DB = DataBase.GetInstance();
            this.DB.ClearInternalCache();

            var q = (from feed in UserInfo.Info.UserFeeds
                     from feedItem in feed.Feed.FeedItems
                     where !UserInfo.Info.UserFeedItems.Any(f => f.FeedItemID == feedItem.ID && f.Read)
                     select feedItem);

            return View(new ViewFeedsViewModel { CurrentPage = page ?? 1, FeedItems = q.OrderByDescending(f => f.Created).Skip(page.HasValue ? Math.Abs((page.Value - 1) * Properties.Settings.Default.PageLength) : 0).Take(Properties.Settings.Default.PageLength), Pages = (int)Math.Ceiling(q.Count() / (double)Properties.Settings.Default.PageLength) });
        }
コード例 #6
0
ファイル: User.cs プロジェクト: bambidarra/FeedReader
        public static bool LogIn(string username, string password)
        {
            if (DB == null) DB = DataBase.GetInstance();
            password = HashPassword(password);

            Models.User user = DB.Users.FirstOrDefault(u => u.Email == username);
            if (user == null || user.PasswordHash != password)
            {
                Thread.Sleep(Properties.Settings.Default.FailedLogInSleep);
                return IsLoggedIn = false;
            }

            CurrentController.Session["UserInfo"] = Info = user;
            return true;
        }
コード例 #7
0
ファイル: DataBase.cs プロジェクト: bambidarra/FeedReader
 public static DataBase GetInstance()
 {
     if (Instance == null) Instance = new DataBase();
     return Instance;
 }