SSDS @ Red Bull
4/1/2008 5:11:20 PM
Friday night, The Code Trip stopped by Red Bull headquarters for some good ol’ P&P (presenting and partying). I was first to speak and Woody, Buzz and I were talking to some of the people there about how easy it is to provision an SSDS Authority and get an application up and running. 20 minutes before I was about to start speaking, Woody and Jason(Buzz) have the video camera out and we are like ‘DUDE…why don’t you go on video and write an app in the 20 minutes you have before you present?’ So what would this app do? How about a database of drinks you can make with Red Bull :) So I found a soft spot in the corner, fired up my laptop, and started coding. A couple minutes later the guys from TechZulu.com came over and were like “What you doing?” and I told them and they proceeded to start interviewing me as I am coding…All in all, I probably coded for about 5 minutes if you factor in the interview time and the laptop booting up and all the people stopping by to ask questions and say hi… Oh yeah, and I was using a wireless network that had a EVDO uplink to the Internet…
But, I did it…
Here’s what it looks like….
This is probably the best UI design I have ever done. The top text box(without the label) is the name of the drink, and the bottom is the ingredients. I know entering a comma separated list is lame, but I was short on time…Add button, will add the drink entity to the Container.
There is also the Setup SSDS button which creates the Red Bull authority and the Drinks container.
The part I wanted to call out in this demo was not only is SSDS easy to provision and develop against, but i wanted to demonstrate flexible entities. If I was doing this using a relational DB, I would need to have two separate tables. DrinkHeader and DrinkIngredient with a foreign key. So when I insert a new drink, I have to insert 1 DrinkHeader record and N DrinkIngredient records where N = the number of ingredients.
SSDS’ flexible entity model allows me to have each Drink entity have whatever shape, or in this case, ingredients that I require…Lets look at a couple entities from the app…
1: <RedBullDrink>
2: <s:Id>redbull jaeger</s:Id>
3: <s:Version>1</s:Version>
4: <Name xsi:type="x:string">redbull jaeger</Name>
5: <Ingred1 xsi:type="x:string">redbull</Ingred1>
6: <Ingred2 xsi:type="x:string">jaegermeister</Ingred2>
7: </RedBullDrink>
8: <RedBullDrink>
9: <s:Id>redbull vodka</s:Id>
10: <s:Version>1</s:Version>
11: <Name xsi:type="x:string">redbull vodka</Name>
12: <Ingred1 xsi:type="x:string">redbull</Ingred1>
13: <Ingred2 xsi:type="x:string">vodka</Ingred2>
14: </RedBullDrink>
15: <RedBullDrink>
16: <s:Id>Chucks Irish Bomb</s:Id>
17: <s:Version>1</s:Version>
18: <Name xsi:type="x:string">Chucks Irish Bomb</Name>
19: <Ingred1 xsi:type="x:string">2 shots Hpnotiq</Ingred1>
20: <Ingred2 xsi:type="x:string">2 shots Jack Daniels</Ingred2>
21: <Ingred3 xsi:type="x:string">1 shot Vodka</Ingred3>
22: <Ingred4 xsi:type="x:string">1 shot Irish Whiskey</Ingred4>
23: <Ingred5 xsi:type="x:string">1 splash Cherry Juice</Ingred5>
24: <Ingred6 xsi:type="x:string">4 shots Red Bull</Ingred6>
25: </RedBullDrink>
So if you scroll through the entities, you will see that each of them have different ingredients. I don't know who Chuck is, but WOW...
The flexibility of our entity model allows your data to take whatever shape you need. In our case instead of having to use a header/line model, I am able to have my entity contain all my data for my item in one nice and neat package...
And...I was able to use my Excel AddIn to pull it down into a spreadsheet...
Here is the code - for the authority and container setup
1: private void button2_Click(object sender, EventArgs e)
2: {
3:
4:
5: ssdsCreds = new NetworkCredential(RBSSDSUserName, RBSSDSPassWord);
6:
7: string payload = BuildAuthorityEntity("redbull");
8: string RBUri = HttpHelper.PostHTTPWebRequest(RBSSDSUri, payload, ssdsCreds);
9:
10: payload = BuildContainerEntity("rbcontainer");
11:
12: RBUri = HttpHelper.PostHTTPWebRequest(RBUri, payload, ssdsCreds);
13: }
14:
15: static string BuildContainerEntity(string ContainerName)
16: {
17: string ContainerTemplate = @"<s:Container xmlns:s='http://schemas.microsoft.com/sitka/2008/03/'>
19: <s:Id>{0}</s:Id>
20: </s:Container>";
21:
22: return String.Format(ContainerTemplate, ContainerName);
23: }
24:
25: static string BuildAuthorityEntity(string AuthorityName)
26: {
27: string AuthorityTemplate = @"<s:Authority xmlns:s='http://schemas.microsoft.com/sitka/2008/03/'>
29: <s:Id>{0}</s:Id>
30: </s:Authority>";
31:
32: return String.Format(AuthorityTemplate, AuthorityName);
33: }
Here is the code to add the drink
1: static void BuildEntity(string name,string Incredients)
2: {
3: string TenantEntityTemplate =
4: @"<RedBullDrink xmlns:s='http://schemas.microsoft.com/sitka/2008/03/'
5: xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
6: xmlns:x='http://www.w3.org/2001/XMLSchema' >
7: <s:Id>{0}</s:Id>
8: <Name xsi:type='x:string'>{1}</Name>";
9:
10: int x=0;
11: string entity = string.Format(TenantEntityTemplate, name, name);
12:
13: foreach(string ingred in Incredients.Split(','))
14: {
15: x++;
16:
17: entity = entity + String.Format(@" <Ingred{0} xsi:type='x:string'>{1}</Ingred{2}>", x, ingred, x);
18: }
19:
20: entity = entity + @" </RedBullDrink>";
21:
22: HttpHelper.PostHTTPWebRequest(containerUri, entity, ssdsCreds);
23: }
So that’s it.
For more SSDS specific goodness, check out my blog at http://blogs.msdn.com/drobinson
-Dave