Exemplo n.º 1
0
        /// <summary>
        /// Save a new post to file. Replaces existing Posts.
        /// </summary>
        /// <param name="post">The post to save</param>
        /// <returns>The bool result of the save operation</returns>
        public static bool SavePost(Episode post)
        {
            try
            {
                var filePath = Path.Combine(_folder + post.Id + ".webinfo");

                var savePost = new XDocument(
                    new XElement("post",
                                 new XElement("title", post.Title),
                                 new XElement("id", post.Id),
                                 new XElement("published_date", post.PostedTime.ToString("yyyy-MM-dd HH:mm:ss")),
                                 new XElement("excerpt", post.MetaDescEpisode),
                                 new XElement("content", post.BodyHtml),
                                 new XElement("markdown_content", post.BodyMarkdown),
                                 new XElement("dont_index", post.DontIndexEpisode.ToString()),
                                 new XElement("embed_url", post.EmbedUrl)
                                 ));

                //save to file
                savePost.Save(filePath);

                //add to cache (or update if exists)
                MemoryCache.AddPost(post);

                return(true);
            }
            catch
            {
                //dont care really, will go into below
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save a new post to file. Replaces existing Posts.
        /// </summary>
        /// <param name="post">The post to save</param>
        /// <returns>The bool result of the save operation</returns>
        public static bool SavePost(Post post)
        {
            //make sure we have it first
            EnsureFolder(post.PostedTime.Year);

            try
            {
                //clean up the categories
                var sb = new StringBuilder();
                if (!string.IsNullOrWhiteSpace(post.Categories))
                {
                    var skipFirst = false;
                    foreach (var category in post.Categories.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        sb.Append((skipFirst ? "," : "") + category.Trim());
                        skipFirst = true;
                    }
                }

                var filePath = Path.Combine(_folder + post.PostedTime.Year + "/", post.Slug + ".webinfo");

                var savePost = new XDocument(
                    new XElement("post",
                                 new XElement("title", post.Title),
                                 new XElement("slug", post.Slug),
                                 new XElement("published_date", post.PostedTime.ToString("yyyy-MM-dd HH:mm:ss")),
                                 new XElement("excerpt", post.MetaDescPost),
                                 new XElement("read_time", post.ReadTime),
                                 new XElement("content", post.BodyHtml),
                                 new XElement("markdown_content", post.BodyMarkdown),
                                 new XElement("dont_index", post.DontIndexPost.ToString()),
                                 new XElement("categories", sb.ToString())
                                 ));

                //save to file
                savePost.Save(filePath);

                //add to cache (or update if exists)
                MemoryCache.AddPost(post);

                return(true);
            }
            catch
            {
                //dont care really, will go into below
            }

            return(false);
        }