Beispiel #1
0
		public static void Save(BlogPost post, string file) {
			post.LastModified = DateTime.UtcNow;

			XDocument doc = new XDocument(
				new XElement("post",
					new XElement("title", post.Title),
					new XElement("slug", post.Slug),
					new XElement("author", post.Author),
					new XElement("pubDate", post.PubDate.ToString("yyyy-MM-dd HH:mm:ss")),
					new XElement("lastModified", post.LastModified.ToString("yyyy-MM-dd HH:mm:ss")),
					new XElement("content", post.Content),
					new XElement("ispublished", post.IsPublished),
					new XElement("categories", string.Empty),
					new XElement("comments", string.Empty)
					));

			XElement categories = doc.XPathSelectElement("post/categories");
			foreach (string category in post.Categories) {
				categories.Add(new XElement("category", category));
			}

			XElement comments = doc.XPathSelectElement("post/comments");

			doc.Save(file);
		}
Beispiel #2
0
		public static BlogPost LoadPost(string file) {
			XElement doc = XElement.Load(file);

			BlogPost post = new BlogPost() {
				ID = Path.GetFileNameWithoutExtension(file),
				Title = ReadValue(doc, "title"),
				Author = ReadValue(doc, "author"),
				Content = ReadValue(doc, "content"),
				Slug = ReadValue(doc, "slug").ToLowerInvariant(),
				PubDate = DateTime.Parse(ReadValue(doc, "pubDate")),
				LastModified = DateTime.Parse(ReadValue(doc, "lastModified", DateTime.Now.ToString())),
				IsPublished = bool.Parse(ReadValue(doc, "ispublished", "true")),
			};

			return post;
		}