public DocumentViewModel(
            IDialogService dialogService,
            IWindowManager windowManager,
            ISiteContextGenerator siteContextGenerator,
            Func<string, IMetaWeblogService> getMetaWeblog,
            ISettingsProvider settingsProvider,
            IDocumentParser documentParser)
        {
            this.dialogService = dialogService;
            this.windowManager = windowManager;
            this.siteContextGenerator = siteContextGenerator;
            this.getMetaWeblog = getMetaWeblog;
            this.settingsProvider = settingsProvider;
            this.documentParser = documentParser;

            FontSize = GetFontSize();

            title = "New Document";
            Original = "";
            Document = new TextDocument();
            Post = new Post();
            timer = new DispatcherTimer();
            timer.Tick += TimerTick;
            timer.Interval = delay;
        }
        public void Publish(string postid, string postTitle, string[] categories, BlogSetting blog)
        {
            if (categories == null) categories = new string[0];

            var proxy = getMetaWeblog(blog.WebAPI);

            var newpost = new Post();
            try
            {
                var renderBody = DocumentParser.GetBodyContents(Document.Text);

                if (string.IsNullOrWhiteSpace(postid))
                {
                    var permalink = DisplayName.Split('.')[0] == "New Document"
                                ? postTitle
                                : DisplayName.Split('.')[0];

                    newpost = new Post
                               {
                                   permalink = permalink,
                                   title = postTitle,
                                   dateCreated = DateTime.Now,
                                   description = blog.Language == "HTML" ? renderBody : Document.Text,
                                   categories = categories,
                                   format = blog.Language
                               };
                    newpost.postid = proxy.NewPost(blog, newpost, true);
                }
                else
                {
                    newpost = proxy.GetPost(postid, blog);
                    newpost.title = postTitle;
                    newpost.description = blog.Language == "HTML" ? renderBody : Document.Text;
                    newpost.categories = categories;
                    newpost.format = blog.Language;

                    proxy.EditPost(postid, blog, newpost, true);
                }
            }
            catch (WebException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }
            catch (XmlRpcException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }
            catch (XmlRpcFaultException ex)
            {
                dialogService.ShowError("Error Publishing", ex.Message, "");
            }

            Post = newpost;
            Original = Document.Text;
            title = postTitle;
            NotifyOfPropertyChange(() => DisplayName);
        }
        public void OpenFromWeb(Post post)
        {
            Post = post;

            title = post.permalink ?? string.Empty; // TODO: no title is displayed now
            Document.Text = post.description ?? string.Empty;
            Original = post.description ?? string.Empty;

            Update();
            EvaluateContext();
        }
        public void OpenFromWeb(Post post)
        {
            Post = post;

            title = post.title ?? string.Empty;
            Document.Text = post.description ?? string.Empty;
            Original = post.description ?? string.Empty;

            Update();
            EvaluateContext();
        }
 public Task<bool> EditPostAsync(string postid, string username, string password, Post post, bool publish)
 {
     return Task<bool>.Factory.FromAsync(BeginEditPost(postid, username, password, post, publish, null, null), EndEditPost);
 }
 public bool EditPost(string postid, string username, string password, Post post, bool publish)
 {
     return (bool)Invoke("EditPost", new object[] { postid, username, password, post, publish });
 }
 public IAsyncResult BeginNewPost(string blogid, string username, string password, Post post, bool publish, AsyncCallback callback, object asyncState)
 {
     return BeginInvoke("NewPost", new object[] { blogid, username, password, post, publish }, this, callback, asyncState);
 }
 public Task<string> NewPostAsync(string blogid, string username, string password, Post post, bool publish)
 {
     return Task<string>.Factory.FromAsync(BeginNewPost(blogid, username, password, post, publish, null, null), EndNewPost);
 }
 public string NewPost(string blogid, string username, string password, Post post, bool publish)
 {
     return (string)Invoke("NewPost", new object[] { blogid, username, password, post, publish });
 }