Beispiel #1
0
        public ModelResult <Role> AddRole(RoleInput roleInput)
        {
            ValidationStateDictionary validationState = new ValidationStateDictionary();

            validationState.Add(typeof(RoleInput), validator.Validate(roleInput));

            if (!validationState.IsValid)
            {
                return(new ModelResult <Role>(validationState));
            }

            Role role;

            using (TransactionScope transaction = new TransactionScope())
            {
                role = roleInput.ToRole();

                validateRole(role, validationState);

                if (!validationState.IsValid)
                {
                    return(new ModelResult <Role>(validationState));
                }

                role = repository.Save(role);

                transaction.Complete();
            }

            pluginEngine.ExecuteAll("RoleSaved", new { context, role = new RoleReadOnly(role) });
            pluginEngine.ExecuteAll("RoleAdded", new { context, role = new RoleReadOnly(role) });

            return(new ModelResult <Role>(role, validationState));
        }
Beispiel #2
0
        public static Post ProcessDisplayOfPost(this IPluginEngine pluginEngine, OxiteContext context, Func <Post> getPost)
        {
            PostForProcessing post = new PostForProcessing(getPost());

            pluginEngine.ExecuteAll("ProcessDisplayOfPost", new { context, post });

            return(post.ToPost());
        }
Beispiel #3
0
        public ModelResult <Post> AddPost(PostInput postInput, EntityState postState)
        {
            postInput = pluginEngine.Process <PluginPostInput>("ProcessInputOfPost", new PluginPostInput(postInput)).ToPostInput();
            postInput = pluginEngine.Process <PluginPostInput>("ProcessInputOfPostOnAdd", new PluginPostInput(postInput)).ToPostInput();

            ModelResult <Post> results = addPost(postInput, () => postInput.ToPost(postState, context.User.Cast <User>(), t => expressions.Clean("TagReplace", t)));

            if (results.IsValid)
            {
                Post   newPost = results.Item;
                string postUrl = urlHelper.AbsolutePath(urlHelper.Post(newPost));

                //TODO: (erikpo) Move this into a module
                addCreatorSubscription(newPost);

                //TODO: (erikpo) Move this into a module
                if (newPost.State == EntityState.Normal && newPost.Published.HasValue)
                {
                    IEnumerable <TrackbackOutbound> trackbacksToAdd    = extractTrackbacks(newPost, postUrl, newPost.Blog.DisplayName);
                    IEnumerable <TrackbackOutbound> unsentTrackbacks   = trackbackOutboundRepository.GetUnsent(newPost.ID);
                    IEnumerable <TrackbackOutbound> trackbacksToRemove = trackbacksToAdd.Where(tb => !unsentTrackbacks.Contains(tb) && !tb.Sent.HasValue);

                    trackbackOutboundRepository.Remove(trackbacksToRemove);
                    trackbackOutboundRepository.Save(trackbacksToAdd);
                }
                else
                {
                    //TODO: (erikpo) Remove all outbound trackbacks
                }

                pluginEngine.ExecuteAll("PostSaved", new { context, post = new PostReadOnly(newPost, postUrl) });
                pluginEngine.ExecuteAll("PostAdded", new { context, post = new PostReadOnly(newPost, postUrl) });

                if (newPost.State == EntityState.Normal && newPost.Published.HasValue && newPost.Published.Value <= DateTime.UtcNow)
                {
                    pluginEngine.ExecuteAll("PostPublished", new { context, post = new PostReadOnly(newPost, postUrl) });
                }
            }

            return(results);
        }
Beispiel #4
0
        private ModelResult <Blog> editBlog <T>(BlogAddress blogAddress, T input, Func <Blog, Blog> applyInput)
        {
            ValidationStateDictionary validationState = new ValidationStateDictionary();

            validationState.Add(typeof(T), validator.Validate(input));

            if (!validationState.IsValid)
            {
                return(new ModelResult <Blog>(validationState));
            }

            Blog originalBlog;
            Blog newBlog;

            using (TransactionScope transaction = new TransactionScope())
            {
                originalBlog = repository.GetBlog(context.Site.ID, blogAddress.BlogName);
                newBlog      = applyInput(originalBlog);

                validateBlog(context.Site.ID, newBlog, originalBlog, validationState);

                if (!validationState.IsValid)
                {
                    return(new ModelResult <Blog>(validationState));
                }

                newBlog = repository.Save(newBlog);

                invalidateCachedBlogForEdit(newBlog, originalBlog);

                transaction.Complete();
            }

            pluginEngine.ExecuteAll("BlogEdited", new { context, blog = new BlogReadOnly(newBlog), blogOriginal = new BlogReadOnly(originalBlog) });

            return(new ModelResult <Blog>(newBlog, validationState));
        }
        public IPageOfItems<ISearchResult> GetSearchResults(PagingInfo pagingInfo, SearchCriteria criteria)
        {
            IPageOfItems<ISearchResult> searchResults =
                cache.GetItems<IPageOfItems<ISearchResult>, ISearchResult>(
                    string.Format("GetPosts-SearchTerm:{0}", criteria.Term),
                    pagingInfo.ToCachePartition(),
                    () => repository.GetSearchResults(pagingInfo, criteria),
                    null
                    );

            //if (context.RequestDataFormat.IsFeed())
            //    searchResults = searchResults.Since(context.RequestContext.HttpContext.Request.IfModifiedSince());

            pluginEngine.ExecuteAll("UserSearched", new { context, criteria });

            return searchResults;
        }
Beispiel #6
0
        public IPageOfItems <ISearchResult> GetSearchResults(int pageIndex, int pageSize, SearchCriteria criteria)
        {
            IPageOfItems <ISearchResult> searchResults =
                cache.GetItems <IPageOfItems <ISearchResult>, ISearchResult>(
                    string.Format("GetPosts-SearchTerm:{0}", criteria.Term),
                    new CachePartition(pageIndex, pageSize),
                    () => repository.GetSearchResults(context.Site.ID, criteria).GetPage(pageIndex, pageSize),
                    null
                    );

            //if (context.RequestDataFormat.IsFeed())
            //    searchResults = searchResults.Since(context.RequestContext.HttpContext.Request.IfModifiedSince());

            pluginEngine.ExecuteAll("UserSearched", new { context, criteria });

            return(searchResults);
        }
Beispiel #7
0
        public ModelResult ChangePassword(User user, UserChangePasswordInput userInput)
        {
            ValidationStateDictionary validationState = new ValidationStateDictionary();

            validationState.Add(typeof(UserChangePasswordInput), validator.Validate(userInput));

            if (!validationState.IsValid)
            {
                return(new ModelResult(validationState));
            }

            string passwordSalt = Guid.NewGuid().ToString("N");
            string password     = userInput.Password.SaltAndHash(passwordSalt);

            repository.SetModuleData(user, "FormsAuthentication", string.Format("{0}|{1}", passwordSalt, password));

            pluginEngine.ExecuteAll("UserChangePassword", new { user, context });

            return(new ModelResult());
        }
Beispiel #8
0
        public ModelResult <UserAuthenticated> AddUser(UserInputAdd userInputAdd)
        {
            ValidationStateDictionary validationState = new ValidationStateDictionary();

            validationState.Add(typeof(UserInputAdd), validator.Validate(userInputAdd));

            if (!validationState.IsValid)
            {
                return(new ModelResult <UserAuthenticated>(validationState));
            }

            //TODO: (erikpo) Replace with some logic to set the language from the user's browser or from a dropdown list
            Language          language = languageRepository.GetLanguage(context.Site.LanguageDefault ?? "en");
            UserAuthenticated user;

            using (TransactionScope transaction = new TransactionScope())
            {
                user = userInputAdd.ToUser(e => e.ComputeEmailHash(), EntityState.Normal, language);

                validateUser(user, validationState);

                if (!validationState.IsValid)
                {
                    return(new ModelResult <UserAuthenticated>(validationState));
                }

                user = repository.Save(user, context.Site.ID);



                invalidateCachedUserDependencies(user);

                transaction.Complete();
            }

            pluginEngine.ExecuteAll("UserSaved", new { context, user = new UserReadOnly(user) });
            pluginEngine.ExecuteAll("UserAdded", new { context, user = new UserReadOnly(user) });

            return(new ModelResult <UserAuthenticated>(user, validationState));
        }
        public ModelResult <ScheduleItemComment> AddComment(ScheduleItemAddress scheduleItemAddress, CommentInput commentInput)
        {
            CommentIn commentIn = new CommentIn(commentInput);

            pluginEngine.ExecuteAll("ProcessInputOfComment", new { context, comment = commentIn });
            commentInput = commentIn.ToCommentInput();

            commentInput = pluginEngine.Process <CommentIn>("ProcessInputOfCommentOnAdd", new CommentIn(commentInput)).ToCommentInput();

            if (pluginEngine.AnyTrue("IsCommentSpam", new { context, comment = commentIn }))
            {
                return(new ModelResult <ScheduleItemComment>(new ValidationStateDictionary(typeof(CommentInput), new ValidationState(new[] { new ValidationError("Comment.IsSpam", commentInput, "The supplied comment was considered to be spam and was not added") }))));
            }

            ValidationStateDictionary validationState = ValidateCommentInput(commentInput);

            if (!validationState.IsValid)
            {
                return(new ModelResult <ScheduleItemComment>(validationState));
            }

            EntityState commentState;

            try
            {
                commentState = context.User.IsAuthenticated ? EntityState.Normal : (EntityState)Enum.Parse(typeof(EntityState), context.Site.CommentStateDefault);
            }
            catch
            {
                commentState = EntityState.PendingApproval;
            }

            //TODO: (erikpo) Replace with some logic to set the language from the user's browser or from a dropdown list
            Language            language = languageRepository.GetLanguage(context.Site.LanguageDefault ?? "en");
            ScheduleItemComment comment;

            using (TransactionScope transaction = new TransactionScope())
            {
                string commentSlug = generateUniqueCommentSlug(scheduleItemAddress);

                comment = commentInput.ToComment(context.User.Cast <UserAuthenticated>(), context.HttpContext.Request.GetUserIPAddress().ToLong(), context.HttpContext.Request.UserAgent, language, commentSlug, commentState);

                comment = conferencesCommentRepository.Save(comment, context.Site.ID, scheduleItemAddress.EventName, scheduleItemAddress.ScheduleItemSlug);

                if (comment.State == EntityState.Normal)
                {
                    invalidateCachedCommentDependencies(comment);
                }

                transaction.Complete();
            }

            //TODO: (erikpo) The following calls to setup the subscription and send out emails for those subscribed needs to happen in the transaction (but can't currently because of issues with them being in different repositories

            //TODO: (erikpo) Move into a module
            if (commentInput.Subscribe)
            {
                if (context.User.IsAuthenticated)
                {
                    scheduleItemRepository.AddSubscription(context.Site.ID, comment.ScheduleItem, comment.CreatorUserID);
                }
                else
                {
                    scheduleItemRepository.AddSubscription(context.Site.ID, comment);
                }
            }

            //TODO: (erikpo) Move into a module
            messageOutboundRepository.Save(generateMessages(comment.ScheduleItem, comment));

            ScheduleItemSmallReadOnly scheduleItemProxy = new ScheduleItemSmallReadOnly(comment.ScheduleItem);
            CommentReadOnly           commentProxy      = new CommentReadOnly(comment, "");

            pluginEngine.ExecuteAll("CommentAdded", new { context, parent = scheduleItemProxy, comment = commentProxy });

            if (comment.State == EntityState.Normal)
            {
                pluginEngine.ExecuteAll("CommentApproved", new { context, parent = scheduleItemProxy, comment = commentProxy });
            }

            return(new ModelResult <ScheduleItemComment>(comment, validationState));
        }
 public static void ExecuteAll(this IPluginEngine pluginEngine, string operation, object parameters)
 {
     pluginEngine.ExecuteAll(operation, parameters, getInstalledAndEnabled(pluginEngine));
 }