Spontaneous Publicity
blogs are the new phone book

Introducing Stacky: A .Net Client Library for the StackOverflow API

July 7, 2010 03:32 by luke

Looking back at the various open source projects I have started, I am starting to see a pattern. When I use a REST API provided by a given web site, I end up writing a full-fledged client for that library if one doesn’t exist. There is something I really enjoy about writing wrapper libraries.

In any event, when the stackoverflow.com api beta was announced, I decided to play around with it. One thing lead to another and I ended up implementing a full client library. That is where Stacky was born (it was originally called Stackoverflow.Net but due to some naming concerns I renamed it). This has been a very fun project to work on and I have received some great participation and feedback from people in the community. The StackOverflow API is officially named Stack Apps because it applies to all Stackoverflow family websites.

Simple

One of my main goals with the library was to just keep things simple. It is a simple library with a simple purpose so there is no need to be fancy or complicated. One feature introduced in c# 4 was optional parameters. Most REST services have a certain amount of optional parameters to each method and it is often messy to model this behavior in C#. Often you end up just having a crazy amount of method overloads. Here is a simple example of using the library:

Multi-Platform

After creating a .Net 4 version of the library, I realized I could also support Silverlight with a minimal amount of extra effort. Then once I had the library running in Silverlight, it was another small step to support Windows Phone 7. So then I had a multi platform library on my hands. This introduced an extra set of problems mostly having to do with making sure all the libraries are in sync and tested correctly.

After I released a version supporting these three platforms I received many requests to support .Net 3.5 so I eventually made a version for .Net 3.5 which used wrapper classes for optional parameters.

You can check out the source for Stacky here: http://stacky.codeplex.com. I will blog more of the specifics in the next week leading up to the final release of the stackapps api.


Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (418) | Comment RSSRSS comment feed

Recent Must Haves

October 26, 2009 18:04 by luke

There are a couple of things lately that I enjoy so much that I feel I need to share them with others.

This American Life

http://www.thisamericanlife.org

This is a free podcast of a public radio show which features stories about everything from stories about being switched at birth to the cruelty of children. Subscribe now. It is free. It is awesome.

Radio Lab

http://www.wnyc.org/shows/radiolab/

Another free podcast that just astounds me with its amazing content show after show. From the first show I heard on time to the recent show on parasites. I constantly find myself wanting to tell people about the amazing things I hear on this show. Usually, my wife ends up with the brunt of it :) Subscribe now. Also Free. Also Awesome.

Greg Laswell

http://www.greglaswell.com

Greg is one of my favorite artists. Everything he touches seems to turn to gold. Recently he released an album of just covers of other peoples songs. How is it that somebody covers an amazing song like Kate Bush’s This Woman’s Work and does it better than the original? Unfortunately, as of this writing the album only seems to be available from iTunes.


Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (70) | Comment RSSRSS comment feed

For The Kids

April 14, 2009 00:01 by luke

The things you do for your kids:

image

I put this song in a playlist we play to help our 8 month old sleep. Now the play count is embarrassingly high. I am very tempted to use the reset play count feature of iTunes to cover my tracks…


Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (55) | Comment RSSRSS comment feed

Code I Almost Wrote

January 23, 2009 12:17 by Luke

The only thing scarier than the code I actually write is the code I thought of and decided not to write. Actually, that is not true. The code I write is always perfect. Until I decide to change it later and make it more perfect.

duh Today I was writing a small console app which I wanted to run indefinitely until the user decides they would like to close it. This posed quite a challenge. Should I stop every 1000 iterations and check if the user has indicated they would like to stop processing? Should this be a windows app so I can have a stop button?

No, I should just run indefinitely and if they user wants the program to terminate, they will close the console window. So simple. My mind really wanted to complicate this one.


Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (44) | Comment RSSRSS comment feed

Microsoft Year One

October 22, 2008 21:51 by luke

I can’t believe it but as of today I have already been at Microsoft for a whole year.windowsvswalls It really has been a great year. Moving up to Washington from San Diego happened so fast my head was spinning for the first couple of months. Now that we feel more settled we really like it up here.

What I Have Worked On

I work on a team called the Windows Reliability Team. I have actually had the opportunity to work on two different features this past year. I started out working on a testing framework which was really challenging and interesting. It was a great introduction to Microsoft and to the Windows organization because it allowed me to interact with different teams and different technologies. When I joined the Windows team I wasn’t sure how much C# (or any managed code) I would get to use. Windows is, however, still mainly a native code product. And that is the way it should be. It is an operating system. But on the test side of things it is much more common for developers to be using .Net. In fact, I sometimes find myself being sort of an evangelist for .Net and C# within the team which is interesting. I never I thought I would join Microsoft only to teach them about their own technology. But then again with a company with such a wide array of products it is impossible for everybody to know them all.

The other feature I have been working on for the last 6 months or so is called Windows Reliability Component (RAC). It is a new feature in Vista which monitors the reliability of your machine. In fact, if you run the reliability monitor (another feature owned by my team) it displays data produced by RAC. We are working on some great new features for Windows 7 and I can’t wait until the PDC when people actually get to see some of our work.

What I Have Learned

Microsoft is a huge company. The opportunities here are immense. The trick is finding something that you are passionate about and pursuing that. Right now, I feel like I am just starting that journey. I have been a developer for almost 10 years and working at Microsoft has shown me that there is so much ahead of me in my career. There are real problems to be solved. Interesting technologies to contribute to.

So have I found my passion at Microsoft? I would say I am still looking. Windows Reliability is a great place for me to be right now. There is so much to learn and there are some great people on my team to learn from. I have often asked myself if I could work on anything I wanted to what would it be. Unfortunately I don’t have a great answer for that. So I am going to continue to search for that answer. And when I find it I will let you know.

Agile Windows

It has been interesting to follow the rise of the Alt.Net movement and the popularization of more Agile techniques in the .Net community. It is especially interesting when you look at the principles of Agile and wonder if they could ever scale to the point of a project like Windows. The way that Windows is engineered is nothing short of amazing. Although I think there is a lot an organization like Windows can learn from the Agile community, I don’t think Windows will be jumping on the Agile bandwagon any time soon. But within the small feature teams, like the one I work on, there is a lot of opportunity to apply TDD and continuous integration.

What I Am Looking Forward To

I am very grateful for the opportunity to work on a product like Windows which is literally used by about a billion people. I can’t wait to get feedback on Windows 7. Internally we have been using it for a while and we love it. Hopefully you will too. I look forward to experiencing everything that goes along with the release of a product like Windows.

Mostly, I am looking forward to all that I know is in store for me at Microsoft. I feel like I have barely had time to scratch the surface of all that Microsoft is about. Probably the best advice I have received since I have been at Microsoft has been this:

Your career at Microsoft is more of a marathon than it is a sprint.

I think of this advice whenever I wonder if I have accomplished enough during my first year. Have I made my mark? No. But I plan on it.


Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (99) | Comment RSSRSS comment feed

Paparazzi For Nerds

June 19, 2008 00:14 by Luke

Microspotting Being a relatively new employee at Microsoft, I have really enjoyed getting to know the culture and the wide array of people that work for Microsoft. To that end, I really enjoy the web site Microspotting which chronicles some of these interesting people. I was hooked as soon as I saw Golden Helmet and got a good laugh out of the Program Managa. Now I have to go figure out what kind of off beat thing I can do to become featured next...

BTW: I would live a free t-shirt.


Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (73) | Comment RSSRSS comment feed

Hidden Gem in .net 3.5 SP1 Announcement

May 12, 2008 15:38 by Luke

There is some great stuff hidden in Time Sneath’s post announcing the WPF aspects of the .net 3.5 SPI release:

It's been a long time in coming, but we're finally adding the much-requested DataGrid control to WPF. This will ship out-of-band at first, just after we release 3.5 SP1…

...Another oft-requested control is the Office Ribbon, and I'm sure you'll be pleased to know that we're also shipping an implementation of that control, also out-of-band, before the end of the year. The ribbon will be fully implemented in WPF,

So there you have it, there is a DataGrid and a Ribbon control coming to WPF! This is really cool. Something else that is really great is it appears that the WPF team is starting to adopt the “out of band” release model that other developer tools such as Asp.net MVC are using. I think this is a huge step forward in terms of integrating customer feedback into their products.


Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (43) | Comment RSSRSS comment feed

Vote to Improve Sql Management Studio

April 29, 2008 12:49 by Luke

I rarely write feedback to product teams but today I decided that I have had enough of this Identity Specification nonsense. How often do you create tables in Sql Management Studio which have some sort of identity column which is a primary key and an auto incrementing integer. Unless I am way off base, this is probably the most common scenario when creating a new table. So why does it take so many clicks? I have to click the Primary Key button to make the column a primary key and then scroll down in the Column Properties pane and find "Identity Specification" and expand it to change the value of "Is Identity" to "Yes".  That is just way too many clicks and scrolls for me.

So I have submitted a suggestion on Microsoft connect:

https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=340996

Vote for it if you agree. If you don’t agree, let me know why.


Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (52) | Comment RSSRSS comment feed

SubSonic BlogProvider for BlogEngine.net

March 28, 2008 03:06 by Luke

One of the things I love about BlogEngine.net is that it is built with extensibility in mind. On example of this extensibility is the ability to customize the provider which it uses to retrieve and persist posts, pages, categories, etc.

xmltodatabase Currently there are two providers that are supported out of the box: The XmlProvider and the MSSQLProvider. After I moved my blog from wordpress.com to BlogEngine.net, I decided I wanted to store my posts and such in a database rather than in xml files. So I set out to get the MSSQLProvider up and running. There is not, however, any established way to convert all of your content from the XmlProvider to the MSSQLProvider. So I first attempted to create my own quick little script to select the content from one provider and insert it using the other. But this didn't work. I ran into connection management problems within the MSSQLProvider code.

SubSonic to the Rescue

Then it dawned on me: what I really wanted was an easy to use data access layer to access the Sql Server tables which I wanted to store my blog content in. Well, since I was planning on using the schema which ships with BlogEngine.net, I already had the schema created. This is the kind of thing that SubSonic is great at - generating an easy to use data access layer given a database schema.

Subsonic ships with a console application called Sonic.exe which can be used to generate the data access classes. Since the database schema in this case is fairly static, I figured I could just generate the classes once and not worry about using a BuildProvider or anything fancy like that. So, here is the command line I used to generate the classes:

sonic generate /override /server HOMIE /db BlogEngine 
/userid OMMITED /password OMMITED /out C:\code\out 
/generatedNamespace BlogEngine.Core.Providers.SubSonic /stripTableText be_

I used the stripTableText option to replace take out the 'be_' prefix from each table which is present in the Sql schema. This results in classes which are named 'Post' and 'Page' rather than 'BePost' and 'BePage'.

ssconvert

Now that I had my data access layer, it was time to write the BlogProvider.

All Your Provider Are Belong To Us

Implementing the provider was pretty straight forward. There isn't really documentation I can find about exactly how the provider should behave so I based my code of the MSSQLProvider. I will not really go over the code too much here because there is not all that much to it. Mostly, it is a matter of mapping the SubSonic generated data access objects to the BlogEngine.net types like this:

private static Post GetPost(SubSonicPost p)
{
    Post post = new Post();
    post.Id = p.PostID;
    post.Title = p.Title;
    post.Content = p.PostContent;
    post.Description = p.Description;
    post.DateCreated = p.DateCreated ?? DateTime.MinValue;
    post.DateModified = p.DateModified ?? DateTime.MinValue;
    post.Author = p.Author;
    post.IsPublished = p.IsPublished ?? false; ;
    post.IsCommentsEnabled = p.IsCommentEnabled ?? false;
    post.Raters = p.Raters ?? 0;
    post.Rating = p.Rating ?? 0;
    post.Slug = p.Slug;
    
    return post;
}

Pretty boring and repetitive code.

Configuration

In order to configure your site to use this provider you must first configure it for SubSonic and then add the SubSonic provider. First, add the SubSonic config section to your confSections in your web.config:

<section name="SubSonicService"
   type="SubSonic.SubSonicSection, SubSonic"
   requirePermission="false"
   allowDefinition="MachineToApplication"
   restartOnExternalChanges="true"/>

And here is the SubSonic section:

<SubSonicService defaultProvider="Default">
    <providers>
        <clear/>
        <add name="Default" type="SubSonic.SqlDataProvider, SubSonic" 
         connectionStringName="BlogEngine"
         generatedNamespace="BlogEngine.Core.Providers.SubSonic"
         enableTrace="false" />
    </providers>
</SubSonicService>

Lastly, you can edit the blogProvider section:

<BlogEngine>
  <blogProvider defaultProvider="SubSonicProvider">
    <providers>
      <add name="XmlBlogProvider"
       type="BlogEngine.Core.Providers.XmlBlogProvider, BlogEngine.Core"/>
      <add name="MSSQLBlogProvider"
       type="BlogEngine.Core.Providers.MSSQLBlogProvider, BlogEngine.Core"/>
      <add name="SubSonicProvider"
       type="BlogEngine.Core.Providers.SubSonicProvider, BlogEngine.Core.Providers.SubSonic"/>
    </providers>
  </blogProvider>
</BlogEngine>

One Gotcha

The one problem I ran into was that SubSonic doesn't appear to run in a medium trust environments because it uses Tracing calls which require elevated trust. This does not mix well with BlogEngine.net and running in a medium trust environment. To get around this I commented out the tracing calls from the SubSonic source code and recompiled the SubSonic.dll. This is just a workaround until I find a permanent fix. You can read this forum post for more details.

So that's it. Here is the code. Feel free to give me any feedback or questions you have.

BlogEngine.Core.Providers.SubSonic.zip

UPDATE: The problem with medium trust and SubSonic has since been fixed so I will remove the SubSonic.dll from this site and just send you to the SubSonic site for download.

kick it on DotNetKicks.com
Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (284) | Comment RSSRSS comment feed

Dotnetkicks Penance

March 26, 2008 20:45 by Luke

penance I am a big fan of Dotnetkicks. I have found several interesting articles written by mostly lesser known authors (like myself) on that site. I have also received the benefits (more traffic) of getting some of my articles on the front page. As has been discussed previously, the “Dotnetkicks Effect” is very unpredictable due to the fact that there aren’t many people who regularly read the “Upcoming” section of the site. As a result, you can never really know if articles you submit to Dotnetkicks will get many views because there are so many different factors that contribute to your article being popular.

Sometimes this feeling of guilt comes over me. A little voice in my head says: “Why haven’t you visited the upcoming section of Dotnetkicks.com lately and given some kick love to your fellow unknown bloggers?” So I dutifully visit the site and read through the first 3 pages of upcoming articles to see if anything seems kick-worthy. I call this Dotnetkicks penance. Does anybody else do this? Could this possibly be the mystery contributing factor that keeps the steady flow of articles from the upcoming page to the front page? I imagine if my fellow guilty bloggers unite we could keep the signal to noise ratio on the front page at a healthy level.

kick it on DotNetKicks.com
Tags:
Categories:
Actions: E-mail | del.icio.us | Permalink | Comments (68) | Comment RSSRSS comment feed