Wednesday, August 6, 2008

Identifying the differences between CallContext Data Slots

Recently I was working on a server side caching strategy for permissions data. The key to the strategy was to place a user's permissions returned from a database call into the CallContext of WCF service. The code to do this looked something like this...

CallContext.SetData("permissionsKey", myPermissionsData);

All subsequent requests for permissions data would then be returned from the CallContext's cache permissions, thereby saving me from having to make redundant database calls for data that I already have.

myPermissionsData = (PermissionData)CallContext.LogicalGetData("permissionsKey")

Simple caching strategy...

During my testing I found that my cached data was not being returned. After further investigation I realized that I was setting the data using the CallContext's SetData method, but I was getting the data using the CallContext's LogicalGetData method. Come to find out, these are not the same. Seems there is a LogicalGetData method, LogicalSetData method, GetData method and SetData method on the CallContext object. So, it was a simple fix to use the LogicalSetData method in conjunction with the LogicalGetData method when implementing my caching strategy.

But why are there two methods that seemingly do the same thing? The documentation on MSDN doesn't really specify the differnce between the two.

Well... after doing some resarch and finding a post by Lucian Bargaoanu on the subject it seems that the difference has to do with AppDomains. Come to find out there is a LogicalCallContext and an IllogicalCallContext. LogicalCallContext will flow across appdomains. It will do this regardless of what type of object you have placed in context. The object doesn't have to implement ILogicalThreadAffinitive. When you call SetData with an ILogicalThreadAffinitive object, the data is set in the LogicalCallContext. When you call GetData it will first look in the LogicalCallContext and then in the IllogicalCallContext. You cannot have the same key in both CallContext(s).

In summary, objects stored using SetData will only flow across AppDomains if they implement ILogicalThreadAffinitive. Objects stored in LogicalSetData will flow across AppDomains even if they don't implement ILogicalThreadAffinitive. LogicalSetData handles seems to handle the ILogicalThreadAffinitive implementation for you.

Labels: , , , ,

Tuesday, July 29, 2008

Cool LINQ Tool

There is a cool LINQ tool called LINQPad available from O'Reilly.

It is pre-loaded with a bunch of great examples from C# 3.0 In a Nutshell by Joseph Albahari and
Ben Albahari

Check it out...

Labels: , , ,

Thursday, May 29, 2008

Neat coding tricks with LINQ

Igor Ostrovsky has compiled a list of 7 tricks to simplify common coding tasks using LINQ.

The LINQ approach to converting sequences or collections is very elegant.

Here are 101 other samples

Labels: , , ,

Tuesday, May 27, 2008

Uninstall SSRS if you are not using it.

I came across a good article over at SQL Server Central. I highly recommend signing up on their site if you haven't done so already. I am always finding good info over there...

Anyway, the article points out that you should really uninstall SSRS if you are not using it. Simply stopping and disabling the service does not fully prevent SSRS from attempting to validate it's encryption keys. I am not certain what problems this would cause other than filling up your event logs and needlessly utilizing you server's CPU cycles, but it is disconcerting that a service you assume is inactive in actuality still has live hooks into your server.

Labels: , , ,

Friday, May 23, 2008

Visual Studio goes dark

I have been noticing a trend. Many developers are beginning to utilize darker color schemes in their VS IDE. I am not sure when or why this started. There are several posts floating around that contain some nice schemes. Most notibly is Tomas Restrepo's site.

Some of these darker schemes are nice, while others tend to remind me of the old 3270 emulators and CICS terminals. Its interesting to note that the IDE for Microsof Expression Blend makes nice use of black and gray.

I have adopted a scheme that I am really enjoying. Go grab it here...


*** UPDATE ***
I have since reverted back to a lighter color scheme. However I am not using the VS Default. Something about all the dark colors became irritating to me. Just personal preference I guess.

Labels: , , , ,

Thursday, May 22, 2008

Silverlight 2.0 - Savior of the Internet or latest fad?

Recently I had the opportunity to build a control for SnagAJob.com in Silverlight 2.0. My first impression is...Wow!... This is going to change a lot of things.

I think it is important to mention that I am coming to Silverlight development late. I never played with the 1.0 or 1.1 releases. I never had to go through the early pains of discovery associated with the technology. (ahh...remember the early days of the AJAX Toolkit). First off, I want to give a big "hats-off" to the team over at Silverlight.Net. If you have not been to the site, you are definitely missing out. The Getting Started section is the perfect place to well.... get started. They also have a fabulous set of video tutorials and gallery samples (many with code) to get you up and running on Silverlight.

If you are new to Silverlight, developing in Silverlight 2.0 with managed code is very intuitive, especially if you have any prior experience with Windows Forms development. An easy way to think about the design paradigm is that of a Windows Form application running in the browser. BUT... it is so much more... It is Flash like in nature in that it runs as an embedded control in your page. You simply have to install the Silverlight runtime. Hopefully Microsoft will begin pushing out the runtime as part of it's Windows Update.

Could Silverlight be the death of AJAX? Silverlight is based upon a subset of WPF. The ability to develop web content using XAML will truly open up the Internet to a host of creative and visually stunning applications. The problem I see with AJAX is that it still requires the mixing of technologies. (HTML, JavaScript, Services). While Silverlight 2.0 doesn't completely eliminate the technology mash-up, I believe the unified development environment (XAML, Managed Code)that Silverlight 2.0 provides will super charge the development of visually attractive and highly interactive user experiences.

Could Silverlight be the death of ClickOnce? In some circumstances it might. It provides the end-user experience required by many applications that are currently written as Windows Forms applications and it's deployment scenario is possibly simpler than that of ClickOnce. To deploy a Silverlight application, you only need to copy the latest-n-greatest bundled version of your control (.xap file) up to your web server. Silverlight is cross-browser compliant, so the headaches of ClickOnce deployment for end-users running Firefox is avoided.

Silverlight is obviously not a silver-bullet. There are plenty of short comings that will need to be overcome, but I believe there are good things in store for this technology.

My friend and colleague Kevin Hazzard has been doing some great presentations and code camps lately on Silverlight. Check out his GotNet blog for some great reading.

Labels: , , , ,