Archive for July, 2009

Windows 7 – Sticky Notes

This is a sticky note!

image 

This is something I will use all the time!

Windows 7 has a feature called “Sticky Notes” – basically, these little notes are like post it notes – they stick to your desktop!

You can change the colour, resize, move them around etc… So simple, yet so useful!

How to get Messenger to run in the TaskBar in Windows 7

After installing the Windows 7 RC, I installed the latest Windows Live Messenger.
After using it, it appears that it does not run in the task bar, as it used to in Vista! This is pretty annoying, as I only keep it open to use now and again.

There is a way around this however… you need to set it to run in Compatibility Mode for Windows Vista.

To do this, first exit Messenger, then locate msnmsgr.exe (in your Program Files directory)
Right click it, select Properties

image

Choose the Compatibility tab, and select Windows Vista.

image

Hit ok, and then restart Live Messenger.

It now runs in the notification area!

Windows Azure Pricing Announced

Microsoft has finally released their pricing model for the forthcoming Windows Azure

Windows Azure:

  • Compute = $0.12 / hour
  • Storage = $0.15 / GB stored / month
  • Storage Transactions = $0.01 / 10K
  • Bandwidth = $0.10 in / $0.15 out / GB

SQL Azure:

  • Web Edition – Up to 1 GB relational database = $9.99
  • Business Edition – Up to 10 GB relational database = $99.99
  • Bandwidth = $0.10 in / $0.15 out / GB

.Net Services:

  • Messages = $0.15/100K message operations , including Service Bus messages and Access Control tokens
  • Bandwidth = $0.10 in / $0.15 out / GB

Further details available from:
http://www.microsoft.com/azure/pricing.mspx

Using JoeBlogs -metaWeblog API Wrapper

Step 1

Download the latest release of JoeBlogs from Codeplex
(Click the Downloads tab, and select the latest download)

Step 2

Unzip the contents of the downloaded zip file.
(I usually copy DLLs I am going to use into a “lib” folder at the root of my solution)

Step 3


Add a reference to BOTH CookComputing.XmlRpcV2.dll AND JoeBlogs.dll

image

Include AlexJamesBrown.JoeBlogs in your class, with using / Imports:

C#

using AlexJamesBrown.JoeBlogs;

VB

Imports AlexJamesBrown.JoeBlogs

Step 4:

Instantiate a new Wrapper object.

So far, the available wrappers are:

MetaWeblogWrapper

WordPressWrapper

C#

WordPressWrapper wrapper = new WordPressWrapper(Url, Username, Password);

VB

Dim wrapper As New WordPressWrapper(Url, Username, Password)

Please note -

The above example has the Url, Username and Password strings omitted. Simply replace them with the relevant information.

Step 5

You can now take full advantage of all the methods on your instantiated wrapper.

C#

string Url = "www.alexjamesbrown.com";
string User = "MyUser"; //enter your username
string Password = "MyPassword"; //enter your password

var wp = new WordPressWrapper(Url, User, Password);

//a few test functions...
var userBlogs = wp.GetUserBlogs();
var tags = wp.GetTags();
var categories = wp.GetCategories();

var authors = wp.GetAuthors();

Why Are Interfaces Useful?

Interfaces, usually prefixed by “I” are useful in software engineering, for a number of reasons.
Primarily, they allow you to create “pluggable” code.
By this, I mean that your code is easier to manage, easier to maintain, easier to change the way certain parts of your application work, without changing the entire way it works.

Lets look at an example.

Our application is an photo sharing web application, allowing users to view and upload photos.
The main functions of the site, are handled by our ImageManager class. This facilitates the retrieval, and storing of images. Fairly integral to the application.

As we are designing our application using SoC (Separation of Concerns), all our ImageManager class will do, is get, or put images. (in reality, we should really have a separate concern for each operation – get & put)
It doesn’t care about storing user details or meta data, against the image in a database, nor does it care about checking to see if a user can view that image or anything like that.
It purely puts, or gets, an image.

Now. this operation sounds simple, to get an image, I just need to connect to my file store, and retrieve my image?
Yes. But what if, one day, you need to be able to switch where you store your images.
For example..on day 1, you are storing your images on the file system, in a directory within your web application project.
This works fine, especially during beta testing, however as demand grows, the strain on your server and your bandwidth become a problem, and you need to change where images are stored.

You also want to be able to use a storage service, such as Amazon S3 to store your images.
(I’m not going to go into how S3 or any other service works in this article, it’s just an example.)

Luckily, we have a couple of ImageManagers….
FileSystemImageManager, and S3ImageManager

Both of which, implement our interface – IImageManager (notice the prefix "I”)

Here’s the interface:

C#

public interface IImageManager
{
  void PutImage(Image image, string fileName);
  Image GetImage(string fileName);
}

VB

Public Interface IImageManager
  Sub PutImage(ByVal image As Image, ByVal fileName As String)
  Function GetImage(ByVal fileName As String) As Image
End Interface

Note the empty method signatures…

Interfaces contain no logic – they are simply a contract that each implementation agrees to follow.

So lets have a look at an implementation of IImageManager:

C#

public class FileSystemImageManager : IImageManager
{
  public void PutImage(Image image, string fileName)
  {
    //code to save the image on the file system
  }

  public Image GetImage(string fileName)
  {
    //code to get the image from the file system
  }
}

VB

Public Class FileSystemImageManager
    Implements IImageManager
    Public Sub PutImage(ByVal image As Image, ByVal fileName As String)
        'code to save the image on the file system
    End Sub

    Public Function GetImage(ByVal fileName As String) As Image
        'code to get the image from the file system
    End Function
End Class

The FileSystemImageManager implements IImageManager (indicated by the : in c#)

note, in visual studio, you can right on your interface implementation declaration and select Implement Interface – this will create the required method signatures within your class.

Implement Interface

Our class now conforms to IImageManager.

But – there’s no code! That doesnt technically matter.

As long as you’ve implemented each method (even by throwing a NotImplementedException), your class will compile.

So what’s the point?

Well, we now have a FileSystemImageManager class, that (after you’ve added your code) gets and puts images on the file system.

In our application, we can do something like:

C#

      //get the image:
      IImageManager imageManager = new FileSystemImage();
      var image = imageManager.GetImage("my_filename");

VB

'get the image:
Dim imageManager As IImageManager = New FileSystemImage()
Dim image = imageManager.GetImage("my_filename")

“Great” you say….

But that means you can “swap out” your functionality, really easily.

Instead of declaring imageManager as a new FileSystemImage() we could have another class, that implements IImageManager called “FlickrImage”

This could then use Flickr to get and put images (obviously additional functionality would be required to authenticate against Flickr API)

I’ll expand this tutorial at a later stage to explain how to effectively use config, factory patterns, IoC etc…