Ask the expert on Web Camps TV: Rey Bango

Every week we give you the chance to ask the experts questions on Web Camps TV when we’re in the studio.  To ask a question – use the Facebook Live Stream below during the “on air time” and we’ll attempt to answer as many questions as possible.  The show will be aired at a later date.

Today, Friday 27th at 4pm PST we have Rey Bango in the Channel 9 studio.  Rey is a member of the jQuery Core Team and also works at Microsoft as a all around web ninja kinda guy.  Ask your questions below and we’ll get them answered!

 

Tags:

Web Camps L.A.– Sold Out in 48 hours (UPDATED)

****UPDATED 8/27/2010 2:20pm****
We have upgraded to a bigger room and there are currently tickets available for the Web Camp in LA. If you were on the wait list you will be automatically assigned a ticket.  If you’ve not yet signed up – make sure you do quickly!

LAWe released the tickets just under 48 hours ago and Web Camp LA is sold out!  That’s good and bad news, right?! For those of you who haven’t yet signed up, don’t be too distressed.  We are currently looking for a bigger room so that we can release some more tickets.  I’ll post an update once we’ve secured the room – fingers crossed!

Remember we are crowdsourcing the agenda – here’s the poll results so far.  Looks like jQuery and ASP.NET MVC 101 is out in front.  Be sure to vote so you hear the right content!

image

Make your voice heard – take the poll and let us know what content you want!

Tags:

New: Windows Azure Storage Helper for WebMatrix

Hot on the heels of the OData Helper for WebMatrix today we are pushing out a new helper into the community.  The Windows Azure Storage Helper makes it ridiculously easy to use Windows Azure Storage (both blob and table) when building your apps.  If you’re not familiar with “cloud storage” I would recommend you take a look at this video where my pal Ryan explains what it’s all about.  In a nutshell, it provides infinitely simple yet scalable storage which is great if you are a website with lots of user generated content and you need your storage to grow auto-magically with the success of your apps.  Tables aren’t your normal relational databases – but they are great for simple data structures and they are super fast.

You can download the helper from the Codeplex website.

Get started in 60 seconds
  1. If you haven’t already got one, sign up for a Windows Azure account
  2. In the _start.cshtml file setup the helper for use with your account by adding this code:

    1. @using Microsoft.Samples.WebPages.Helpers
    2. @{
    3.     WindowsAzureStorage.AccountName = "youraccountname";
    4.     WindowsAzureStorage.AccountKey = "youraccountkey";
    5. }

  3. Download the latest Windows Azure Storage Helper Binaries
  4. In your WebMatrix project, create a folder named "bin" off the root
  5. Copy the Windows Azure Storage Helper Binaries there
  6. Check out the documentation
  7. Start using Windows Azure Storage Tables and Blobs from WebMatrix with the Helper!

There are loads of use cases out there for blob and table storage.  You just need to look at of the popular startups like Facebook, Twitter, YFrog, Foursquare, Dropbox who all use this type of storage to gain great scale and performance.

How to use the helper

With the helper we’ve provided a bunch of methods that make common operations really easy so that you can that in your WebMatrix apps.  Here are some of my favorite examples:

1. Getting a row from a table – notice how we can just dump the result into a WebGrid and have it render our table for us.

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.     var rows = WindowsAzureStorage.GetRows("JamesTable");
  4.     var grid = new WebGrid(rows);
  5. }

2. Updating a row in a table – first we get the individual row, making sure to pass it the partition and table name.  Next we make a change to an item, then update the table.

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.     var row = WindowsAzureStorage.GetRow("JamesTable", "partition1", "row1");
  4.     row.Name = "James Senior";
  5.     WindowsAzureStorage.UpdateRow("JamesTable", row);
  6. }

3. Uploading a file into blob storage – I like to use this in combination with the FileUpload helper that we ship with WebMatrix.  You can pass a stream, binary file or text string into the helper method and it’ll be placed in the blob address you specify.

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.     var uploadedFile = Request.Files[0];
  4.     WindowsAzureStorage.UploadBinaryToBlob("MyContainer/" + uploadedFile.FileName, uploadedFile.InputStream);
  5. }

4. To grab the blob, use one of the download methods like DownloadBlobAsText or DownloadBlobAsText.

@using Microsoft.Samples.WebPages.Helpers
@{
   // reference to my blob
   var blobRef = "MyContainer/foo.txt";

   // gets the blob as text
   var astring = WindowsAzureStorage.DownloadBlobAsText(blobRef);
  
   // gets the blob as a byte array and puts it in the
   var bytes = WindowsAzureStorage.DownloadBlobAsByteArray(blobRef);
 
   // Send the response so the user can download the file
   Response.ClearContent();
   Response.AppendHeader("Content-Type", "application/octet-stream");
   Response.AppendHeader("Content-Disposition:", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(blobRef)));
   Response.BinaryWrite(bytes);
   Response.End();
}

Here’s a video where I walk through how to do all this good stuff in detail:

Get Microsoft Silverlight

 

Future work

There’s some more features I’d like to add to the next version of this helper. I’ve started a discussion here about that – join the conversation if you have any ideas!  Here are the current ideas:

  • Error Handling (Windows Azure Tables)
  • Pagination and continuation tokens (Windows Azure Tables)
  • Lease/Snapshot/Copy Blob operations (Windows Azure Blobs)
  • Sharing Blobs (Windows Azure Blobs)
  • Delimiters (Windows Azure Blobs)
  • Client-side ordering (Windows Azure Tables)

Tags:

Announcing the OData Helper for WebMatrix Beta

I’m a big fan of working smarter, not harder.  I hope you are too.  That’s why I’m excited by the helpers in WebMatrix which are designed to make your life easier when creating websites.  There are a range of Helpers available out of the box with WebMatrix – you’ll use these day in, day out when creating websites – things like Data access, membership, WebGrid and more.  Get more information on the built-in helpers here.

It’s also possible to create your own helpers (more on that in a future blog post) to enable other people to use your own services or widgets.  We are are currently working on a community site for people to share and publicize their own helpers – stay tuned for more information on that. 

Today we are releasing the OData Helper for WebMatrix.  Designed to make it easier to use OData services in your WebMatrix website, we are open sourcing it on CodePlex and is available for you to download, use, explore and also contribute to.  You can download it from the CodePlex website.

  1. @{
  2. var result = OData.Get("http://odata.netflix.com/Catalog/Genres('Horror')/Titles","$orderby=AverageRating desc&$top=5");
  3. var grid = new WebGrid(result);
  4. }
  5.  
  6. @grid.GetHtml();
 

What is OData?

OData, or as I like to call it “Oh…. Data” Winking smile, is an open specification that makes it possible to have consistent APIs for all the different services out there.  Effectively it’s REST with a powerful query syntax that makes it easy to extract the data you want from a service.  So far there are a bunch of websites out there that have exposed their data using the spec, including Facebook, Netflix, Stackoverlow etc.  There’s a full list over at www.odata.org as well as more information on the spec itself.

Getting Started Video

Get Microsoft Silverlight

How to use the OData Helper

The OData helper supports CRUD (Create, Read, Update and Delete) methods - as you would expect -  but for reading there are a couple of syntaxes available; use the one which feels most natural to you.  Here are a couple of examples of the different syntaxes:

Get the top 5 Horror Titles (Using String Filters)

 

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3. var result = OData.Get("http://odata.netflix.com/Catalog/Genres('Horror')/Titles","$orderby=AverageRating desc&$top=5");
  4. var grid = new WebGrid(result);
  5. }

 

Get the top 3 Movies in French (Using Query Syntax)

 

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3. var result = OData.Open("http://odata.netflix.com/Catalog/Languages('French')/Titles")
  4. .Where("Type eq 'Movie'")
  5. .OrderBy("AverageRating desc")
  6. .Top(3)
  7. .Get();
  8. var grid = new WebGrid(result);
  9. }

 

Inserting new data
  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.    var movie = OData.CreateEntity();
  4.    movie.Name = "OData Helpers - The Movie";
  5.    movie.ReleaseYear = 2010;
  6.    movie.BoxArt.LargeUrl = "http://cdn-4.nflximg.com/us/boxshots/tiny/5670394.jpg";
  7.    OData.Insert("http://odata.netflix.com/Catalog/Titles", movie);
  8. }

Updating existing data

 

  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.    var movie = OData.Get("http://odata.netflix.com/Catalog/Titles('13kaI')");
  4.    movie.Name = "OData Helpers - The Movie";
  5.    OData.Update("http://odata.netflix.com/Catalog/Titles('13kaI')", movie);
  6. }

 

Deleting existing data
  1. @using Microsoft.Samples.WebPages.Helpers
  2. @{
  3.    OData.Delete("http://odata.netflix.com/Catalog/Titles('13kaI')");
  4. }

With Netflix service the insert, update and delete operations won’t work because they only provide read access – so the examples above are just for illustrative purposes only.

If you are new to the OData query syntax I would recommend checking out the docs that the OData team have put together.

What can you do?

There are bunch of OData services out there (full list here), why not create some wrapper classes for each service with common operations baked in so other developers don’t even have to know the syntax.  You’ll see what I mean if you explore the sample application in the download section of the CodePlex project.  We’ve included a Netflix.cs file in app_code folder – it’s just a wrapper around the OData helper class which performs some commonly used queries for the user.  I’d love to hear what you can do!

Next Steps

OData Helper v2

We’ve already cooked up some enhancements for the next version of the OData helper, you can find the list here.  If you think of anything you would like to see, please reply to the discussion in the forum!

Other Helpers

I’m now working on some other helpers which I think are pretty cool – you’ll hear more about them soon.  I’d love to hear about your ideas for helpers – maybe I can build it for you!  If you have an idea leave me a comment or send me mail – james {at} microsoft.com

Tags: