Facebook C# SDK - Outercurve Foundation and v6 RTW

A lot has been happening around Facebook C# SDK for a past few months. Earlier this week we official released the v6 RTW of SDK and today I am extremely excited to announce that Facebook C# SDK is now part of the Outercurve Foundation. You care read more about it at http://www.outercurve.org/News/articleType/ArticleView/articleId/54/Outercurve-Foundation-Accepts-Facebook-C-SDK-Project

Overtime Facebook C# SDK has gone over numerous internal architectural changes that allowed us to easily target wide variety of platforms. Currently we support .NET 3.5 Client Profile, .NET 4.0 Client Profile, Silverlight 5 and Windows Phone 7.1 (Mango) and even .NET 4.5 (VS11 Beta) and Windows 8 Metro Style Applications (Windows 8 Consumer Preview). This has all been possible due to internal sub-projects that SDK uses which most of you might not even know it existed.

Facebook C# SDK consists of another 3 projects bundled in one Facebook.dll.

HttpHelper is a mockable HTTP helper for .NET 2.0+/SL4+/WP7/WinRT with support for Task Parallel Library as well as async and await in platforms where available. HttpHelper has allowed us to easily use our existing codes to port it easily to multiple .NET platforms. Here is a simple synchronous example of complex Twitter Streaming Api with HttpHelper and SimpleJson demonstrating how easy it is to use.

private static void StartTwitterStreamingApiSync()
{
    var httpHelper = new HttpHelper("http://stream.twitter.com/1/statuses/sample.json");
    httpHelper.AuthenticateUsingHttpBasicAuthentication("username", "password");

    using (var responseStream = httpHelper.OpenRead())
    {
        using (var reader = new StreamReader(responseStream))
        {
            while (true)
            {
                dynamic json = SimpleJson.DeserializeObject(reader.ReadLine());
                string text = json.text;
                Console.WriteLine(text);

                Console.WriteLine();
            }
        }
    }
}

And an asynchronous equivalent of the above code using async/await with support for cancellation.

private static async Task StartTwitterStreamingApi(CancellationToken ct)
{
    var httpHelper = new HttpHelper("http://stream.twitter.com/1/statuses/sample.json");
    httpHelper.AuthenticateUsingHttpBasicAuthentication("username", password);

    using (var responseStream = await httpHelper.OpenReadTaskAsync(ct))
    {
        using (var reader = new StreamReader(responseStream))
        {
            while (true)
            {
                dynamic json = SimpleJson.DeserializeObject(await reader.ReadLineAsync());
                string text = json.text;
                Console.WriteLine(text);

                Console.WriteLine();
            }
        }
    }
}

SimpleJson – SimpleJson is the default lightweight json serializer/deserializer for Facebook C# SDK. All of the json parsing and dyanmic that you see in the SDK has been possible due to SimpleJson.

ReflectionUtils – SimpleJson contains another internal helper project called ReflectionUtils which related to all the reflection helper methods.

Dividing Facebook C# SDK into internal sub-project has allowed us to easily target multiple platforms. In fact it was so easy that after porting ReflectionUtils, SimpleJson and HttpHelper to WinRT (Windows 8 Metro Style Application), it took us less then 5 minutes to port the entire Facebook C# SDK to WinRT. If you are creating applications that target wide variety of .NET platforms, we believe you can take advantage of both Facebook C# SDK and these sub-projects which are also now part of the Outercurve Foundation.

All these project are open source and is available under the Facebook C# SDK Github organization which can be found at https://github.com/facebook-csharp-sdk

blog comments powered by Disqus