Exemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pageSize"></param>
 /// <param name="tagMode"></param>
 /// <param name="resultsCollection"></param>
 /// <returns></returns>
 internal static IEnumerable<TermInfo> GetHomeTermCollection(int pageSize, Constants.TagMode tagMode, IEnumerable<TermInfo> resultsCollection)
 {
     switch (tagMode)
     {
         case Constants.TagMode.ShowDailyUsage:
             return (from t in resultsCollection orderby t.DayTermUsage descending, t.Name ascending select t).Skip(0).Take(pageSize);
         case Constants.TagMode.ShowWeeklyUsage:
             return (from t in resultsCollection orderby t.WeekTermUsage descending, t.Name ascending select t).Skip(0).Take(pageSize);
         case Constants.TagMode.ShowMonthlyUsage:
             return (from t in resultsCollection orderby t.MonthTermUsage descending, t.Name ascending select t).Skip(0).Take(pageSize);
         default: // total
             return (from t in resultsCollection orderby t.TotalTermUsage descending, t.Name ascending select t).Skip(0).Take(pageSize);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string GenerateNotifications(DateTime lastRunDate, DateTime currentRunDate, Constants.SubscriptionType subType)
        {
            var strErrors = "";

            // based on subscription type, generate list of content additions to email
            switch (subType)
            {
                case Constants.SubscriptionType.DailyTerm:
                    // daily term (all questions created between dates)

                    // This email is going to be user specific, so we need to start w/ a list of subscribers (based on type daily term); each user can have multiple terms
                    // -- select all questions where

                    // we retrieve a collection of questions, each question will have a contentItem associated with it (we only retrieve stuff not voted out)

                    // we need to retrieve a collection of terms, based on content item collection from above
                    strErrors = "Daily Term: Sent " + 0 + " emails <br />";
                    break;
                case Constants.SubscriptionType.InstantTerm:
                    var typeController = new ContentTypeController();
                    var colContentTypes = (from t in typeController.GetContentTypes() where t.ContentType == Constants.ContentTypeName select t);

                    if (colContentTypes.Count() > 0)
                    {
                        var contentType = colContentTypes.Single();
                        var colContentItems = Controller.GetContentItemsByTypeAndCreated(contentType.ContentTypeId, lastRunDate, currentRunDate);

                        foreach (var item in colContentItems)
                        {
                            // we are using the question object because content item doesn't have a title association yet (for core integration)
                            var objQuestion = Controller.GetQuestionByContentItem(item.ContentItemId);

                            if (objQuestion != null)
                            {
                                // use the content item to build the email subject/body/content (sub question for content item now)
                                var colEmail = QaSettings.GetEmailCollection(Controller.GetQaPortalSettings(objQuestion.PortalId), objQuestion.PortalId);
                                var senderEmail = colEmail.Single(s => s.Key == Constants.EmailSettings.FromAddress.ToString()).Value;
                                //var urlBase = colEmail.Single(s => s.Key == Constants.EmailSettings.PrimaryUrl.ToString()).Value;
                                var questionTemplate =  colEmail.Single(s => s.Key == Constants.EmailSettings.SingleQuestionTemplate.ToString()).Value;
                                var ps = new PortalSettings(objQuestion.PortalId);

                                var titleLink = "http://" + ps.DefaultPortalAlias + "/tabid/" + objQuestion.TabID + "/view/question/id/" + objQuestion.PostId + "/" + DotNetNuke.Common.Globals.glbDefaultPage;
                                var subscribeLink = "http://" + ps.DefaultPortalAlias + "/tabid/" + objQuestion.TabID + "/view/subscriptions/" + DotNetNuke.Common.Globals.glbDefaultPage;

                                var terms = "";
                                var i = 0;
                                foreach (var t in objQuestion.Terms)
                                {
                                    terms += t.Name;
                                    i += 1;

                                    if (objQuestion.Terms.Count != i)
                                    {
                                        terms += ", ";
                                    }
                                }

                                questionTemplate = questionTemplate.Replace("[AUTHOR]", objQuestion.CreatedByDisplayName);
                                questionTemplate = questionTemplate.Replace("[TERMS]", terms);
                                questionTemplate = questionTemplate.Replace("[TITLELINK]", titleLink);
                                questionTemplate = questionTemplate.Replace("[TITLE]", objQuestion.Title);
                                questionTemplate = questionTemplate.Replace("[BODY]", Utils.ProcessDisplayPostBody(objQuestion.Body));
                                questionTemplate = questionTemplate.Replace("[SUBSCRIBELINK]", subscribeLink);

                                var colSubscribers = Controller.GetSubscribersByContentItem(item.ContentItemId, (int)Constants.SubscriptionType.InstantTerm, objQuestion.PortalId);
                                foreach (var subscriber in colSubscribers)
                                {
                                    // send off the email one by one (same email to multiple subscribers)
                                    Mail.SendMail(senderEmail, subscriber.Email, "", "", MailPriority.Normal,
                                                  HtmlUtils.StripWhiteSpace(objQuestion.Title, true), MailFormat.Html, Encoding.UTF8, questionTemplate,
                                                  "", Host.SMTPServer, Host.SMTPAuthentication, Host.SMTPUsername,
                                                  Host.SMTPPassword, Host.EnableSMTPSSL);
                                }

                                strErrors = "Instant Term: Sent " + colSubscribers.Count + " emails - " + objQuestion.Title + "<br />";
                            }
                        }
                    }
                    else
                    {
                        strErrors = "Instant Term: No email to send <br />";
                    }

                    break;
                default:
                    var colAnswers = Controller.GetAnswersByDate(lastRunDate, currentRunDate);

                    if (colAnswers.Count() > 0)
                    {
                        // for each content item in the collection, get a list of subscribers and send the emails off one by one.
                        foreach (var item in colAnswers)
                        {
                            var objQuestion = Controller.GetQuestionByContentItem(item.ContentItemId);
                            // use the post item to build the email subject/body/content (sub question for content item now)
                            var colEmail = QaSettings.GetEmailCollection(Controller.GetQaPortalSettings(item.PortalId), item.PortalId);
                            var senderEmail = colEmail.Single(s => s.Key == Constants.EmailSettings.FromAddress.ToString()).Value;
                            //var urlBase = colEmail.Single(s => s.Key == Constants.EmailSettings.PrimaryUrl.ToString()).Value;
                            var answerTemplate = colEmail.Single(s => s.Key == Constants.EmailSettings.AnswerTemplate.ToString()).Value;
                            var ps = new PortalSettings(item.PortalId);

                            var titleLink = "http://" + ps.DefaultPortalAlias + "/tabid/" + objQuestion.TabID + "/view/question/id/" + objQuestion.PostId + "/" + DotNetNuke.Common.Globals.glbDefaultPage;
                            var subscribeLink = "http://" + ps.DefaultPortalAlias + "/tabid/" + objQuestion.TabID + "/view/subscriptions/" + DotNetNuke.Common.Globals.glbDefaultPage;

                            answerTemplate = answerTemplate.Replace("[AUTHOR]", item.PostCreatedDisplayName);
                            answerTemplate = answerTemplate.Replace("[TITLELINK]", titleLink);
                            answerTemplate = answerTemplate.Replace("[TITLE]", objQuestion.Title);
                            answerTemplate = answerTemplate.Replace("[BODY]", Utils.ProcessDisplayPostBody(item.Body));
                            answerTemplate = answerTemplate.Replace("[SUBSCRIBELINK]", subscribeLink);

                            var colSubscribers = Controller.GetSubscribersByQuestion(item.ParentId, (int)Constants.SubscriptionType.InstantPost, item.PortalId);
                            foreach (var subscriber in colSubscribers)
                            {
                                // send off the email one by one (same email to multiple subscribers)
                                Mail.SendMail(senderEmail, subscriber.Email, "", "", MailPriority.Normal,
                                              HtmlUtils.StripWhiteSpace(objQuestion.Title, true), MailFormat.Html, Encoding.UTF8, answerTemplate,
                                              "", Host.SMTPServer, Host.SMTPAuthentication, Host.SMTPUsername,
                                              Host.SMTPPassword, Host.EnableSMTPSSL);
                            }

                            strErrors = "Instant Post: Sent " + colSubscribers.Count + " emails - " + objQuestion.Title + "<br />";
                        }
                    }
                    else
                    {
                        strErrors = "Instant Post: No new answers to email <br />";
                    }

                    // now we move onto comments
                    var colComments = Controller.GetCommentsByDate(lastRunDate, currentRunDate);

                    if (colComments.Count() > 0)
                    {
                        foreach (var item in colComments)
                        {
                            var objPost = Controller.GetPost(item.PostId, -1);
                            var ps = new PortalSettings(objPost.PortalId);
                            var objQuestion = objPost.ParentId == 0 ? objPost : Controller.GetQuestionByContentItem(objPost.ContentItemId);
                            var colEmail = QaSettings.GetEmailCollection(Controller.GetQaPortalSettings(objQuestion.PortalId), objPost.PortalId);
                            var commentTemplate = colEmail.Single(s => s.Key == Constants.EmailSettings.CommentTemplate.ToString()).Value;
                            var senderEmail = colEmail.Single(s => s.Key == Constants.EmailSettings.FromAddress.ToString()).Value;

                            var titleLink = "http://" + ps.DefaultPortalAlias + "/tabid/" + objQuestion.TabID + "/view/question/id/" + objQuestion.PostId + "/" + DotNetNuke.Common.Globals.glbDefaultPage;
                            var subscribeLink = "http://" + ps.DefaultPortalAlias + "/tabid/" + objQuestion.TabID + "/view/subscriptions/" + DotNetNuke.Common.Globals.glbDefaultPage;

                            commentTemplate = commentTemplate.Replace("[AUTHOR]", DotNetNuke.Entities.Users.UserController.GetUserById(objQuestion.PortalId, item.UserId).DisplayName);
                            commentTemplate = commentTemplate.Replace("[TITLELINK]", titleLink);
                            commentTemplate = commentTemplate.Replace("[TITLE]", objQuestion.Title);
                            commentTemplate = commentTemplate.Replace("[COMMENT]", Utils.ProcessDisplayPostBody(item.Comment));
                            commentTemplate = commentTemplate.Replace("[SUBSCRIBELINK]", subscribeLink);

                            var colSubscribers = Controller.GetSubscribersByQuestion(objQuestion.PostId, (int)Constants.SubscriptionType.InstantPost, objQuestion.PortalId);
                            foreach (var subscriber in colSubscribers)
                            {
                                // send off the email one by one (same email to multiple subscribers)
                                Mail.SendMail(senderEmail, subscriber.Email, "", "", MailPriority.Normal,
                                              HtmlUtils.StripWhiteSpace(objQuestion.Title, true), MailFormat.Html, Encoding.UTF8, commentTemplate,
                                              "", Host.SMTPServer, Host.SMTPAuthentication, Host.SMTPUsername,
                                              Host.SMTPPassword, Host.EnableSMTPSSL);
                            }
                            // we also have to remember to check if we emailed notification of a comment around this question already (only within this method, to avoid to comments on question being emailed 2x).
                            // also avoid emailing someone of their own comment

                        }
                    }
                    else
                    {
                        strErrors = "Instant Post: No new comments to email <br />";
                    }

                    break;
            }

            return strErrors;
        }