Translate

Tuesday, 5 August 2014

Patterns and nuts!

Ask yourself this - Why do they always put a nut in a place where the spanner cannot reach it? - when you find the problem and the design pattern not matching.

All problems could be the same. It is only the context, the domain, the applicability, the robustness that the solution must be subject to, the experience and maturity of the solution provider that make problems unique and different.

A psycho's reactions can be easily simulated in a child and for those to whom the child is not visible, from afar or through heresy or by reading about it, both will seem the same. It is this knowledge that is important to make decisions and not whether the similarity of actions with a psycho makes a child a psycho nor whether the psycho is a child.

This knowledge, the ability to dwell deep to the real core of a problem, is what is necessary to know where designs emerge and which design patterns to decide on.

Tuesday, 15 July 2014

Blogger post from ASP.Net

Sample post! It looks like setting a draft post to false on the AtomEntry object does not work or it is simply a matter of providing the postId alongwith the blogId and not setting the URL to default feeds.

Below is the code: (you can use NUGet to install the Google API into your VS project)

using System;
using Google.GData.Client;
using System.Web.UI;

namespace BloggerPost
{
    public partial class _Default : Page
    {
        string blogId = ""; // This id will be part of the query string in your browser address bar when you access your blog
        string username;
        string password;
        private void PostOrUpdateBlogPost(string yourBlogId,bool isUpdate)
        {
            if (yourBlogId != null)
            {
                var service = new Google.GData.Client.Service("","Application Name");
                service.Credentials = new GDataCredentials(username, password);
                AtomEntry newPost = null;
                if (isUpdate)
                {
                    try
                    {
                        // need to correct the URL here
                        newPost = service.Get(yourBlogId);
                        newPost.Categories.Clear();
                        // Setting the isDraft property requires the above URL to contain the postId (need to confirm test this).
                        if (newPost.IsDraft) newPost.IsDraft = false;
                    }
                    catch (Exception ex)
                    {

                    }
                }
                else
                {
                    newPost = new AtomEntry();
                    newPost.Title.Text = "Blogger post from ASP.Net";
                    newPost.Content = new AtomContent();
                    newPost.Content.Content = "Sample post! It looks like setting a draft post to false on the AtomEntry object does not work or it is simply a matter of providing the postId alongwith the blogId and not setting the URL to default feeds.";
                    newPost.Content.Type = "html";
                }
             
                try
                {
                    if (!isUpdate)
                    {
                        Uri blogPostUri = new Uri("http://www.blogger.com/feeds/" + yourBlogId + "/posts/default");
                        newPost = service.Insert(blogPostUri, newPost);
                    }
                    else
                    {
                        newPost = newPost.Update();
                    }
                }
                catch (Exception ex)
                {              
                }
            }
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PostOrUpdateBlogPost(blogId,false); // the boolean is to specify if it is a new post or an update.
            }
        }
 
    }
}

Publishing a post using the Google API for Blogger!

It is not as easy as many have posted on the web! Many posts indicate that all you need to do

is send in your credentials to the service object. Not as simple as that !

Blogger API Post


This post was created with the Blogger API v3