예제 #1
0
        /// <summary>
        /// Creates a draft post
        /// Called when creating a new post
        /// </summary>
        /// <param name="title">
        /// The Title
        /// </param>
        /// <param name="author">
        /// The Author
        /// </param>
        /// <param name="time">
        /// The Time
        /// </param>
        /// <param name="catID">
        /// Category ID
        /// </param>
        /// <returns>
        /// Draft Post
        /// </returns>
        public DraftPost Create(string title, string author, DateTime time, string catID)
        {
            DraftPost post = new DraftPost();

            post.FileID = string.Empty;
            DateTime now = LocalTime.GetCurrentTime(SettingsData.TimeZoneInfo);
            post.DraftID = DraftPost.GetNewDraftID(this.GetUniqueFileID(title), now);
            post.Time = time;
            post.CatID = catID;
            post.Title = title;
            post.Author = author;
            post.Type = PostType.New;

            string xmlTime = post.Time.ToString(DataContext.DateTimeFormat, CultureInfo.InvariantCulture);

            string template = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
            template +=
                "<Post Title=\"{0}\" FileID=\"{1}\" Author=\"{2}\" Time=\"{3}\" CatID=\"{4}\" Comments=\"0\" Type=\"New\">";
            template += "<Documents></Documents>";
            template += "<Content></Content>";
            template += "<Comments></Comments></Post>";

            string xml = string.Format(template, title, post.FileID, author, xmlTime, catID);

            XElement postElem = XElement.Parse(xml);

            string path = this.GetFilePath(post.DraftID);
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            XmlWriter writer = XmlWriter.Create(path, settings);
            postElem.Save(writer);
            writer.Close();

            DraftData draft = new DraftData();
            draft.Insert(post.DraftID, title);
            return post;
        }
예제 #2
0
 /// <summary>
 /// Creates draft post
 /// Called when editing a published post
 /// </summary>
 /// <param name="fileID">
 /// Post ID
 /// </param>
 /// <returns>
 /// Draft Post
 /// </returns>
 public DraftPost Create(string fileID)
 {
     PostData data = new PostData();
     Post post = data.Load(fileID);
     DraftPost draft = new DraftPost(post);
     DateTime now = LocalTime.GetCurrentTime(SettingsData.TimeZoneInfo);
     draft.DraftID = DraftPost.GetNewDraftID(fileID, now);
     this.Save(draft);
     DraftData data2 = new DraftData();
     data2.Insert(draft.DraftID, draft.Title);
     return draft;
 }