コード例 #1
0
        private static string GetEmailBody(out bool postsMade)
        {
            DateTime start = DateTime.Now.AddDays(-1).Date;
            DateTime end   = start.AddDays(1);

            string result        = "<span style='font-size:x-large;'>Discussion Recap For " + start.ToLongDateDisplay() + ".</span><br><br>";
            int    numberOfPosts = 0;

            foreach (HomeAppsLib.db.NFL_forum post in LibCommon.DBModel().NFL_forums.Where(x => x.insert_dt >= start && x.insert_dt < end).OrderBy(x => x.insert_dt))
            {
                numberOfPosts++;

                result += HomeAppsLib.EmailSubscriptions.GenerateDiscPostEmailBodyText(post);

                result += "<br><br>";
            }
            if (numberOfPosts == 0)
            {
                result += "There are no discussions to report.<br><br>";
            }

            postsMade = numberOfPosts > 0;

            result += "<a href='" + LibCommon.WebsiteUrlRoot() + "'>Click here to log in and view all discussions.</a><br><br>";
            result += "Thanks,<br>The Wright Picks";

            result += "<br><br><br><span style='font-size:small;'>P.S. If you'd like to unsubscribe from this email, click <a href='" + EmailSubscriptions.LinkToUnsubscripe("XXXXXXXXXX", (int)EmailSubscriptionType.DailyForumRecap) + "'>here.</a></span>";

            return(result);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                LibCommon.UpdateNFLMatchups(false);
                return;

                DateTime start = DateTime.Now; // start timestamp

                // run program
                int picksRemindersCount = PicksReminders.SendPicksReminders();
                int formRecapCount      = ForumRecaps.SendDailyForumRecaps();

                DateTime finish = DateTime.Now; // finish timestamp



                // report results

                string type = "Daily Engine Version " + GetVersion();
                string desc = "Started {" + start + "}, Completed {" + finish + "}, Pick Reminders {" + picksRemindersCount + " sent}, Discussion Recaps {" + formRecapCount + " sent}.";

                LogRun(type, desc);
                if (DateTime.Now < Convert.ToDateTime("2/8/14"))
                {
                    LibCommon.SendEmail("*****@*****.**", type, "Should be last email for a while!<hr>" + desc, "Daily Engine");
                }
            }
            catch (Exception ex)
            {
                LibCommon.SendEmail("*****@*****.**", "ERROR in Daily Engine", ex.ToString(), "Daily Engine");
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            System.Net.WebClient client = new System.Net.WebClient();
            while (true)
            {
                try
                {
                    // 1. update data
                    bool changesMade = LibCommon.UpdateNFLMatchups(false);

                    // 2. try force refresh cache
                    if (changesMade)
                    {
                        try
                        {
                            string url = LibCommon.WebsiteUrlRoot() + "LoadCache.aspx?key=true";
                            client.DownloadString(url);
                        }
                        catch { }
                    }

                    // 3. report
                    if (LibCommon.IsAppInTestMode())
                    {
                        LibCommon.SendEmail("*****@*****.**", "Console Service Successful", "At " + DateTime.Now, "Console Service");
                    }

                    // 4. wait
                    System.Threading.Thread.Sleep(1000 * 60 * RUN_INVERVAL_MINUTES);
                }
                catch (Exception ex)
                {
                    try
                    {
                        _exceptionCount++;
                        string body = ex.ToString();

                        if (_exceptionCount == EXCEPTION_THRESHOLD)
                        {
                            body = "PROGRAM TERMINATED AFTER " + EXCEPTION_THRESHOLD + " ATTEMPTS<br /><br />" + body;
                        }

                        LibCommon.SendEmail("*****@*****.**", "Console Service Exception", body, "Console Service");

                        if (_exceptionCount == EXCEPTION_THRESHOLD)
                        {
                            return;
                        }
                    }
                    catch (Exception ex2)
                    {
                        string message = "Ex1={" + ex.Message + "}\n\nEx2={" + ex2.Message + "}";
                        Console.WriteLine(message);
                        Console.ReadLine();
                        return;
                    }
                }
            }
        }
コード例 #4
0
        private static void LogRun(string type, string desc)
        {
            var data = LibCommon.DBModel();

            HomeAppsLib.db.log log = new HomeAppsLib.db.log();
            log.type        = type;
            log.description = desc;
            log.LogDate     = DateTime.Now;
            data.logs.InsertOnSubmit(log);
            data.SubmitChanges();
        }
コード例 #5
0
        internal static void CallCacheUrlAsync()
        {
            string querystring = HttpContext.Current.Session["autoweek"] != null ?
                                 "?week=" + HttpContext.Current.Session["autoweek"].ToString() :
                                 "";
            string url = LibCommon.WebsiteUrlRoot() + "LoadCache.aspx" + querystring;

            Meta m = new Meta();

            m.URL = url;
            System.Threading.Thread t = new System.Threading.Thread(m.DoCallURLWork);
            t.Start();
        }
コード例 #6
0
        public static int SendPicksReminders()
        {
            DateTime aFewDaysOut        = DateTime.Now.AddDays(1).ToEndOfDay();
            var      weeksAboutToExpire = LibCommon.DBModel().NFL_weeks.Where(x => x.exp_dt > DateTime.Now && x.exp_dt < aFewDaysOut && x.week > 0);

            int count = 0;

            foreach (var weekAboutToExpire in weeksAboutToExpire)
            {
                count += SendRemindersForWeek(weekAboutToExpire);
            }

            return(count);
        }
コード例 #7
0
        private static int SendReminderEmails(HomeAppsLib.db.NFL_week weekAboutToExpire, EmailSubscriptionType emailSubscriptionType)
        {
            int count = 0;

            foreach (var user in EmailSubscriptions.GetSubscribedUsers(emailSubscriptionType))
            {
                if (LibCommon.DBModel().NFL_userPicks.Count(x => x.week == weekAboutToExpire.week && x.username == user.name) == 0)
                {
                    string to = LibCommon.IsDevelopmentEnvironment() ? "*****@*****.**" : user.email;

                    int daysLeft = (weekAboutToExpire.exp_dt.Date - DateTime.Now.Date).Days;

                    string subject = "Only " + daysLeft + " days left to make your picks!";
                    if (daysLeft == 1)
                    {
                        subject = subject.Replace("days", "day");
                    }
                    if (daysLeft == 0)
                    {
                        subject = "Picks expire today!";
                    }

                    //if (DateTime.Now < new DateTime(2016, 9, 10))
                    //    subject = "FEATURING CORY QUICK PICKS!! " + subject;

                    string body = "Hi, " + user.name + "!<br><br>";
                    body += "Remember, picks for <b>" + weekAboutToExpire.text + "</b> will expire on " + weekAboutToExpire.exp_dt.ToLongDateTimeDisplay() + "!<br><br>";
                    body += "<span style='font-size:x-large;'>Be sure to make your picks before then!</span><br>";
                    body += "<br><a href='" + LibCommon.WebsiteUrlRoot() + "nflpicks.aspx?quickpicks=true&autoweek=" + weekAboutToExpire.week + "&sso=" + LibCommon.SSOUserKey(user) + "' style='font-size:xx-large;'>CLICK HERE FOR NEW CORY QUICK PICKS!</span><br><br>";
                    body += "<span style='font-size:large;'><a href='" + LibCommon.WebsiteUrlRoot() + "'>Click here to log in and make your picks now</a></span><br><br>";
                    body += "Thanks,<br>The Wright Picks";
                    body += "<br><br><br><span style='font-size:small;'>P.S. If you'd like to unsubscribe from this email, click <a href='" + EmailSubscriptions.LinkToUnsubscripe(user, (int)emailSubscriptionType) + "'>here.</a></span>";

                    LibCommon.SendEmail(to, subject, body, "The Wright Picks", waitAfter: TimeSpan.FromSeconds(15));

                    if (user.name.ToLower() == "cory")
                    {
                        HomeAppsLib.LibCommon.SendCoryText(weekAboutToExpire.week);
                    }

                    count++;
                }
            }

            return(count);
        }
コード例 #8
0
        public static int SendDailyForumRecaps()
        {
            int  emailCount = 0;
            bool postsMade;

            string emailBody = GetEmailBody(out postsMade);

            if (postsMade)
            {
                foreach (HomeAppsLib.db.user user in EmailSubscriptions.GetSubscribedUsers(EmailSubscriptionType.DailyForumRecap))
                {
                    LibCommon.SendEmail(user.email, "Daily Disussion Recap", emailBody.Replace("XXXXXXXXXX", user.encPW), "The Wright Picks", waitAfter: TimeSpan.FromSeconds(1));
                    emailCount++;
                }
            }

            return(emailCount);
        }
コード例 #9
0
        private void DoWork()
        {
            System.Net.WebClient client = new System.Net.WebClient();
            while (true)
            {
                if (bgw.CancellationPending)
                {
                    return;
                }

                try
                {
                    // 1. update data
                    bool changesMade = LibCommon.UpdateNFLMatchups(false);

                    // 2. try force refresh cache
                    if (changesMade)
                    {
                        try
                        {
                            string url = LibCommon.WebsiteUrlRoot() + "LoadCache.aspx?key=true";
                            client.DownloadString(url);
                        }
                        catch { }
                    }

                    // sleep only 15 seconds during gameplay, otherwise 15 minutes
                    int sleep = changesMade ? 1000 * 15 : 1000 * 60 * 15;

                    // 3. report
                    if (LibCommon.IsAppInTestMode())
                    {
                        LibCommon.SendEmail("*****@*****.**", "Console Service Successful", "At " + DateTime.Now + ". Sleep = " + sleep, "Console Service");
                    }

                    // 4. wait
                    System.Threading.Thread.Sleep(sleep);
                }
                catch (Exception ex)
                {
                    try
                    {
                        _exceptionCount++;
                        string body = ex.ToString();

                        if (_exceptionCount == EXCEPTION_THRESHOLD)
                        {
                            body = "PROGRAM TERMINATED AFTER " + EXCEPTION_THRESHOLD + " ATTEMPTS<br /><br />" + body;
                        }

                        LibCommon.SendEmail("*****@*****.**", "Console Service Exception", body, "Console Service");

                        if (_exceptionCount == EXCEPTION_THRESHOLD)
                        {
                            return;
                        }
                    }
                    catch (Exception ex2)
                    {
                        string message = "Ex1={" + ex.Message + "}\n\nEx2={" + ex2.Message + "}";
                        Console.WriteLine(message);
                        Console.ReadLine();
                        return;
                    }
                }
            }
        }
コード例 #10
0
 protected override void OnStop()
 {
     bgw.CancelAsync();
     LibCommon.SendEmail("*****@*****.**", "Batch Service Stopped", "Batch Service Stopped", "Console Service");
 }