private bool changeState(ScheduleItemCommentAddress commentAddress, EntityState state, string pluginEventName)
        {
            bool commentStateChanged    = false;
            ScheduleItemComment comment = getComment(commentAddress);

            using (TransactionScope transaction = new TransactionScope())
            {
                if (comment != null && comment.State != state)
                {
                    commentRepository.ChangeState(comment.ID, state);

                    commentStateChanged = commentRepository.GetComment(comment.ID).State == state;
                }

                if (commentStateChanged)
                {
                    cache.InvalidateItem(comment);
                }

                transaction.Complete();
            }

            if (commentStateChanged)
            {
                pluginEngine.ExecuteAll(pluginEventName, new { context, parent = new ScheduleItemSmallReadOnly(comment.ScheduleItem), comment = new CommentReadOnly(comment, absolutePathHelper.GetAbsolutePath(comment)) });
            }

            return(commentStateChanged);
        }
        private void invalidateCachedCommentDependencies(ScheduleItemComment comment)
        {
            if (comment.Parent != null)
            {
                cache.InvalidateItem(new ScheduleItemComment(comment.Parent.ID));
            }

            cache.InvalidateItem(new ScheduleItem(comment.ScheduleItem.ID));
        }
Пример #3
0
 public static string Gravatar <TModel>(this HtmlHelper <TModel> htmlHelper, ScheduleItemComment comment, string size) where TModel : OxiteViewModel
 {
     return(htmlHelper.Gravatar(
                comment.CreatorEmailHash.CleanAttribute(),
                comment.CreatorName.CleanAttribute(),
                size,
                htmlHelper.ViewData.Model.Site.GravatarDefault
                ));
 }
        private string generateMessageBody(ScheduleItemSmall post, ScheduleItemComment comment, Site site)
        {
            string body = getPhrase("Messages.NewComment", site.LanguageDefault, getDefaultBody());
            //TODO: (erikpo) Change this to come from the user this message is going to if applicable
            double timeZoneOffset = site.TimeZoneOffset;

            body = body.Replace("{Site.Name}", site.DisplayName);
            body = body.Replace("{User.Name}", comment.CreatorName);
            body = body.Replace("{Post.Title}", post.Title);
            //TODO: (erikpo) Change the published date to be relative (e.g. 5 minutes ago)
            body = body.Replace("{Comment.Created}", comment.Created.AddHours(timeZoneOffset).ToLongTimeString());
            body = body.Replace("{Comment.Body}", comment.Body);
            body = body.Replace("{Comment.Permalink}", absolutePathHelper.GetAbsolutePath(comment).Replace("%23", "#"));

            return(body);
        }
        private string generateUniqueCommentSlug(ScheduleItemAddress scheduleItemAddress)
        {
            string commentSlug = null;
            bool   isUnique    = false;

            while (!isUnique)
            {
                commentSlug = Guid.NewGuid().ToString("N").Substring(0, 5);

                ScheduleItemComment foundComment = getComment(new ScheduleItemCommentAddress(scheduleItemAddress, commentSlug));

                isUnique = foundComment == null;
            }

            return(commentSlug);
        }
Пример #6
0
        public void AddSubscription(Guid siteID, ScheduleItemComment comment)
        {
            if (getSubscriptionExists(siteID, comment.ScheduleItem, comment.CreatorEmail))
            {
                return;
            }

            oxite_Subscription subscription = new oxite_Subscription {
                SubscriptionID = Guid.NewGuid(), UserID = context.oxite_Users.Single(u => u.Username == "Anonymous").UserID, UserName = comment.CreatorName, UserEmail = comment.CreatorEmail
            };

            context.oxite_Subscriptions.InsertOnSubmit(subscription);
            context.oxite_Conferences_ScheduleItemSubscriptionRelationships.InsertOnSubmit(new oxite_Conferences_ScheduleItemSubscriptionRelationship {
                SubscriptionID = subscription.SubscriptionID, ScheduleItemID = GetScheduleItem(comment.ScheduleItem.EventName, comment.ScheduleItem.Slug).ID
            });

            context.SubmitChanges();
        }
Пример #7
0
        public string GetAbsolutePath(ScheduleItemComment comment)
        {
            if (comment == null)
            {
                throw new ArgumentNullException("comment");
            }
            if (string.IsNullOrEmpty(comment.Slug) || string.IsNullOrEmpty(comment.ScheduleItem.Slug) || string.IsNullOrEmpty(comment.ScheduleItem.EventName))
            {
                throw new ArgumentException();
            }

            UriBuilder builder   = new UriBuilder(context.Site.Host.Scheme, context.Site.Host.Host, context.Site.Host.Port, context.Site.Host.AbsolutePath);
            UrlHelper  urlHelper = new UrlHelper(new RequestContext(new DummyHttpContext(null, context.Site.Host), new RouteData()), context.Routes);

            //TODO: (erikpo) It might make sense to move UrlHelperExtensions back into Oxite so this isn't duplicated
            //TODO: (erikpo) This is pointing to a route that's current in App_Code.  That route should move
            builder.Path = urlHelper.RouteUrl("PDC09SessionCommentPermalink", new { scheduleItemSlug = comment.ScheduleItem.Slug, commentSlug = comment.Slug });

            return(builder.Uri.ToString());
        }
        private IEnumerable <MessageOutbound> generateMessages(ScheduleItemSmall post, ScheduleItemComment comment)
        {
            IEnumerable <ScheduleItemSubscription> subscriptions = scheduleItemRepository.GetSubscriptions(post.EventName, post.Slug);
            List <MessageOutbound> messages = new List <MessageOutbound>();
            //TODO: (erikpo) Once the plugin model is done, get this from the plugin
            int retryCount = 4;

            foreach (ScheduleItemSubscription subscription in subscriptions)
            {
                string userName = subscription.UserName;

                MessageOutbound message = new MessageOutbound
                {
                    ID                  = Guid.NewGuid(),
                    To                  = !string.IsNullOrEmpty(userName) ? string.Format("{0} <{1}>", userName, subscription.UserEmail) : subscription.UserEmail,
                    Subject             = string.Format(getPhrase("Messages.Formats.ReplySubject", context.Site.LanguageDefault, "RE: {0}"), post.Title),
                    Body                = generateMessageBody(post, comment, context.Site),
                    RemainingRetryCount = retryCount
                };

                messages.Add(message);
            }

            return(messages);
        }
Пример #9
0
 public static string ApproveComment(this UrlHelper urlHelper, ScheduleItemComment comment)
 {
     return(urlHelper.RouteUrl("ApproveScheduleItemComment", new { /*eventName = comment.ScheduleItem.EventName, */ scheduleItemSlug = comment.ScheduleItem.Slug, commentSlug = comment.Slug }));
 }
Пример #10
0
 public static string CommentPending(this UrlHelper urlHelper, ScheduleItemComment comment)
 {
     //todo: (nheskew) really want ScheduleItemCommentForm w/ a query string inserted but that's not going to happen in the near term so hacking together the URL
     return(string.Format("{0}#comment", urlHelper.RouteUrl("ScheduleItem", new { /*eventName = comment.ScheduleItem.EventName, */ scheduleItemSlug = comment.ScheduleItem.Slug, pending = bool.TrueString })));
 }
Пример #11
0
 public static string Comment(this UrlHelper urlHelper, ScheduleItemComment comment)
 {
     return(urlHelper.RouteUrl("PDC09SessionCommentPermalink", new { /*eventName = comment.ScheduleItem.EventName, */ scheduleItemSlug = comment.ScheduleItem.Slug, commentSlug = comment.Slug }));
 }
Пример #12
0
        public ScheduleItemComment Save(ScheduleItemComment comment)
        {
            oxite_Comment commentToSave = null;

            if (comment.ID != Guid.Empty)
            {
                commentToSave = context.oxite_Comments.FirstOrDefault(c => c.CommentID == comment.ID);
            }

            if (commentToSave == null)
            {
                commentToSave = new oxite_Comment();

                commentToSave.CommentID   = comment.ID != Guid.Empty ? comment.ID : Guid.NewGuid();
                commentToSave.CreatedDate = commentToSave.ModifiedDate = DateTime.UtcNow;

                context.oxite_Comments.InsertOnSubmit(commentToSave);
            }
            else
            {
                commentToSave.ModifiedDate = DateTime.UtcNow;
            }

            oxite_Conferences_ScheduleItem scheduleItem = (from si in context.oxite_Conferences_ScheduleItems join e in context.oxite_Conferences_Events on si.EventID equals e.EventID where /*e.SiteID == siteID && */ string.Compare(e.EventName, comment.ScheduleItem.EventName, true) == 0 && string.Compare(si.Slug, comment.ScheduleItem.Slug, true) == 0 select si).FirstOrDefault();

            if (scheduleItem == null)
            {
                throw new InvalidOperationException(string.Format("ScheduleItem in Event {0} at slug {1} could not be found to add the comment to", comment.ScheduleItem.EventName, comment.ScheduleItem.Slug));
            }
            context.oxite_Conferences_ScheduleItemCommentRelationships.InsertOnSubmit(
                new oxite_Conferences_ScheduleItemCommentRelationship
            {
                CommentID      = commentToSave.CommentID,
                ScheduleItemID = scheduleItem.ScheduleItemID,
                Slug           = comment.Slug
            }
                );

            commentToSave.ParentCommentID = comment.Parent != null && comment.Parent.ID != Guid.Empty ? comment.Parent.ID : commentToSave.CommentID;
            commentToSave.Body            = comment.Body;
            commentToSave.CreatorIP       = comment.CreatorIP;
            commentToSave.State           = (byte)comment.State;
            commentToSave.UserAgent       = comment.CreatorUserAgent;
            commentToSave.oxite_Language  = context.oxite_Languages.Where(l => l.LanguageName == comment.Language.Name).FirstOrDefault();

            if (comment.CreatorUserID != Guid.Empty)
            {
                commentToSave.CreatorUserID = comment.CreatorUserID;
            }
            else
            {
                oxite_User anonymousUser = context.oxite_Users.FirstOrDefault(u => u.Username == "Anonymous");
                if (anonymousUser == null)
                {
                    throw new InvalidOperationException("Could not find anonymous user");
                }
                commentToSave.CreatorUserID = anonymousUser.UserID;

                commentToSave.CreatorName        = comment.CreatorName;
                commentToSave.CreatorEmail       = comment.CreatorEmail;
                commentToSave.CreatorHashedEmail = comment.CreatorEmailHash;
                commentToSave.CreatorUrl         = comment.CreatorUrl;
            }

            context.SubmitChanges();

            return((
                       from c in context.oxite_Comments
                       join sicr in context.oxite_Conferences_ScheduleItemCommentRelationships on c.CommentID equals sicr.CommentID
                       join si in context.oxite_Conferences_ScheduleItems on sicr.ScheduleItemID equals si.ScheduleItemID
                       join e in context.oxite_Conferences_Events on si.EventID equals e.EventID
                       join u in context.oxite_Users on c.CreatorUserID equals u.UserID
                       where /*e.SiteID == siteID && */ string.Compare(e.EventName, comment.ScheduleItem.EventName, true) == 0 && string.Compare(si.Slug, scheduleItem.Slug, true) == 0 && string.Compare(sicr.Slug, comment.Slug, true) == 0
                       select projectComment(c, sicr, si, e, u)
                       ).FirstOrDefault());
        }