PDA

View Full Version : .Net - LinqToLfsWorld


elkdanger
2nd June 2008, 12:14
Hello programmers,

I've just released the first full version of LinqToLfsWorld, which is a custom LINQ implementation used to query the LfsWorld Pubstat service through the .Net Framework.

If you're not quite sure what LINQ is or does, this is a good place to start (http://msdn.microsoft.com/en-us/netframework/aa904594.aspx). Essentially it allows you to write a Language INtegrated Query to transform one set of information into another (such as a url).

What this means is, using .Net and my library, you can query LfsWorld like so (in C#):

var query = from stats in LfsWorldContext.RacerStats
where stats.RacerName == "elkdanger"
select stats;This query will produce the appropriate url to send to LfsWorld and retrieve the racer's stats for you.

All of the available actions have been implemented according to v1.4 of the pubstat service, and all of the required and optional parameters have been implemented.

Another goal of the project has been to implement a caching system where you can easily cache your responses to save hitting the pubstat service too often, without having to write special code yourself. It also prevents you from hitting the 5-second tarpit if you're not a premium member; of course you can switch this off if you are a premium member.

The library also allows you to use a custom configuration section to store all your LinqToLfsWorld settings in the application configuration file (app.config or web.config). Included with the release download (link below) is an example website which shows you how to use this configuration section.

For the moment, rather than pre-empt any questions that arise on how to use it, if you post here I can answer questions as they come up (assuming someone tries this out of course).

So here's the good stuff. The library comes as a DLL which you reference into your .Net project, and from there you can get access to the LfsWorldContext (the hub for making your queries). Also contained within the download archive is full class library documentation.

You can grab the library on the LinqToLfsWorld project site (http://www.codeplex.com/linqtolfsworld). Included with the download is an example website which shows you how to use the library to perform a hosts query and how to use the custom configuration section. All the source code is available from the Source Code tab on that site too. I'm also going to provide some code samples and issues with the library on my blog at stevescodingblog.co.uk (http://stevescodingblog.co.uk) over the next week or so.

Here's the code from the sample website included which gives you an idea of what you can do with it:

using (LfsWorldContext context = new LfsWorldContext())
{

// Make sure caching is enabled
context.CachingEnabled = true;

// Handle any "request made" events
context.RequestMade += new LfsRequestHandler(context_RequestMade);

/* Make an initial query to the hosts action */
var query = from host in context.Hosts
orderby host.RacerCount descending
select new
{
host.RacerCount,
host.TrackName,
host.HostName,
host.QualifyingMinutes,
host.Laps
};

// Refine further - only show active hosts
var list = query.Where(host => host.RacerCount > 0).ToList();

// Bind to the grid view
LfsHostsGridView.DataSource = list;
LfsHostsGridView.DataBind();
}

Links

Download LinqToLfsWorld (http://www.codeplex.com/linqtolfsworld)
Query reference (http://stevescodingblog.co.uk/post/querying-lfsworld-with-linqtolfsworld/)
Explaination of the demo website (http://stevescodingblog.co.uk/post/linqtolfsworld-a-look-at-the-demo-website/)

BurnOut69
2nd June 2008, 12:22
Nice proof of concept with LINQ, I've been wanting to give it a go for some time now.

I'll try to test this when I have time - may be quite some time from now though.

elkdanger
2nd June 2008, 12:43
Nice proof of concept with LINQ, I've been wanting to give it a go for some time now.

I'll try to test this when I have time - may be quite some time from now though.

No probs - thanks for having a look. And if you get a chance to have a go, let me know what you think :)

DarkTimes
2nd June 2008, 13:51
Wow, very nice work! :thumb:

elkdanger
2nd June 2008, 14:40
Wow, very nice work! :thumb:

Cheers!

elkdanger
3rd June 2008, 22:16
Hi

Just to let you know I've updated my blog with a fairly lengthy post giving more details about the inner workings of LinqToLfsWorld, and more importantly how to use and configure it!

You can read it here (http://stevescodingblog.co.uk/post/linqtolfsworld-a-look-at-the-demo-website/) :)

elkdanger
23rd June 2008, 19:51
Hello,

Just to let you know v1.0 of LinqToLfsWorld has now been released! You can grab it from the project homepage (http://www.codeplex.com/linqtolfsworld).

The interface has essentially stayed the same since the 0.8 release at the beggining of the month, but the main difference is the expression engine which is used to translate your initial queries into a pubstat query; it's a lot more expressive and is a lot less fickle to work with.

My blog (http://stevescodingblog.co.uk) still has some discussion on using the library, and this week I plan to write up a bit more about exactly what changes have gone on since the preview release, and some more code examples.

For now, enjoy using it and if there are any issues with the library please email me, contact me on my blog or raise an issue on the Codeplex project page.

dougie-lampkin
24th June 2008, 17:19
Nice work, just the thing I was looking for earlier ;)

D/L'ing :)

elkdanger
24th June 2008, 21:49
Nice work, just the thing I was looking for earlier ;)

D/L'ing :)

Thanks bud. Let us know if you have any issues with the library :)

elkdanger
26th June 2008, 11:49
Hello,

I've written up a reference which shows all the queries you can make and what parameters you need; you can read it on my blog (http://stevescodingblog.co.uk/post/querying-lfsworld-with-linqtolfsworld/) :-)

Also, if anyone is after some VB.Net samples of these queries, please ask and I'll sort some out.

elkdanger
11th July 2008, 15:21
Hi

I've just released LinqToLfsWorld (http://www.codeplex.com/linqtolfsworld) v1.0.2, which has a couple of minor bug fixes, support for Xml and Json serialization/deserialization and some helper constants for working with Car, Track ident and Steering type parameters.

You can grab it on the 1.0.2 release page (http://www.codeplex.com/linqtolfsworld/Release/ProjectReleases.aspx?ReleaseId=14653).