示例#1
0
        /// <summary>
        /// The unpublish.
        /// </summary>
        /// <param name="postInfo">
        /// The post info.
        /// </param>
        public static void Unpublish(PostInfo postInfo)
        {
            BlogComp.Delete(postInfo.FileID);
            if (postInfo.CatID != string.Empty)
            {
                string[] catIDs = postInfo.CatID.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string catID in catIDs)
                {
                    CategoryComp.Decrement(catID);
                }
            }

            ArchiveComp.Decrement(postInfo.Time.Month, postInfo.Time.Year);

            // Remove file
            Post post2 = PostComp.Load(postInfo.FileID);
            foreach (Comment comment in post2.Comments)
            {
                CommentComp.Delete(comment.ID);
            }

            PostComp.Delete(postInfo.FileID);
        }
示例#2
0
        /// <summary>
        /// Gets list of post items
        /// Called from home page
        /// Called from archive page
        /// Called from category page
        /// Called from post management page
        /// Caching disables frequent access
        /// </summary>
        /// <returns>List of Posts</returns>
        public List<PostInfo> GetBlogItems()
        {
            List<PostInfo> posts = new List<PostInfo>();

            XElement root = null;

            try
            {
                root = XElement.Load(this._path);
            }
            catch (Exception ex)
            {
                Logger.Log(NO_FILE_ERROR, ex);
                throw new ApplicationException(NO_FILE_ERROR, ex);
            }

            try
            {
                foreach (XElement blogElem in root.Elements("Post"))
                {
                    PostInfo post = new PostInfo();
                    post.Title = blogElem.Attribute("Title").Value;
                    if (blogElem.Attribute("Author") != null)
                    {
                        post.Author = blogElem.Attribute("Author").Value;
                    }

                    post.FileID = blogElem.Attribute("FileID").Value;
                    post.CatID = blogElem.Attribute("CatID").Value;

                    try
                    {
                        post.Time = DateTime.ParseExact(
                            blogElem.Attribute("Time").Value, DataContext.DateTimeFormat, CultureInfo.InvariantCulture);
                    }
                    catch (Exception ex)
                    {
                        string msg = string.Format(DATE_FORMAT_ERROR, post.FileID);
                        Logger.Log(msg, ex);
                        post.Time = DateTime.MinValue;
                    }

                    try
                    {
                        post.Views = int.Parse(blogElem.Attribute("Views").Value);
                    }
                    catch (Exception ex)
                    {
                        string msg = string.Format(VIEWS_FORMAT_ERROR, post.FileID);
                        Logger.Log(msg, ex);
                        post.Views = 1;
                    }

                    post.MonthID = blogElem.Attribute("MonthID").Value;
                    posts.Add(post);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(XML_FORMAT_ERROR, ex);
                throw new ApplicationException(XML_FORMAT_ERROR, ex);
            }

            return posts;
        }
示例#3
0
        /// <summary>
        /// Creates a new post node for published posts
        /// Called at the time of publishing a post
        /// </summary>
        /// <param name="postInfo">
        /// The PostInfo
        /// </param>
        public void Create(PostInfo postInfo)
        {
            XElement root = null;

            try
            {
                root = XElement.Load(this._path);
            }
            catch (Exception ex)
            {
                Logger.Log(NO_FILE_ERROR, ex);
                throw new ApplicationException(NO_FILE_ERROR, ex);
            }

            var qry = from elem in root.Elements("Post")
                      where elem.Attribute("FileID").Value == postInfo.FileID
                      select elem;

            if (qry.Count<XElement>() > 0)
            {
                Logger.Log(DUP_POST_ERROR);
                throw new ApplicationException(DUP_POST_ERROR);
            }

            XElement postElem = new XElement(
                "Post",
                new XAttribute("Title", postInfo.Title),
                new XAttribute("FileID", postInfo.FileID),
                new XAttribute("Author", postInfo.Author),
                new XAttribute("CatID", postInfo.CatID),
                new XAttribute("MonthID", postInfo.MonthID),
                new XAttribute("Time", postInfo.Time.ToString(DataContext.DateTimeFormat, CultureInfo.InvariantCulture)),
                new XAttribute("Views", 1));

            try
            {
                bool lastNode = true;
                foreach (XElement refElem in root.Elements("Post"))
                {
                    DateTime refDate;
                    try
                    {
                        refDate = DateTime.ParseExact(
                            refElem.Attribute("Time").Value, DataContext.DateTimeFormat, CultureInfo.InvariantCulture);
                    }
                    catch (Exception ex)
                    {
                        string msg = string.Format(DATE_FORMAT_ERROR, refElem.Attribute("FileID").Value);
                        Logger.Log(msg, ex);
                        refDate = DateTime.MaxValue;
                    }

                    if (postInfo.Time > refDate)
                    {
                        refElem.AddBeforeSelf(postElem);
                        lastNode = false;
                        break;
                    }
                }

                if (lastNode)
                {
                    root.Add(postElem);
                }

                // root.Save(_path);
                XmlHelper.Save(root, this._path);
            }
            catch (Exception ex)
            {
                Logger.Log(XML_FORMAT_ERROR, ex);
                throw new ApplicationException(XML_FORMAT_ERROR, ex);
            }
        }
示例#4
0
 /// <summary>
 /// The update post.
 /// </summary>
 /// <param name="post">
 /// The post.
 /// </param>
 private static void UpdatePost(DraftPost post)
 {
     if (post.Type == PostType.New)
     {
         PostInfo postInfo = new PostInfo();
         postInfo.FileID = post.FileID;
         postInfo.Author = post.Author;
         postInfo.Title = post.Title;
         postInfo.CatID = post.CatID;
         postInfo.Time = post.Time;
         BlogComp.Create(postInfo);
     }
     else
     {
         BlogComp.Update(post.FileID, post.Title, post.CatID);
     }
 }
示例#5
0
 /// <summary>
 /// The create.
 /// </summary>
 /// <param name="postInfo">
 /// The post info.
 /// </param>
 public static void Create(PostInfo postInfo)
 {
     IBlogData data = ConfigHelper.DataContext.BlogData;
     data.Create(postInfo);
 }
示例#6
0
        /// <summary>
        /// Gets list of scheduled draft entries
        /// Called by scheduled publisher service
        /// </summary>
        /// <returns>List of draft entries</returns>
        public List<PostInfo> GetScheduledDraftItems()
        {
            List<PostInfo> posts = new List<PostInfo>();

            XElement root = null;

            try
            {
                root = XElement.Load(this._path);
            }
            catch (Exception ex)
            {
                Logger.Log(NO_FILE_ERROR, ex);
                throw new ApplicationException(NO_FILE_ERROR, ex);
            }

            var qry = from elem in root.Elements("Draft") where elem.Attribute("Scheduled") != null select elem;

            try
            {
                foreach (XElement draftElem in qry)
                {
                    PostInfo post = new PostInfo();
                    post.Title = draftElem.Attribute("Title").Value;
                    post.FileID = draftElem.Attribute("FileID").Value;

                    try
                    {
                        post.Time = DateTime.ParseExact(
                            draftElem.Attribute("Scheduled").Value,
                            DataContext.DateTimeFormat,
                            CultureInfo.InvariantCulture);
                    }
                    catch (Exception ex)
                    {
                        string msg = string.Format(DATE_FORMAT_ERROR, post.FileID);
                        Logger.Log(msg, ex);
                        post.Time = DateTime.MaxValue;
                    }

                    posts.Add(post);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(XML_FORMAT_ERROR, ex);
                throw new ApplicationException(XML_FORMAT_ERROR, ex);
            }

            return posts;
        }