Subtext.Framework.XmlRpc.MetaWeblog.PostContent C# (CSharp) Method

PostContent() private method

private PostContent ( string username, string password, Subtext.Framework.XmlRpc.Post &post, bool publish, PostType postType ) : string
username string
password string
post Subtext.Framework.XmlRpc.Post
publish bool
postType PostType
return string
        private string PostContent(string username, string password, ref Post post, bool publish, PostType postType)
        {
            Framework.BlogInfo info = Config.CurrentBlog;
            ValidateUser(username, password, info.AllowServiceAccess);

            Entry entry = new Entry(postType);
            entry.Author = info.Author;
            entry.Email = info.Email;
            entry.Body = post.description;
            entry.Title = post.title;
            entry.Description = string.Empty;

            //TODO: Figure out why this is here.
            //		Probably means the poster forgot to set the date.

            DateTime dateTimeInPost = Config.CurrentBlog.TimeZone.ToLocalTime(post.dateCreated);
            var lastEntryDate = DbProvider.Instance().GetLatestEntryDate();

            if (dateTimeInPost.Year >= 2003)
            {
                // this is an indication that we want to move the rest of the posts
                if (dateTimeInPost.AddHours(-1) <= Config.CurrentBlog.TimeZone.Now)
                {
                    DbProvider.Instance().PushOtherPostsDatesAfter(dateTimeInPost);
                }
                entry.DateCreated = dateTimeInPost;
                entry.DateModified = dateTimeInPost;
            }
            else
            {

                if (lastEntryDate == null) // there is no next entry date
                {
                    entry.DateCreated = Config.CurrentBlog.TimeZone.Now;
                }
                else if (lastEntryDate.Value.AddDays(1) < Config.CurrentBlog.TimeZone.Now) // the latest date it too far in the past
                {
                    entry.DateCreated = Config.CurrentBlog.TimeZone.Now;
                }
                else
                {
                    // noon the next day
                    entry.DateCreated = lastEntryDate.Value.Date.AddDays(1).AddHours(12);
                    entry.Body = "<blockquote>Originally posted at " + Config.CurrentBlog.TimeZone.Now.ToShortDateString() +
                        "</blockquote>" + entry.Body;
                }
                entry.DateModified = entry.DateCreated;
            }

            if (post.categories != null)
            {
                entry.Categories.AddRange(post.categories);
            }

            if (!string.IsNullOrEmpty(post.wp_slug))
            {
                entry.EntryName = post.wp_slug;
            }

            entry.PostType = postType;

            entry.IsActive = publish;
            if (publish)
            {
                entry.DateSyndicated = entry.DateCreated;
            }
            entry.AllowComments = true;
            entry.DisplayOnHomePage = true;
            entry.IncludeInMainSyndication = true;
            entry.IsAggregated = true;
            entry.SyndicateDescriptionOnly = false;

            int postID;
            try
            {
                postID = Entries.Create(entry);

                if (!string.IsNullOrEmpty(post.enclosure.url))
                {
                    Components.Enclosure enc = new Components.Enclosure();
                    enc.Url = post.enclosure.url;
                    enc.MimeType = post.enclosure.type;
                    enc.Size = post.enclosure.length;
                    enc.EntryId = postID;
                    Enclosures.Create(enc);
                }

                AddCommunityCredits(entry);
            }
            catch (Exception e)
            {
                throw new XmlRpcFaultException(0, e.Message + " " + e.StackTrace);
            }
            if (postID < 0)
            {
                throw new XmlRpcFaultException(0, "The post could not be added");
            }
            return postID.ToString(CultureInfo.InvariantCulture);
        }