protected XElement[] GenerateRsdApiList(BlogAddress blogAddress, XNamespace rsdNamespace)
        {
            IEnumerable <Blog> blogs    = blogAddress != null ? new Blog[] { blogService.GetBlog(blogAddress) } : blogService.GetBlogs(0, 10000).ToArray();
            List <XElement>    elements = new List <XElement>(blogs.Count());

            string apiLink = new UriBuilder(context.Site.Host)
            {
                Path = Url.MetaWeblog()
            }.Uri.ToString();

            foreach (Blog blog in blogs)
            {
                elements.Add(
                    new XElement(
                        rsdNamespace + "api",
                        new XAttribute("name", "MetaWeblog"),
                        new XAttribute("blogID", blog.Name),
                        new XAttribute(
                            "preferred",
                            (blogs.Count() == 1 || string.Compare(blog.Name, blogAddress.BlogName, true) == 0).ToString().ToLower()
                            ),
                        new XAttribute("apiLink", apiLink)
                        )
                    );
            }

            return(elements.ToArray());
        }
Example #2
0
 public Blog GetBlog(BlogAddress blogAddress)
 {
     return(cache.GetItem <Blog>(
                string.Format("GetBlog-Name:{0}", blogAddress.BlogName),
                () => repository.GetBlog(context.Site.ID, blogAddress.BlogName),
                a => getBlogDependencies(a)
                ));
 }
Example #3
0
        public OxiteViewModelItem <PostInput> Add(BlogAddress blogAddress, PostInput postInput)
        {
            //TODO: (erikpo) Check permissions

            Blog blog = blogAddress != null?blogService.GetBlog(blogAddress) : null;

            return(new OxiteViewModelItem <PostInput>(new PostInput(blog, postInput)));
        }
Example #4
0
 //TODO: (erikpo) Need to change the query to return back data about the posts so they can be added as cache dependencies
 public IEnumerable <KeyValuePair <ArchiveData, int> > GetArchives(BlogAddress blogAddress)
 {
     return(cache.GetItems <IEnumerable <KeyValuePair <ArchiveData, int> >, KeyValuePair <ArchiveData, int> >(
                string.Format("GetArchives-Blog:{0}", blogAddress.BlogName),
                () => repository.GetArchivesByBlog(context.Site.ID, blogAddress.BlogName).ToArray(),
                null
                ));
 }
Example #5
0
 public IPageOfItems <Post> GetPostsWithDrafts(int pageIndex, int pageSize, BlogAddress blogAddress)
 {
     return(cache.GetItems <IPageOfItems <Post>, Post>(
                string.Format("GetPostsWithDrafts-Blog:{0}", blogAddress.BlogName),
                new CachePartition(pageIndex, pageSize),
                () => pluginEngine.ProcessDisplayOfPosts(context, () => repository.GetPostsByBlogWithDrafts(context.Site.ID, blogAddress.BlogName).GetPage(pageIndex, pageSize).FillTags(tagService).FillComments(commentService)),
                p => p.GetDependencies()
                ));
 }
        public virtual OxiteViewModel Import(BlogAddress blogAddress)
        {
            //TODO: (erikpo) Change this to be user selectable in the multiple blogs case if the user is a site owner
            Blog blog = blogService.GetBlog(blogAddress);

            if (blog == null)
            {
                return(null);
            }

            return(new OxiteViewModel {
                Container = blog
            });
        }
Example #7
0
        public object AddSave(BlogAddress blogAddress, PostInput postInput)
        {
            //TODO: (erikpo) Check permissions

            ModelResult <Post> results = postService.AddPost(postInput, EntityState.Normal);

            if (!results.IsValid)
            {
                ModelState.AddModelErrors(results.ValidationState);

                return(Add(blogAddress, postInput));
            }

            return(Redirect(Url.Post(results.Item)));
        }
Example #8
0
        public IPageOfItems <Post> GetPosts(int pageIndex, int pageSize, BlogAddress blogAddress)
        {
            IPageOfItems <Post> posts =
                cache.GetItems <IPageOfItems <Post>, Post>(
                    string.Format("GetPosts-Blog:{0}", blogAddress.BlogName),
                    new CachePartition(pageIndex, pageSize),
                    () => pluginEngine.ProcessDisplayOfPosts(context, () => repository.GetPostsByBlog(context.Site.ID, blogAddress.BlogName).GetPage(pageIndex, pageSize).FillTags(tagService).FillComments(commentService)),
                    p => p.GetDependencies()
                    );

            if (context.RequestDataFormat.IsFeed())
            {
                posts = posts.Since(p => p.Published.Value, context.HttpContext.Request.IfModifiedSince());
            }

            return(posts);
        }
Example #9
0
        public OxiteViewModelItems <Post> ListByBlog(int?pageNumber, int pageSize, BlogAddress blogAddress)
        {
            int  pageIndex = pageNumber.HasValue ? pageNumber.Value - 1 : 0;
            Blog blog      = blogService.GetBlog(blogAddress);

            if (blog == null)
            {
                return(null);
            }

            IPageOfItems <Post> posts = postService.GetPosts(pageIndex, pageSize, blogAddress);

            return(new OxiteViewModelItems <Post>(posts)
            {
                Container = blog
            });
        }
        protected XDocument GenerateRsd(BlogAddress blogAddress)
        {
            XNamespace rsdNamespace = "http://archipelago.phrasewise.com/rsd";
            XDocument  rsd          = new XDocument(
                new XElement(rsdNamespace + "rsd", new XAttribute("version", "1.0"),
                             new XElement(rsdNamespace + "service",
                                          new XElement(rsdNamespace + "engineName", "Oxite"),
                                          new XElement(rsdNamespace + "engineLink", Url.Oxite()),
                                          new XElement(rsdNamespace + "homePageLink", Url.AbsolutePath(Url.Home())),
                                          new XElement(rsdNamespace + "apis",
                                                       GenerateRsdApiList(blogAddress, rsdNamespace)
                                                       )
                                          )
                             ));

            return(rsd);
        }
Example #11
0
        public void RemoveBlog(BlogAddress blogAddress)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                Blog blog = repository.GetBlog(context.Site.ID, blogAddress.BlogName);

                if (blog != null && repository.Remove(context.Site.ID, blogAddress.BlogName))
                {
                    invalidateCachedBlogForRemove(blog);

                    transaction.Complete();

                    pluginEngine.ExecuteAll("BlogRemoved", new { context, blog = new BlogReadOnly(blog) });

                    return;
                }

                transaction.Complete();
            }
        }
Example #12
0
        public virtual object ItemSave(BlogAddress blogAddress, BlogInput blogInput)
        {
            ValidationStateDictionary validationState;

            if (blogAddress == null)
            {
                ModelResult <Blog> results = blogService.AddBlog(blogInput);

                validationState = results.ValidationState;

                if (results.IsValid)
                {
                    ////TODO: (erikpo) Get rid of HasMultipleBlogs and make it a calculated field so the following isn't necessary
                    //Site siteToEdit = siteService.GetSite(site.Name);

                    //siteToEdit.HasMultipleBlogs = true;

                    //siteService.EditSite(siteToEdit, out validationState);

                    if (validationState.IsValid)
                    {
                        OxiteApplication.Load(ControllerContext.HttpContext);
                    }
                }
            }
            else
            {
                ModelResult <Blog> results = blogService.EditBlog(blogAddress, blogInput);

                validationState = results.ValidationState;
            }

            if (!validationState.IsValid)
            {
                ModelState.AddModelErrors(validationState);

                return(ItemEdit(blogAddress));
            }

            return(Redirect(Url.AppPath(Url.Admin())));
        }
Example #13
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));
        }
Example #14
0
 public PostAddress(BlogAddress blogAddress, string postSlug)
     : this(blogAddress.BlogName, postSlug)
 {
 }
Example #15
0
        public virtual OxiteViewModelItem <Blog> ItemEdit(BlogAddress blogAddress)
        {
            Blog blog = blogAddress != null?blogService.GetBlog(blogAddress) : null;

            return(new OxiteViewModelItem <Blog>(blog));
        }
        public virtual OxiteViewModel ImportSave(BlogAddress blogAddress, string slugPattern)
        {
            Blog blog = blogService.GetBlog(blogAddress);

            if (blog == null)
            {
                return(null);
            }

            ValidationStateDictionary validationState = new ValidationStateDictionary();
            XmlTextReader             reader          = null;
            bool modifiedSite = false;

            try
            {
                reader = new XmlTextReader(Request.Files[0].InputStream);

                BlogMLBlog         blogMLBlog = BlogMLSerializer.Deserialize(reader);
                Language           language   = languageService.GetLanguage(context.Site.LanguageDefault);
                BlogInputForImport blogInput  = new BlogInputForImport(blogMLBlog.SubTitle, blogMLBlog.SubTitle, blogMLBlog.DateCreated);
                ModelResult <Blog> results    = blogService.EditBlog(blogAddress, blogInput);

                if (!results.IsValid)
                {
                    ModelState.AddModelErrors(results.ValidationState);

                    return(Import(blogAddress));
                }

                if (!context.Site.HasMultipleBlogs)
                {
                    Site site = siteService.GetSite();

                    site.DisplayName = blog.DisplayName;
                    site.Description = blog.Description;

                    siteService.EditSite(site, out validationState);

                    if (!validationState.IsValid)
                    {
                        throw new Exception();
                    }

                    modifiedSite = true;
                }

                postService.RemoveAll(blogAddress);

                foreach (BlogMLPost blogMLPost in blogMLBlog.Posts)
                {
                    if (string.IsNullOrEmpty(blogMLPost.Title) || string.IsNullOrEmpty(blogMLPost.Content.Text))
                    {
                        continue;
                    }

                    PostInputForImport postInput      = blogMLPost.ToImportPostInput(blogMLBlog, context.Site.CommentingDisabled | blog.CommentingDisabled, slugPattern, blogMLPost.Approved ? EntityState.Normal : EntityState.PendingApproval, context.User.Cast <UserAuthenticated>());
                    ModelResult <Post> addPostResults = postService.AddPost(blog, postInput);

                    if (!addPostResults.IsValid)
                    {
                        ModelState.AddModelErrors(addPostResults.ValidationState);

                        return(Import(blogAddress));
                    }

                    foreach (BlogMLComment blogMLComment in blogMLPost.Comments)
                    {
                        CommentInputForImport     commentInput      = blogMLComment.ToImportCommentInput(blogMLBlog, context.User.Cast <UserAuthenticated>(), language);
                        ModelResult <PostComment> addCommentResults = commentService.AddComment(addPostResults.Item, commentInput);

                        if (!addCommentResults.IsValid)
                        {
                            ModelState.AddModelErrors(addCommentResults.ValidationState);

                            return(Import(blogAddress));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelErrors(validationState);

                if (!string.IsNullOrEmpty(ex.Message))
                {
                    ModelState.AddModelError("ModelName", ex);
                }

                return(Import(blogAddress));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            if (modifiedSite)
            {
                OxiteApplication.Load(ControllerContext.HttpContext);
            }

            return(new OxiteViewModel {
                Container = blog
            });
        }
Example #17
0
 public ModelResult <Blog> EditBlog(BlogAddress blogAddress, BlogInputForImport blogInput)
 {
     return(editBlog(blogAddress, blogInput, b => b.Apply(blogInput)));
 }
Example #18
0
 public void RemoveAll(BlogAddress blogAddress)
 {
     repository.RemoveAllByBlog(context.Site.ID, blogAddress.BlogName);
 }
Example #19
0
 public IEnumerable <KeyValuePair <PostTag, int> > GetTagsUsedIn(BlogAddress blogAddress)
 {
     return(repository.GetTagsUsedInBlog(blogAddress.BlogName).ToArray());
 }
 public ContentResult Rsd(BlogAddress blogAddress)
 {
     return(Content(GenerateRsd(blogAddress).ToString(), "text/xml"));
 }