I held a presentation at UBISOFT Buchares headquarters for the RONUA local programmers user group recently as I've announced earlier. Here's the contents, step-by-step, final code and slides.
I was recently tasked with rewriting an app component by leveraging Reactive Extensions. I knew little about Rx (the short form of Reactive Extensions) and all I remembered was that it has two interfaces IObservable and IObserver and it seemed dull at that time.
Basically the component enables search without needing to hit ENTER or a "Go!" button, although provides for these. After the user finishes typing an async request goes to the data store and searches for the phrase entered and fetches the results. In the original implementation the component used a lot of timers, event handlers, private fields all making up a nice spaghetti bowl of code.
Let's do this step by step and see how our little (demo) app develops. Fire up Visual Studio 2012 and start a new WPF project (.NET 4.5 preferably). The very next thing we'll install Rx. Right click on the project in the Solution Explorer and select "Manage NuGet Packages" (you can also use the Package Manager Console if you like it better). Search online for "Reactive Extensions".
In the result lists (this requires a functional internet connection) select 'Reactive Extensions – WPF Helpers' (the nice thing about NuGet packages is that it automatically resolves and installs all the dependencies). Accept the EULAs (you know what's the most common lie told these days? "I have read and accepted the terms of the license" ).
In our demo we will use Bing as the data store which we'll target through our searches (sorry, Google was too difficult to setup, offered less search requests per month and no C# demo code. Thanks Google, thanks again.). In order to do this you will need a Microsoft Account (I guess we all have one these days). Go to http://www.bing.com/developers/ and then select "Search API" -> Start now (this will lead you to https://datamarket.azure.com/dataset/5BA839F1-12CE-4CCE-BF57-A49D98D29A44 ). There are paid subscriptions and a free subscription. Hit signup and go through the process (leave a comment if you are unable to go through this process).
Read more: Codeproject
QR: