Programming
Connecting to Azure Table Storage
Mar 12th
After you finally manage to get Table Storage working (see nice tutorial here) you’ll try to deploy it to your staging environment. That means you need to change the configuration.
There are three settings to use: AccountName, AccountSharedKey and TableStorageEndpoint.
Unfortunately, the values you need for them aren’t what you would naturally expect.
AccountName: This isn’t your account name, but the name of your storage account. (I guess that’s why it has to be a unique name at the time you create it.) On the summary page of your storage project you will only see the value you need in the list of endpoints. It’s the first part of each of the three domain names.
AccountSharedKey: This is the Primary Access Key as found in the summary page of your storage project in the developer portal.
TableStorageEndpoint: This isn’t the endpoint as described in the summary page, but rather a shortened version. Just lop off the AccountName part of the endpoint you use as described in the summary page. That should give you something like http://table.core.windows.net.
For more information see this article on MSDN.
It is so time-consuming to get right, that it really makes sense to follow the advice in the documentation. First, test locally. Then test your local hosted app using the live Storage account. Finally, load your app and test that in the staging environment.
Saying that, I haven’t yet managed to get the second scenario to work. It just crashes on start-up. (Help!)
Learning Windows Azure
Mar 12th
I started to learn how to use the Azure Cloud Service from Microsoft this week. Currently it’s still in Tech Preview stage. Unfortunately you can tell that from the SDK documentation.
Here’s some useful links to get you going:
- Screencasts: http://msdn.microsoft.com/en-us/azure/dd439432.aspx
These are quite basic, but trust me, you need them to be basic to get you started. - SDK: http://www.microsoft.com/downloads/details.aspx?FamilyID=80e3eabf-0507-4560-aeb6-d31e9a70a0a6&displaylang=en
Contains CHTM-style documentation, tools and samples. Don’t expect too much from the docs; they explain enough to get you confused, and then have an API reference. You need to unzip the samples and get into them to start understanding how everything fits together. - Visual Studio Templates: http://www.microsoft.com/downloads/details.aspx?FamilyID=8e90b639-1ef0-4e21-bb73-fc22662911bc&displaylang=en
This gives you a set of project and item templates which you can use to create and publish Azure applications. Don’t worry about the extra projects it adds to a solution, or the config files. You will learn more about them later. - The Azure developer center on MSDN: http://msdn.microsoft.com/en-us/azure/default.aspx
Assuming you already registered for Azure, that’s all you really need to get started.
The biggest problem I found at first was deploying an app. Once you have generated an Azure project in Visual Studio, you expect to be able to publish it from Visual Studio too. Unfortunately you can’t, and it takes a little more effort. I’ll write more about that in another post.
I also needed help trying to understand what to focus on to get started. So here’s a big tip: Ignore .Net Services, Live Services, and SQL Data Services. They aren’t part of Azure per se. You can come back to them later. First you just need a hosted project and some storage – either blob storage or table storage. (There’s also queue storage, but I bet no one will want to use that straight away – it’s for tying two apps together, which no one will want to do at first.)
I recommend you download the SDK and the Visual Studio templates, create yourself a “Web Role” project (which is really the equivalent of an ASP.Net project), and work on that. Then move onto table and blob storage. You can use the screencasts to help you.
Good luck getting started!
Design Guidelines for LINQ
Mar 13th
Have you wondered if and when you should use the new LINQ features in .Net 3.5?
Like, where should I put a new extension method? Should I use Func<T> or a custom delegate? How do I best implement a mix-in (extension methods on an interface)?
Well, Mircea Trofin has just published a new draft of some LINQ design guidelines. You might just find your answers there.
Remove and Sort Those Ugly “using-Statements”
Mar 3rd
Visual Studio 2008 has lots of goodies in it, like LINQ syntax, CSS editing, and testing tools. There’s a lesser-known feature which I really appreciate though – the “Remove and Sort Usings” command in the C# editor.
You activate the command by placing your cursor over the using statements and clicking on the right mouse-button.
The LinqDataSource and the Hidden Viewstate
Feb 21st
Yesterday I thought I’d learn about the LinqDataSource in ASP.Net 3.5, and got an interesting surprise.
The new LinqDataSource can also be used with a LINQ-to-SQL model to perform updates. You simply add the DataSource to your page, set the table name, and set EnableUpdate to true. Then, using a standard DataControl, you can make updates to your data entities.
The question is, how does this work? It appears to be a bit magical. More >
Writing Custom Exception Classes the Quick Way
Feb 15th
Until recently I thought this was a well-known feature. After demonstrating it a few times, I found out it wasn’t.
A long time ago, in an cubicle far, far away, someone created the .Net Framework. To cut a long story short, they simultaneously produced guidelines for creating Exception classes, which you should always use or face having your fingernails pulled out with a staple-gun.
The guidelines state:
“Use the common constructors shown in the following code example when creating exception classes. “
[C#]
public class XxxException : ApplicationException
{
public XxxException() {… }
public XxxException(string message) {… }
public XxxException(string message, Exception inner) {… }
public XxxException(SerializationInfo info, StreamingContext context) {…}
}