Launching your EC2 instances with AWS Management Console

Posted by admin | Posted in Cloud Computing | Posted on 29-04-2009

1

How easy this can get, when I was starting with Amazon Web Services the things were looking kind of scary but right now we have bunch of tools to help us using the amazon EC2 instances so easy that I just cannot belive that. I knew that AWS Management console existed for quite a bit now but never actually gave it a try. Today I will do just that, I have some experience with EC2 and I’m running constantly one server on it for over a half a year now but I guess this tutorial would be no brainer and you don’t have to have any knowledge or experience to start your own instances.
First of all, of course, I assume that you are already signed up for EC2. If not you can do that by visiting this link.
Once you have an account go to the console web application which you can find here. When you log in you should see a screen similar to this one:

amazon aws console

Next, click on the ‘Amazon EC2′ tab and you should see a dashboard describing your running instances and resources.

amazon aws console dashboard

If you are here, and all went well, we are ready to move forward.
Click on the big yellowish button called ‘Launch instances’ in the middle of the screen to start the journey into the cloud. Here you get a box with three tabs where you can look for specific instances you are interested in. You can choose between ‘Quick Start’ listing a few example AMIs, select your own instances created earlier (see my post on backup up the whole EC2 image), or simply search for already created community AMIs. We will choose the last option and search for ‘ubuntu’ but its really your choice and here the fun begins. I have choosen Debian 5.0 Lenny base install image but you can choose whatever you want. Its worth to have a look at the following site where you can browse AMIs, see a bit more information about them than on the AWS Management Console and see the discussion about them.
After you’ve decided which server you want to have, click ’select’. If you didn’t have any keypairs created earlier you would have to add at least one to be able to launch your instance.
Select number of instances you want to run (we choose ‘1′ for now), your keypair and security group on the following screen:

launch ec2 instance

Hit ‘Launch’, you will see the following screen if all went ok:

ec2 launched from AWS console

Close the window and go to your instances list by clicking ‘Instances’ on the left vertical menu.

capture6

From here you can reboot and shut down your instances.

But wait, the best part is still to come, when you are on your console ‘Overview’ tab, you can see the ‘Coming Soon’ part describing upcoming functionalites for AWS Console, those include:

  • Monitoring, Load balancing and auto scaling
  • SQS support
  • S3 Support
  • CloudFront Support
  • SimpleDB Support

Amazon AWS services are becoming more and more interesting and if you haven’t already done so, I assure you that its worth checking out.

Windows Forms application with Splash Screen

Posted by admin | Posted in Code Snippets | Posted on 28-04-2009

0

Today I will describe how to add simple yet effective splash screen functionality using Visual Basic assembly goodness. To show exactly how to do that I will create a simple project describing step by step what you have to do to create splash screen for your win forms application.
First of all, lets create a simple windows forms application, open up Visual Studio and select File -> New -> Project.

screen1

Select ‘Windows Forms Application’, set the name for your project and click ‘OK’.
This creates simple windows forms application which you can start up by clicking ‘F5′.

Lets say that my Form1.cs is the main form of the application I want to start up. Before launching Form1 I want to create a splash screen to load some additional resources, connect to the database or remote server. The project structure for now should look like this:

screen2

Now, when we have our application created and ready to be launched we create a splash screen for it. We create the splash screen itself first and than modify a bit the code to launch our splash before the main application starts.
Our splash itself would be another form which we modify a bit to look like, well, like a splash screen :) .
Lets add another form to our project:

screen3

and name it ‘SplashForm.cs’. This form will be launched until our main form loads. To make it look like a proper splash screen we have to find the property named ‘FormBorderStyle’ and set it to ‘None’, as well as set the ‘StartPostion’ to ‘CenterScreen’.
You can prettify the splash form by adding picture boxes, labels etc to add your custom graphics etc. I’m going to add a simple label and animated gif loader to my form. You can use animated gifs generated on this website which I found very cool.

screen4

Ok, our splash screen is ready, now we need to modify the code which starts our application to show the splash screen and destroy it when the main form is ready.
Originally, when you create the windows forms type of project a simple class called ‘Program’ gets created. You can find the source for this class inside ‘Program.cs’ file. It should look somthing like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace TestFormApplication
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

In order to use our splash form created earlier correctly we need to modify this code a bit. First, add a reference to Microsoft.VisualBasic assembly found under .NET tab. Go to you project references and find the following:
screen5
Next, add the folowing piece of code among other ‘using’ statements on top of the ‘Program’ class file:

using Microsoft.VisualBasic;
using Microsoft.VisualBasic.ApplicationServices;

Once this is done you are ready to use the VB goodness. Add the following code below the Program class, inside the same namespace as the Program class itself:

class SplashApp : WindowsFormsApplicationBase
        {
            protected override void OnCreateSplashScreen()
            {
                this.SplashScreen = new SplashForm();
            }
            protected override void OnCreateMainForm()
            {
                //Connect to db, remote server or anything you like in here
                System.Threading.Thread.Sleep(2000);
                //create your main form and the SplashForm will close here automatically
                this.MainForm = new Form1();
            }
        }

You have to modify the main method a bit as well, use the main with arguments option and start you application using our newly created SplashApp class, the full source code for the Program.cs will look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.ApplicationServices;

namespace TestFormApplication
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            new SplashApp().Run(args);
        }
        class SplashApp : WindowsFormsApplicationBase
        {
            protected override void OnCreateSplashScreen()
            {
                this.SplashScreen = new SplashForm();
            }
            protected override void OnCreateMainForm()
            {
                //Connect to db, remote server or anything you like in here
                System.Threading.Thread.Sleep(2000);
                //create your main form and the SplashForm will close here automatically
                this.MainForm = new Form1();
            }
        }
    }
}

You can download the whole VS 2008 solution file here.

Reading XML from the web using C#

Posted by admin | Posted in Code Snippets | Posted on 27-04-2009

0

Today I will describe quick and dirty way to read xml data received as a web response. This can get very usefull if you want to send some information in a quck way without creating whole bunch of web service references etc.

Lets say I want to get some data from the server in the xml like this:


&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
  &lt;root&gt;
  &lt;order&gt;
  &lt;order_id&gt;100000001&lt;/order_id&gt;
  &lt;order_date&gt;2009-04-20 15:09:29&lt;/order_date&gt;
  &lt;b_name1&gt;Kris Gr&lt;/b_name1&gt;
  &lt;b_name2&gt;softberrieseshop&lt;/b_name2&gt;
  &lt;b_address_line1&gt;adres 1 adres 2&lt;/b_address_line1&gt;
  &lt;b_city&gt;Elblag&lt;/b_city&gt;
  &lt;b_postcode&gt;2341234&lt;/b_postcode&gt;
  &lt;b_tel&gt;65464564666&lt;/b_tel&gt;
  &lt;b_fax&gt;6546876465&lt;/b_fax&gt;
  &lt;item&gt;
      &lt;item_sku&gt;DZFOREVER2&lt;/item_sku&gt;
      &lt;qty_ordered&gt;1.0000&lt;/qty_ordered&gt;
      &lt;qty_invoiced&gt;1.0000&lt;/qty_invoiced&gt;
      &lt;qty_refunded&gt;0.0000&lt;/qty_refunded&gt;
      &lt;qty_shipped&gt;0.0000&lt;/qty_shipped&gt;
      &lt;qty_canceled&gt;0.0000&lt;/qty_canceled&gt;
  &lt;/item&gt;
  &lt;/order&gt;
  &lt;/root&gt;

Retrive the xml information contained within XML document using the url to the document itself (urlString):

             XmlDocument document = new XmlDocument();
             document.Load(urlString);
             XmlElement root = doc.DocumentElement;
             XmlNodeList nodes = root.SelectNodes(&quot;/root/order&quot;); 

             foreach (XmlNode node in nodes)
             {
                 string idStr = node[&quot;order_id&quot;].InnerText;
                 string dateStr = node[&quot;order_date&quot;].InnerText;

                 XmlElement root2 = doc.DocumentElement;
                 XmlNodeList nodes2 = root.SelectNodes(&quot;/root/order/item&quot;);
                  foreach (XmlNode nodex in nodes)
                 {
                       string sku = nodex[&quot;item_sku&quot;].InnerText;
                 }
             }

Simple and dead easy!

Free file sharing service based on Amazon S3

Posted by admin | Posted in Tools | Posted on 26-04-2009

3

storage
A short note about a brand new rapidshare competition based on Amazon S3 called Storage For Free (www.storage43.com). Without registration you can share here your project files or basically anything you want to share quickly (up to 200 MB no registration required and the file is alive on the server for 30 days), if you are still unhappy you can register for free and get 500MB for a single upload. This is another service that proves growing popularity of Amazon Web Services which in my opinion are great!

Enjoy!

Launch your application automatically when the system starts with C#

Posted by admin | Posted in Code Snippets | Posted on 23-04-2009

0

In this article I will describe automatic startup of your c# application on windows machine using the registry settings. This article is somehow opposite to the one posted earlier about automatic shutdown.
To set the registry for your application to start up automatically you need to find the key responsible for automatic startup and set value of your application on this key:

RegistryKey rkey = Registry.CurrentUser.CreateSubKey(@"SoftwareMicrosoftWindowsCurrentVersionRun");
             rkey.SetValue("YourApplicationName", Assembly.GetExecutingAssembly().Location);

Executing this from your program will automatically add your assembly to auto start, this is thanks to Assembly.GetExecutingAssembly().Location piece.
When running your application you can easily check if you app has the key set:

RegistryKey rkey = Registry.CurrentUser.OpenSubKey(@"SoftwareMicrosoftWindowsCurrentVersionRun");
              if(rkey == null)
                      //not set
              if((string)rkey.GetValue("YourApplicationName") == null)
                      //not set either

If you decide that you don’t want the application to be started automatically when the system starts, you have to delete the value for the key:

RegistryKey rkey = Registry.CurrentUser.CreateSubKey(@"SoftwareMicrosoftWindowsCurrentVersionRun");
              rkey.DeleteValue("YourApplicationName");

And thats it. Registry looks scary at the beginning but hey, this was fun and easy!

Shutting down Windows with C#

Posted by admin | Posted in Code Snippets | Posted on 23-04-2009

1

This article describes how to shut down your machine using C# code. There are a few approaches to do that in C# but I will describe the easiest one, which works on both Win XP and Vista. All you have to do is just to make sure that you don’t have any additonal threads running, otherwise your machine may refuse to shut down (spotted this problem on XP).
Here you have a short snipped which will do the work for you:

System.Diagnostics.Process process = new Process();
                process.StartInfo.FileName = "SHUTDOWN";
                process.StartInfo.Arguments = "-s -t 05"; // -r is for restart, -s is for shutdown
                process.Start();

After this call if you have a windows forms application you can call Dispose() on the main form to exit nicely.

Continuous Integration with CruiseControll.NET

Posted by admin | Posted in Tools | Posted on 09-04-2009

3

Today I will try to bite quite a big topic which is continuous integration setup for .NET application build using Visual Studio 2008, Vistual Studio Unit Tests and Cruise Control.NET.
Continuous integration, in a few simple words works the following way: there are a number of developers working on a project, developers use subversion or other code versioning system to manage their source code. When they work on the project they commit changes to the subversion repo and from the other side another part of the process called ‘continuous integration server’ checks this code out every few minutes, and tries to build it and run unit tests on it, to see if it is so far all ok.
That was probably the shortest description of continuous integration process you would ever be able to find on the internet ;) .

So, how do you set up your own? Well, actually its not that difficult but looks scary at the frist sight. First of all of course, you would have to download and install all software needed, and this is:

That should be it on the server side! While installing just follow the defaults and you should be fine. I do install Cruise Control directly on the C: drive which ends up as C:CruiseControl.NET but you can install it wherever you want, I do it this way as its easier for me to write scripts if neccessary (short pathes instead of long ones).

Once CC.NET is installed you should be able to run it. You have two options, first one run it as a console app or run it as a service. For the setup, I would recommend running it as a console, make sure that CC.NET service is not running and double click ccnet.exe file inside C:CruiseControl.NETserver directory or any other ’server’ directory depending on your installation path.
If all went fine you can see the CC.NET dashboard in your browser. Just browse to the url ‘http://localhost/ccnet’ where ‘ccnet’ is a virtual directory created by Cruise Control application setup.
capture1

Ok then, once all is runnning and installed we can start configuring our CC server. To do that you would need to open ccnet.config file in your favourite text editor. Inside ccnet.config you will be able to set your project which should be build and tested by Cruise Control. The ccnet.config file consist of a number of project sections. You can have as many ‘project sections as you wish, all contained inside the root element of the document.

<cruisecontrol xmlns:cb="urn:ccnet.config.builder">

  <project name="Project One">
  </project>

  <project name="Project Two">
  </project>

</cruisecontrol>

Lets configure one of the projects, all elements described above would be a subnodes of the project element. First of all we need to specify a working directory for our project. Simply create a dir on your drive somewhere and add a path to it between ‘workingDirectory’ elements. This directory will be used to download the subversion sources.

<workingDirectory>c:projectone</workingDirectory>

After we specify ‘workingDirectory’ we have to specify a trigger which will call updates on our source code, checked out form the subversion. Right here we specify that CC.NET should check the subversion repo every 60 seconds and if it finds any modifications it should run the whole continuous integration process.

<triggers>
         <intervalTrigger seconds="60"/>
     </triggers>

To allow cruise controll download/update your sources, we need to specify the adress of the subversion repository as well as username and password

<!--set the sourcecontrol type to subversion and point to the subversion exe-->
    <sourcecontrol type="svn">
      <executable>C:Program FilesSubversionbinsvn.exe</executable>
      <workingDirectory>C:projectone</workingDirectory>
      <trunkUrl>http://svn_server.com/projectone</trunkUrl>
      <autoGetSource>true</autoGetSource>
      <username>your_username</username>
      <password>your_password</password>
    </sourcecontrol>

This section was pretty easy, after we specify working directory, trigger and subversion settings we are ready to add sections responsible for building, testing and publishing our results.
All of the mentioned should happen inside the ‘tasks’ section so, just after the ’sourcecontrol’ element add the following:

<tasks>
      </tasks>

Inside the ‘tasks’ we will add the elements for building the project/solution (msbuild element), unit testing (2 times ‘exec’ element), publishing our work to a separate directory (‘buildpublisher’ element) as well as publish our test results to CC.NET dashboard (‘publishers’ element).

To do all that, we need to first build our project. We are going to use MSBuild.exe which you should be able to find in C:WINDOWSMicrosoft.NETFrameworkv3.5 if you are using .NET 3.5 version. Instead of building single project we are going to build a whole solution. To build a solution you need to specify the place where the solution file exists as well as the name of the solution file itself. Depending on the project size and characteristics you have to set the timeout option to suit your needs and to prevent CC.NET to timeout before the project have a chance to actually build.

<!-- Configure MSBuild to compile the updated files -->c:
      <msbuild>
        <executable>C:WINDOWSMicrosoft.NETFrameworkv3.5MSBuild.exe</executable>
        <workingDirectory>C:projectonetrunk</workingDirectory>
        <projectFile>projectOne.sln</projectFile>
        <buildArgs>/noconsolelogger /p:Configuration=Debug</buildArgs>
        <targets></targets>
        <timeout>300</timeout>
        <logger>C:CruiseControl.NETwebdashboardbinThoughtWorks.CruiseControl.MsBuild.dll</logger>
      </msbuild>

Ok, so we are already able to automatically build our project and this is really cool but what would be continuous integration without executing unit tests :) . As it makes development easier, for my projects, wherever possible I use built in Unit Test functionality in Visual Studio 2008.In my opinion, VS Unit Tests are a bit more tricky to set up than NUnit on CC.NET, especially publishing results part of it) but the developmnet on the other hand is easier and I will stick to it.
We need to do the following three things to properly execute tests. First of all we need to run tests using MSTest.exe, this part is pretty easy but before doing that we need to delete previous test results or otherwise our MSTest would complain. Therefore you have to add into your tasks the two following ‘exec’ sections.
First one to delete any previouse test results using bat file (deleteTestLog.bat) with single command:

DEL C:projectoneresults.trx
<exec>
            <executable>deleteTestLog.bat</executable>
            <baseDirectory>C:CruiseControl.NETserver</baseDirectory>
            <buildArgs></buildArgs>
            <buildTimeoutSeconds>30</buildTimeoutSeconds>
        </exec>

Second ‘exec’ section running the actual unit tests:

<exec>
            <!--Call mstest to run the tests contained in the TestProject -->
            <executable>mstest.exe</executable>
            <baseDirectory>C:projectonetrunkprojectOneTests</baseDirectory>
            <!--testcontainer: points to the DLL that contains the tests -->
            <!--runconfig: points to solutions testrunconfig that is created by vs.net, list what test to run -->
            <!--resultsfile: normally the test run log is written to the uniquely named testresults directory  -->
            <!--                   this option causes a fixed name copy of the file to be written as well -->
            <buildArgs>/testcontainer:C:projectonetrunkprojectOneTestsBinDebugprojectOneTests.dll /resultsfile:C:projectoneresults.trx</buildArgs>
            <buildTimeoutSeconds>90</buildTimeoutSeconds>
         </exec>

Right now our server builds and tests our solution automatically. If we want to publish the build results somewhere else, lets say to another virtual directory or web site we can copy the files using ‘buildPublisher’. This way, if its a web application, after each build you can browse to the web site url and see the latest changes in place, all freshly build and tested.

<buildpublisher>
        <sourceDir>C:projectonetrunkprojectOne</sourceDir>
        <publishDir>D:projectOnePublished</publishDir>
        <useLabelSubDirectory>false</useLabelSubDirectory>
      </buildpublisher>

At this point we have a continuous integration server running which automatically update our solution if it detects any changes on subversion server, builds the sources, runs unit tests and publish the build results. This is great, one problem though, MSTest is not well integrated into CC.NET so we won’t be able to see our tests results, if any fails for e.g. on our CC dashboard.
To publish your test results into cruise control dashboard you would need to add the following section inside your ‘project’, just after ‘exec’ or ‘buildPublisher’ sections:

<!--Publishers will be done after the build has completed-->
    <publishers>
         <merge>
               <files>
                     <file>results.trx</file>
               </files>
         </merge>
         <xmllogger logDir="C:CruiseControl.NETserverProjectOneArtifactsbuildlogs" />
    </publishers>

This will merge your test results into the dashboard.

I hope you will enjoy having continuous integration as part of your project building flow. Have fun.

Backup your MS SQL Server with C#

Posted by admin | Posted in Code Snippets, System Administration | Posted on 08-04-2009

1

Today I will describe some code snippets on how to backup your MS SQL Server database to a ‘.bak’ file using C#. Later on we will zip our .bak file using open source C# zip library as bak files seems to have high compression ratio.
Backing up files require us to connect to the database server and than use of Microsoft.SqlServer.Mangement.Smo objects to create actual backup.

Assuming we have some private fileds ready:

private Server sqlsrv; //initialized when connection succeedes
        private string dbName;
        private string backupFile;
        private string serverName;
        private string sqlUser;
        private string sqlPass;

Lets first create a connection to our database server and initialize our Server type object:

private bool connectToSQLServer()
        {
            try
            {
                ServerConnection serverConn = new ServerConnection(this.serverName);
                // Log in into sqlserver
                serverConn.LoginSecure = false;
                // Give the login username
                serverConn.Login = this.sqlUser;
                // Give the login password
                serverConn.Password = this.sqlPass;
                // create a new sql server object
                sqlsrv = new Server(serverConn);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return false;
            }
            return true;
        }

If all goes fine and we have our Server (sqlsrv) object ready we can start our backup operation:

public bool bakBackup()
        {
            //If the connection returns false return from this method too.
            if (!connectToSQLServer())
                return false;
            try
            {
                // Create a new backup object
                Backup bkpDatabase = new Backup();
                // Set the type to database
                bkpDatabase.Action = BackupActionType.Database;
                // set the database name we want to actually backup
                bkpDatabase.Database = dbName;
                // To get the file from me actual backup create BackupDeviceItem
                BackupDeviceItem bkpDevice = new BackupDeviceItem(this.backupFile, DeviceType.File);
                // add the backup file device to our backup
                bkpDatabase.Devices.Add(bkpDevice);
                // execute the actual backup using Smo
                bkpDatabase.SqlBackup(sqlsrv);
                //verify if the file exist
                if (File.Exists(this.backupFile))
                    return true;
                else
                    return false;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Backup file couldn't be created" + ex.StackTrace);
                return false;
            }
        }

As a side note I would mention that the only two folders I have found on my system where I can actually perform the backup (store tha bak file) is “C:Program FilesMicrosoft SQL ServerMSSQL.3MSSQLBackup” or “C:Program FilesMicrosoft SQL ServerMSSQL.3MSSQLData” folders, this has something to do with permissions setup and I’ll will update this post once I find the solution. You can read my post on stackoverflow regarding this issue.

Assuming that all went ok, lets create a zip file which will compress our bak file to the size more than 2 times smaller than the original bak file.
For file comression I will use great C# library ‘SharpZipLib’ which you can find here.
Before using the snippet below you would have to add a reference to the library in your project.

public static void Zip(string sourceFile, string destinationFile, int BufferSize)
        {
            FileStream fileStreamIn = new FileStream(sourceFile, FileMode.Open, FileAccess.Read);
            FileStream fileStreamOut = new FileStream(destinationFile, FileMode.Create, FileAccess.Write);
            ZipOutputStream zipOutputStream = new ZipOutputStream(fileStreamOut);

            byte[] buffer = new byte[BufferSize];

            ZipEntry entry = new ZipEntry(Path.GetFileName(sourceFile));
            zipOutputStream.PutNextEntry(entry);

            int size;
            do
            {
                size = fileStreamIn.Read(buffer, 0, buffer.Length);
                zipOutputStream.Write(buffer, 0, size);
            } while (size > 0);

            zipOutputStream.Close();
            fileStreamOut.Close();
            fileStreamIn.Close();
        }

Looks pretty easy? Well, actually it is! As a source and destination file arguments provide full path to your file (.bak) as source and (.zip) as destination and you are done.
You can of course change one name to another using simple call:

string zipFileName = fileName.Replace(".bak", ".zip");

Happy coding!

How to backup your entire server from EC2 to S3

Posted by admin | Posted in Cloud Computing | Posted on 07-04-2009

4

Today I will describe in short how to create an AMI instance of EC2 and than upload it to S3 server. All you need to have is running instance of EC2 server (I’m using Debian) with EC2 tools preinstalled.
First of all, make sure that you don’t have any unnecessary files on your server filesystem which you don’t need to bundle in an image as it will only slow the process down and make your costs of storing backup images higher.
Once you are sure that your instance is fine and EC2 tools are in place you have to transfer your private key file and certificate file to the server. Lets put the files under /root directory.
If all is set up correctly, first of all, we create and image by running:

ec2-bundle-vol -d /mnt -k /root/PrivateKey.pem  --cert /root/Certificate.pem  -u 012345678901

The number after the -u flag is your Amazon account ID which you can find on the AWS website once logged in.
Running above command will take a bit and will create a number of files under /mnt directory.
Once we have the files and manifest ready (all happens auto-magically) we can start transferring the image onto S3 account.
In order to transfer your image on S3 you would have to create a bucket there first, for this you can use famous firefox plugin (S3 Organizer) or do it using Affirma’s library (previous post).

ec2-upload-bundle -b yourbucketname00404042009 -m /mnt/image.manifest.xml -a your_s3_access_key -s your_s3_secret_access_key

If for some reason you encouter any problems during upload but your bundling went ok, you can retry the upload using –retry flag:

ec2-upload-bundle -b yourbucketname00404042009 -m /mnt/image.manifest.xml -a your_s3_access_key -s your_s3_secret_access_key  --retry

Happy bundling!

Affirma S3 library for C#

Posted by admin | Posted in Cloud Computing, General Programming, Tools | Posted on 06-04-2009

0

Finally I have found S3 library that works in C#. The library was written by Joel Wetzel from Affirma Consulting and I just wanted to spread the word about it.
Once downloaded you are presented with the whole C# Visual Studio solution which contains the library project as well as some example on how to use it.
There is even a simple wrapper written which greatly simplyfies the use of the affirma’s library.
As an example:
1. Create wrapper object (constructor listed)

public ThreeSharpWrapper(String awsAccessKeyId, String awsSecretAccessKey)
        {
            this.config = new ThreeSharpConfig();
            this.config.AwsAccessKeyID = awsAccessKeyId;
            this.config.AwsSecretAccessKey = awsSecretAccessKey;

            this.service = new ThreeSharpQuery(this.config);
        }

and then use it having the following methods:

/// Adds a bucket to an S3 account
public void AddBucket(String bucketName);

 /// Returns a string of XML, describing the contents of a bucket
public String ListBucket(String bucketName);

/// Adds a string to a bucket, as an object
public void AddStringObject(String bucketName, String keyName, String data);

/// Streams a file to a bucket as an object
public void AddFileObject(String bucketName, String keyName, String localfile);

/// Streams a file to a bucket as an object, with encryption
public void AddEncryptFileObject(String bucketName, String keyName, String localfile, String encryptionKey, String encryptionIV);

/// Gets a string object from a bucket, and returns it as a String
public String GetStringObject(String bucketName, String keyName);

/// Gets a file object from a bucket, and streams it to disk
public void GetFileObject(String bucketName, String keyName, String localfile);

/// Gets a file object from a bucket, streaming it to disk, with decryption
public void GetDecryptFileObject(String bucketName, String keyName, String localfile, String encryptionKey, String encryptionIV);

/// Copies an object from a source location to a destination location
public void CopyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey);

/// Generates a URL to access an S3 object in a bucket
public String GetUrl(String bucketName, String keyName);

/// Deletes an object from a bucket
public void DeleteObject(String bucketName, String keyName);

/// Deletes a bucket from an S3 account
public void DeleteBucket(String bucketName);

/// Changes the request payer value for the specified bucket
public String PaymentChange(String bucketName, PaymentChangeRequest.Payer payer);

/// Gets the request payer value for the specified bucket
public String PaymentGet(String bucketName);

The library is dead easy to use and most importantly it works (comparing to other S3 libraries I’ve found). Great work Joel!
You can download the solution zip from here or directly from the codeplex hosting the project here