Пример #1
0
        public DocumentViewModel(IDialogService dialogService, ISettingsService settings)
        {
            this.dialogService = dialogService;
            this.settings = settings;

            title = "New Document";
            Original = "";
            Document = new TextDocument();
            post = new Post();
            timer = new DispatcherTimer();
            timer.Tick += TimerTick;
            timer.Interval = delay;
        }
Пример #2
0
        public DocumentViewModel(IDialogService dialogService, ISettingsService settings, IWindowManager windowManager, ISiteContextGenerator siteContextGenerator)
        {
            this.dialogService = dialogService;
            this.settings = settings;
            this.windowManager = windowManager;
            this.siteContextGenerator = siteContextGenerator;

            title = "New Document";
            Original = "";
            Document = new TextDocument();
            Post = new Post();
            timer = new DispatcherTimer();
            timer.Tick += TimerTick;
            timer.Interval = delay;
        }
 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 });
 }
Пример #8
0
        public void Publish(string postid, string postTitle, string[] categories, BlogSetting blog)
        {
            if (categories == null) categories = new string[0];

            var proxy = new MetaWeblog(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
                               };
                    newpost.postid = proxy.NewPost(blog.BlogInfo.blogid, blog.Username, blog.Password, newpost, true);

                    settings.Set(newpost.permalink, newpost);
                    settings.Save();
                }
                else
                {
                    newpost = proxy.GetPost(postid, blog.Username, blog.Password);
                    newpost.title = postTitle;
                    newpost.description = blog.Language == "HTML" ? renderBody : Document.Text;
                    newpost.categories = categories;
                    newpost.format = blog.Language;

                    proxy.EditPost(postid, blog.Username, blog.Password, newpost, true);

                    //Not sure what this is doing??
                    settings.Set(newpost.permalink, newpost);
                    settings.Save();
                }
            }
            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);
        }
Пример #9
0
        public void OpenFromWeb(Post post)
        {
            Post = post;
            title = post.permalink;
            Document.Text = post.description;
            Original = post.description;

            Update();
        }
Пример #10
0
        public void Publish(string postTitle, string[] categories, BlogSetting blog)
        {
            if (categories == null) categories = new string[0];

            var proxy = XmlRpcProxyGen.Create<IMetaWeblog>();
            ((IXmlRpcProxy)proxy).Url = blog.WebAPI;

            var newpost = new Post();

            var permalink = this.DisplayName.Split('.')[0] == "New Document"
                                ? postTitle
                                : this.DisplayName.Split('.')[0];

            if (newpost.postid != null && !string.IsNullOrWhiteSpace(newpost.postid.ToString()))
            {
                newpost = proxy.GetPost(newpost.postid.ToString(), blog.Username, blog.Password);
            }

            try
            {
                if (string.IsNullOrWhiteSpace(newpost.permalink))
                {
                    newpost = new Post
                               {
                                   permalink = permalink,
                                   title = postTitle,
                                   dateCreated = DateTime.Now,
                                   description = blog.Language == "HTML" ? RenderBody : Document.Text,
                                   categories = categories
                               };
                    newpost.postid = proxy.AddPost(blog.BlogInfo.blogid, blog.Username, blog.Password, newpost, true);

                    settings.Set(newpost.permalink, newpost);
                    settings.Save();
                }
                else
                {
                    newpost.title = postTitle;
                    newpost.description = blog.Language == "HTML" ? RenderBody : Document.Text;
                    newpost.categories = categories;

                    proxy.UpdatePost(newpost.postid.ToString(), blog.Username, blog.Password, newpost, true);

                    settings.Set(newpost.permalink, newpost);
                    settings.Save();
                }
            }
            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, "");
            }

            this.post = newpost;
            Original = Document.Text;
            title = postTitle;
            NotifyOfPropertyChange(() => DisplayName);
        }