private void refreshDatabase(PageReadData data, bool notified = false, int revID = -1)
        {
            using (UserDataEntities dc = new UserDataEntities())
            {
                var currentPage = from page in dc.Pages
                                  where page.Id == data.PageId
                                  select page;
                try
                {
                    var page = currentPage.First();
                    if (notified)
                    {
                        // If user has been notified
                        page.LastRevision = revID;
                        page.LastNotified = DateTime.Now;
                    }
                    page.LastRefreshed = DateTime.Now;

                    dc.SaveChanges();
                }
                catch (ArgumentNullException exp)
                {
                    Console.WriteLine("Error: " + exp.Message + "\n\t Possibly wrong page id.");
                }
            }
        }
        private void sendEmail(PageReadData data)
        {
            EmailSender emailSender = new EmailSender();

            emailSender.sendEmail(data.Email, data.UserName, data.WikiPage + " Wikipedia page has been changed",
                                  "Dear " + data.UserName + "!\n\n" +
                                  "A wikipedia page followed by you has been changed:\n" +
                                  "https://en.wikipedia.org/wiki/" + data.WikiPage + "\n\n\n" +
                                  "Regards,\n" +
                                  "The Wikipedia Follower Team"
                                  );
            Console.WriteLine("Email has been sent to " + data.Email);
        }
        private void checkAndUpdateWikiPage(PageReadData data)
        {
            // First check revID
            WikiAPI api    = new WikiAPI();
            var     revIDs = api.GetRevisions(data.WikiPage, data.LastRevision).OrderBy(x => x.RevId).ToList();

            if (revIDs.Count <= 1)
            {
                // No newer revID
                return;
            }

            var currentRevID = revIDs.Last().RevId;

            if (data.LastRevision == -1)
            {
                // First check send email
                sendEmail(data);
                refreshDatabase(data, true, currentRevID);
                return;
            }

            string currentPageContent = api.GetContent(data.WikiPage, currentRevID);
            string prevPageContent    = api.GetContent(data.WikiPage, data.LastRevision);

            MatchCollection words1 = Regex.Matches(currentPageContent, @"\b(\w+)\b");
            MatchCollection words2 = Regex.Matches(prevPageContent, @"\b(\w+)\b");

            var hs1 = new HashSet <string>(words1.Cast <Match>().Select(m => m.Value));
            var hs2 = new HashSet <string>(words2.Cast <Match>().Select(m => m.Value));

            var hs1_mod = new HashSet <string>(hs1);
            var hs2_mod = new HashSet <string>(hs2);

            hs2_mod.ExceptWith(hs1);
            int prevVersionExtraWordCounter = hs2_mod.Count;

            hs1_mod.ExceptWith(hs2);
            int newVersionExtraWordCounter = hs1_mod.Count;

            // Calculate diff, if bigger then sensititvity, then send email
            if (newVersionExtraWordCounter + prevVersionExtraWordCounter > data.Sensitivity)
            {
                sendEmail(data);
                refreshDatabase(data, true, currentRevID);
            }
            else
            {
                refreshDatabase(data);
            }
        }