Esempio n. 1
0
            public void Execute(IJobExecutionContext context)
            {
                using (var contextDb = new DasKlubDbContext())
                {
                    var oneWeekAgo = DateTime.UtcNow.AddDays(-7);

                    const int totalTopAmount = 3;

                    var mostPopularForumPosts =
                        contextDb.ForumPost
                            .Where(x => x.CreateDate > oneWeekAgo)
                            .GroupBy(x => x.ForumSubCategoryID)
                            .OrderByDescending(y => y.Count())
                            .Take(totalTopAmount)
                            .ToList();

                    if (mostPopularForumPosts.Count == totalTopAmount)
                    {
                        var threads = new StringBuilder();

                        foreach (var item in mostPopularForumPosts)
                        {
                            ForumSubCategory forumThread =
                                contextDb.ForumSubCategory
                                    .FirstOrDefault(x => x.ForumSubCategoryID == item.Key);

                            ForumCategory forum =
                                contextDb.ForumCategory
                                    .FirstOrDefault(x => x.ForumCategoryID == forumThread.ForumCategoryID);

                            threads.Append(forumThread.Title);
                            threads.AppendLine();
                            threads.AppendFormat("{0}/forum/{1}/{2}", GeneralConfigs.SiteDomain, forum.Key,
                                forumThread.Key);
                            threads.AppendLine();
                            threads.Append("------------------------------");
                            threads.AppendLine();
                            threads.AppendLine();
                        }

                        string top3Threads = threads.ToString();

                        DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
                        Calendar cal = dfi.Calendar;
                        int weekNumber = cal.GetWeekOfYear(DateTime.UtcNow, dfi.CalendarWeekRule, dfi.FirstDayOfWeek);

                        string title = string.Format("TOP {0} Forum Threads [Week: {1}, {2}]",
                            totalTopAmount,
                            weekNumber,
                            DateTime.UtcNow.Year);

                        var uas = new UserAccounts();
                        uas.GetAll();

                        foreach (UserAccount user in uas)
                        {
                            var uad = new UserAccountDetail();
                            uad.GetUserAccountDeailForUser(user.UserAccountID);

                            if (!uad.EmailMessages || uad.UserAccountDetailID == 0) continue;

                            string message = string.Format(
                                                "Hello {0}! {1}{1}{2}",
                                                user.UserName,
                                                Environment.NewLine,
                                                top3Threads);

                            System.Threading.Thread.Sleep(1000 / MaxEmailsPerSecond);

                            _mail.SendMail(AmazonCloudConfigs.SendFromEmail,
                                user.EMail,
                                title,
                                message);

                            Log.Info(string.Format("Sent top 3 to: {0}", user.EMail));
                        }
                    }
                    else
                    {
                        Log.Info("Not enough forum activity to mail users");
                    }
                }
            }
Esempio n. 2
0
        private void SendMassMail(string message)
        {
            _mail = new MailService();

            int totalSent = 0;

            var uas = new UserAccounts();
            uas.GetAll();

            foreach (UserAccount ua1 in uas.OrderBy(x => x.CreateDate))
            {
                var uad = new UserAccountDetail();
                uad.GetUserAccountDeailForUser(ua1.UserAccountID);

                if (!uad.EmailMessages) continue;

                // safety
               if (ua1.UserName != "bootlegbaron") continue;

                var userAddress = new UserAddress();
                userAddress.GetUserAddress(ua1.UserAccountID);

                System.Threading.Thread.Sleep(200);

                if (_mail.SendMail("*****@*****.**", ua1.EMail, "Das Klub Kalendar 2017 - Competition!", message))
                {
                    totalSent++;
                }
                else
                {
                    uad.EmailMessages = false;
                    uad.Update();
                }
            }

            HttpContext.Current.Response.Write(totalSent);
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType = "text/xml";

            XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);

            writer.WriteStartDocument();
            writer.WriteStartElement("urlset");
            writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
            writer.WriteString("\r\n");     //newline

            // home
            writer.WriteStartElement("url");
            writer.WriteElementString("loc", "http://DasKlub.com/");
            writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.UtcNow));
            writer.WriteElementString("changefreq", "weekly");
            writer.WriteElementString("priority", "1.0");
            writer.WriteEndElement();
            writer.WriteString("\r\n");     //newline

            Artists artis = new Artists();
            artis.GetAll();

            foreach (BootBaronLib.AppSpec.DasKlub.BOL.ArtistContent.Artist app in artis)
            {

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://DasKlub.com/" + app.URLOfArtist);
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", app.UpdateDate));
                writer.WriteElementString("changefreq", "weekly");
                writer.WriteElementString("priority", "0.8");
                writer.WriteEndElement();
                writer.WriteString("\r\n");     //newline

            }

            ArrayList userAccounts = Videos.GetDistinctUsers();

            foreach (string app in userAccounts)
            {

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://DasKlub.com/" + app);
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.UtcNow));
                writer.WriteElementString("changefreq", "weekly");
                writer.WriteElementString("priority", "0.7");
                writer.WriteEndElement();
                writer.WriteString("\r\n");     //newline
            }

            // users
            UserAccounts uas = new UserAccounts();
            uas.GetAll();

            foreach (UserAccount ua1 in uas)
            {
                //foreach (string a1 in userAccounts)
                //{
                  //  if (a1 == ua1.UserName) continue;// already added as a video

                    writer.WriteStartElement("url");
                    writer.WriteElementString("loc", "http://DasKlub.com/" + ua1.UserName.Replace(" ", "-"));
                    writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", ua1.LastActivityDate));
                    writer.WriteElementString("changefreq", "weekly");
                    writer.WriteElementString("priority", "0.7");
                    writer.WriteEndElement();
                    writer.WriteString("\r\n");     //newline
                //}
            }

            /// content

            Contents cnts = new Contents();
            cnts.GetAllActiveContent();

            foreach (BootBaronLib.AppSpec.DasKlub.BOL.UserContent.Content c1 in cnts)
            {
                //foreach (string a1 in userAccounts)
                //{
                //  if (a1 == ua1.UserName) continue;// already added as a video

                writer.WriteStartElement("url");
                writer.WriteElementString("loc", "http://DasKlub.com/news/" + c1.ContentKey);
                writer.WriteElementString("lastmod", String.Format("{0:yyyy-MM-dd}", c1.ReleaseDate));
                writer.WriteElementString("changefreq", "weekly");
                writer.WriteElementString("priority", "0.8");
                writer.WriteEndElement();
                writer.WriteString("\r\n");     //newline
                //}
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();

            Response.End();
        }