Ejemplo n.º 1
0
		public static void Serialize(PostInfo[] posts, string filename)
		{
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(PostInfo[]));
			StreamWriter streamWriter = new StreamWriter(filename);
			xmlSerializer.Serialize(streamWriter, posts);
			streamWriter.Close();
		}
Ejemplo n.º 2
0
        public async Task <PostInfo> GetPostAsync(string postid)
        {
            Service    service    = new Service(this.BlogConnectionInfo.MetaWeblogURL);
            MethodCall methodCall = new MethodCall("metaWeblog.getPost");

            methodCall.Parameters.Add(postid);
            methodCall.Parameters.Add(this.BlogConnectionInfo.Username);
            methodCall.Parameters.Add(this.BlogConnectionInfo.Password);
            service.Cookies = this.BlogConnectionInfo.Cookies;
            MethodResponse methodResponse = await service.ExecuteAsync(methodCall);

            Value    value    = methodResponse.Parameters[0];
            Struct   @struct  = (Struct)value;
            PostInfo postinfo = new PostInfo();

            postinfo.PostID      = @struct.Get <StringValue>("postid").String;
            postinfo.Description = @struct.Get <StringValue>("description").String;
            postinfo.Link        = @struct.Get <StringValue>("link", StringValue.NullString).String;
            postinfo.DateCreated = new DateTime?(@struct.Get <DateTimeValue>("dateCreated").Data);
            postinfo.PermaLink   = @struct.Get <StringValue>("permaLink", StringValue.NullString).String;
            postinfo.PostStatus  = @struct.Get <StringValue>("post_status", StringValue.NullString).String;
            postinfo.Title       = @struct.Get <StringValue>("title").String;
            postinfo.UserID      = @struct.Get <StringValue>("userid", StringValue.NullString).String;
            XmlRPC.Array source = @struct.Get <global::CloudNotes.DesktopClient.Extensions.Blog.MetaWeblogSharp.XmlRPC.Array>("categories");
            source.ToList <Value>().ForEach(delegate(Value i)
            {
                if (i is StringValue)
                {
                    string @string = (i as StringValue).String;
                    if (@string != "" && !postinfo.Categories.Contains(@string))
                    {
                        postinfo.Categories.Add(@string);
                    }
                }
            });
            return(postinfo);
        }
Ejemplo n.º 3
0
 public async Task <string> NewPostAsync(PostInfo pi, IList <string> categories, bool publish)
 {
     return(await this.NewPostAsync(pi.Title, pi.Description, categories, publish, pi.DateCreated));
 }
Ejemplo n.º 4
0
		public async Task<PostInfo> GetPostAsync(string postid)
		{
			Service service = new Service(this.BlogConnectionInfo.MetaWeblogURL);
			MethodCall methodCall = new MethodCall("metaWeblog.getPost");
			methodCall.Parameters.Add(postid);
			methodCall.Parameters.Add(this.BlogConnectionInfo.Username);
			methodCall.Parameters.Add(this.BlogConnectionInfo.Password);
			service.Cookies = this.BlogConnectionInfo.Cookies;
			MethodResponse methodResponse = await service.ExecuteAsync(methodCall);
			Value value = methodResponse.Parameters[0];
			Struct @struct = (Struct)value;
			PostInfo postinfo = new PostInfo();
			postinfo.PostID = @struct.Get<StringValue>("postid").String;
			postinfo.Description = @struct.Get<StringValue>("description").String;
			postinfo.Link = @struct.Get<StringValue>("link", StringValue.NullString).String;
			postinfo.DateCreated = new DateTime?(@struct.Get<DateTimeValue>("dateCreated").Data);
			postinfo.PermaLink = @struct.Get<StringValue>("permaLink", StringValue.NullString).String;
			postinfo.PostStatus = @struct.Get<StringValue>("post_status", StringValue.NullString).String;
			postinfo.Title = @struct.Get<StringValue>("title").String;
			postinfo.UserID = @struct.Get<StringValue>("userid", StringValue.NullString).String;
			XmlRPC.Array source = @struct.Get<global::CloudNotes.DesktopClient.Extensions.Blog.MetaWeblogSharp.XmlRPC.Array>("categories");
			source.ToList<Value>().ForEach(delegate(Value i)
			{
				if (i is StringValue)
				{
					string @string = (i as StringValue).String;
					if (@string != "" && !postinfo.Categories.Contains(@string))
					{
						postinfo.Categories.Add(@string);
					}
				}
			});
			return postinfo;
		}
Ejemplo n.º 5
0
		public async Task<string> NewPostAsync(PostInfo pi, IList<string> categories, bool publish)
		{
			return await this.NewPostAsync(pi.Title, pi.Description, categories, publish, pi.DateCreated);
		}
Ejemplo n.º 6
0
        /// <summary>
        /// Executes the current extension.
        /// </summary>
        /// <param name="shell">The <see cref="IShell" /> object on which the current extension will be executed.</param>
        protected async override void DoExecute(IShell shell)
        {
            if (shell.HasActiveDocument)
            {
                await SafeExecutionContext.ExecuteAsync((Form) shell.Owner, async () =>
                {
                    var blogSetting = this.SettingProvider.GetExtensionSetting<BlogSetting>();
                    if (string.IsNullOrEmpty(blogSetting.MetaWeblogAddress) ||
                        string.IsNullOrEmpty(blogSetting.UserName) ||
                        string.IsNullOrEmpty(blogSetting.Password))
                    {
                        MessageBox.Show(Resources.MissingBlogConfigurationMsg, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    var gateway = new BlogGateway(blogSetting.MetaWeblogAddress, blogSetting.UserName,
                        blogSetting.Password);
                    if (await gateway.TestConnectionAsync())
                    {
                        var blogPublishDialog = new FrmBlogPublish(gateway);
                        if (blogPublishDialog.ShowDialog() == DialogResult.OK)
                        {
                            var selectedCategories = blogPublishDialog.SelectedCategories.Select(s => s.Title).ToList();
                            var postInfo = new PostInfo
                            {
                                Categories = selectedCategories,
                                DateCreated = DateTime.Now,
                                Description =
                                    HtmlUtilities.Tidy(HtmlUtilities.ReplaceFileSystemImages(shell.Note.Content)),
                                Title = shell.Note.Title
                            };
                            await gateway.PublishBlog(postInfo, selectedCategories);
                            shell.StatusText = Resources.PublishSucceeded;
                        }
                    }
                    else
                    {
                        MessageBox.Show(Resources.BlogExtensionCannotConnectToBlogService, Resources.Error,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                });
            }
            else
            {
                MessageBox.Show(Resources.NoActiveNoteOpened, Resources.Error, MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }