Example #1
0
        private void CreateAndPublish(Post p)
        {
            var stream = getStream();

            if (stream != null)
            {
                var cs = new ContentService();
                int postId;
                IContent post;

                if (TryGetPostId(p, out postId))
                    post = cs.GetById(postId);
                else
                {
                    var parent = createFolderScructure(p.Date, stream);
                    post = cs.CreateContent(p.Name, parent, PostTypeAlias);
                }

                MarkdownSharp.Markdown md = new Markdown();
                post.SetValue("bodyText", md.Transform(p.Content));

               post.SetValue("postDate", p.Date);

                if (p.Draft)
                    cs.Save(post);
                else
                    cs.SaveAndPublish(post);
            }
        }
Example #2
0
 public void Delete(Post p)
 {
     int id;
     if (TryGetPostId(p, out id))
     {
         var cs = new ContentService();
         var post = cs.GetById(id);
         cs.UnPublish(post);
         cs.Delete(post);
     }
 }
Example #3
0
        private static string GetName(Post p, bool hasDate)
        {
            var name = p.FileName;

            if (p.Draft)
                name = name.Remove(name.Length - 9);
            else
                name = name.Remove(name.Length - 3);

            if (hasDate)
                name = name.Substring(11);

            name = name.Replace('-', ' ');
            return name;
        }
Example #4
0
        public static Post Convert(FileInfo fi)
        {
            var p = new Post();
            p.FileName = fi.Name;
            p.Draft = p.FileName.ToLower().EndsWith(".draft.md");

            DateTime _d;
            bool hasDate = true;
            if (p.FileName.Length > 10 && DateTime.TryParse(p.FileName.Substring(0, 10), out _d))
                p.Date = _d;
            else
            {
                p.Date = DateTime.Now;
                hasDate = false;

            }
            p.Name = GetName(p, hasDate);
            var s = fi.OpenText();
            p.Content = s.ReadToEnd();
            s.Close();

            return p;
        }
Example #5
0
 public void ProcessPost(Post p)
 {
     if(!p.Draft)
         CreateAndPublish(p);
 }
Example #6
0
 public bool Exists(Post p)
 {
     int id;
     return TryGetPostId(p, out id);
 }
Example #7
0
        private bool TryGetPostId(Post p, out int id)
        {
            id = 0;
            var stream = getStream();

            if (stream == null)
                return false;

            var post = stream.Descendants(PostTypeAlias).Where(x => x.Name == p.Name).FirstOrDefault();
            if (post == null)
                return false;

            id = post.Id;
            return true;
        }