DataReaders, LINQ to XML and Range Generation

I’m doing a bunch of database / XML stuff @ work, so I decided to use to VS08 beta 2 so I can use LINQ. For reasons I don’t want to get into, I needed a way to convert arbitrary database rows, read using a SqlDataReader, into XML. LINQ to SQL was out, since the code has to work against arbitrary tables (i.e. I have no compile time schema knowledge). But XLinq LINQ to XML helped me out a ton. Check out this example:

const string ns = "{http://some.sample.namespace.schema}";

while (dr.Read())
{
    XElement rowXml = new XElement(ns + tableName,
        from i in GetRange(0, dr.FieldCount)
        select new XElement(ns + dr.GetName(i), dr.GetValue(i)));
}

That’s pretty cool. The only strange thing in there is the GetRange method. I needed an easy way to build a range of integers from zero to the number of fields in the data reader. I wasn’t sure of any standard way, so I wrote this little two line function:

IEnumerable<int> GetRange(int min, int max)
{
    for (int i = min; i < max; i++)
        yield return i;
}

It’s simple enough, but I found it strange that I couldn’t find a standard way to generate a range with a more elegant syntax. Ruby has standard range syntax that looks like (1..10), but I couldn’t find the equivalent C#. Did I miss something, or am I really on my own to write a GetRange function?

Update: As expected, I missed something. John Lewicki pointed me to the static Enumerable.Range method that does exactly what I needed.

Morning Coffee 112

  • The Lee Holmes over at the Powershell Team Blog writes about alternatives to the “decades-old” Windows console host. Powershell Plus looks awesome. PoshConsole also looks pretty cool (though far from finished yet) and is free.
  • WL IDWeb Authentication SDK has been released. Details on the WL ID team blog. It looks like what Passport SDK provided for quite some time, but now it’s free. There’s also a client auth SDK in development. (via Dare Obasanjo)
  • Libor Soucek leaps to the wrong conclusion about not differentiating enterprise & support systems. Of course, different systems will have different availability requirements. But what happens when we connect them together? We can’t let the support system effect the availability of the enterprise system, right? To me, that implies either a) the support system now needs to conform to enterprise system availability requirements or b) we need some other mechanism (like async durable messaging) to act as a buffer between them. Personally, I like “b”.
  • Nick Carr points to an article The Trouble with Enterprise Software by Cynthia Rettig. Cynthia writes that while the massive complexity of enterprise software, especially large-scale ERP systems like SAP, significantly hinder it’s value. It’s a must read. Choice quotes:
    • “It is estimated that for every 25% increase in complexity in the tasks to be automated, the complexity of the software solution itself rises by 100%.”
    • “The notion of reusable software works on a small scale. Programmers have successfully built and reused subroutines of standard functions. But as software grows more complex, reusability becomes a difficult or impossible task.”
    • “Hope, unfortunately, has never been a very effective strategy.”
    • “Is enterprise software just too complex to deliver on its promises? After all, enterprise systems were supposed to streamline and simplify business processes. Instead, they have brought high risks, uncertainty and a deeply worrying level of complexity. Rather than agility they have produced rigidity and unexpected barriers to change, a veritable glut of information containing myriad hidden errors, and a cloud of questions regarding their overall benefits.”

Morning Coffee 111

  • I’m not sure if I should laugh or cry at Nick Malik’s definition of politecture. I mean, it’s funny so I’m laughing, but it’s so true that it makes me want to cry.
  • Don Box comments on retiring the tenets. It’s good to see him say “please God tell me we can do better” than CLR interfaces or WSDL.
  • Looks like the P2P APIs are finally getting the managed treatment in .NET FX 3.5. A long time ago, John deVadoss asked me what an enterprise system like CRM might look like if it used a peer-to-peer approach instead of client-server. If I had any free time, I’d prototype one out on this API. (via Mike Taulty)
  • Scott Guthrie goes back to his LINQ to SQL series to tackle Stored Procs and UDFs. Being able to use UDFs inline with LINQ queries is very cool. However, it seems to me that LINQ discourages the use of stored procs. As a developer, I’d rather write LINQ queries than stored procs, if I can. The probably puts me at odds with DBAs who’d rather all DB access be via stored procs they control.
  • Soma writes about new MSBuild enhancements in VS08: multi-targeting and parallel build.
  • I just discovered Vista Battery Saver. Basically, it turns off Aero and Sidebar when you’re on battery. I’m traveling to Chicago next week, so we’ll see if it has much impact on my battery life. (via Plenty of Code and Larkware)

Hawkeye on Office Communicator 2007

I’ve been running Office Communicator 2007 (aka OC07) and the Polycom CX200 phone for a couple of weeks now. Here are a few thoughts on the experience.

  • Multiple Points of Presence. I’ve got OC07 installed on both my desktop and laptop. Unlike WL Messenger with it’s “you’ve signed in on another machine” messages, OC07 happily lets me log in both places. If I get an IM, it pops up on both screens. If my phone rings, I can answer it on either machine.
  • Simultaneous Ring: When I get a call, both my machines and my mobile phone ring. I can answer in whatever place I want. For the most part, people know my mobile phone number, so I’ll need to get out the word to call my work number instead. (First step: re-program my work number in my wife’s phone.) I can also choose to forward my work calls directly to my mobile phone, though I tend to be better about checking work voice mail so I doubt I’ll use that feature.
  • Outlook Integration: The previous version of OC had PBX system integration and Outlook. So you could call someone simply by right clicking on their name in Outlook, OC would talk to your PBX system to place the call. Unfortunately, when we moved offices we also got new IP phones that didn’t integrate with OC05. Now that I’m on OC07, my computer is my phone and all the Outlook integration works again.
  • Status Indicator on the Phone: It’s minor, but the USB handset has the OC logo that lights up the same as your status. If you’re available, the logo is green. Busy? The logo is red. Do Not Disturb? Logo flashes red. Nice touch.
  • Missed Conversations: The other day when I was in training, a colleague IMed me but I was away from my desk and my laptop was turned off. The IM conversation ended up in my inbox like an email. Doesn’t help for “You there?” IMs, but when he realized I wasn’t there, he just wrote the information he wanted me to know and I got it the next time I logged in.
  • No Clock: A very minor sticking point, but the old phone system had a clock on the phone so you could easily see what time it is, even if your machine is locked. The USB handset doesn’t have a clock and I miss it. Not nearly enough to go back to my old phone, but enough that I’m going to go buy a little desk clock.
  • No Keypad: I didn’t miss it right off the bat, but the lack of a keypad is a hassle. If I have to look a phone number up, having the ability to place the call inside of Outlook is slick. If I know the number off the top of my head (home, wife’s cell phone, helpdesk) then having to type it into Communicator is a pain. Also, if you’re calling one of those automated systems, keying the numbers on the software keypad is a real hassle.
  • IM to Phone: Since I have to look my wife up in Communicator to call her anyway, I can shoot her an IM before  call her. The kids nap in the afternoon, so if I catch her online, it avoids a potentially waking ring.
  • Extra Speaker: When you set up the USB phone, it sets itself up as the default speaker. That’s typically not what you want, but it’s easy enough to change in the sound control panel. However, when my earphones broke and I found myself sans audio, I changed it back until I could get new earphones. The only problem with this approach is that in a cube environment (like I work in), the noise from the phone speaker is a bit loud. You can pick up the receiver and listen that way without bugging your neighbors, but after about 20 seconds, it reverts back to speaker phone for no apparent reason.

Morning Coffee 110

  • Monday @ Gamefest, the XNA team announced XNA Game Studio 2.0. The two big new things are support for the entire VS product line (1.0 only works on VC# Express) and the addition of networking APIs. Let’s Kill Dave has a good wrapup of the announcements from Gamefest Day One.
  • Speaking of Xbox 360, I played thru the demos of Stranglehold and Bioshock. Two thumbs up on both. It’s gonna be an expensive year for Xbox gamers.
  • Mark Cuban noodles on taking your house public. “Why not create a market or exchange where homeowners can sell equity in their homes?” I’ve thought about this myself from time to time. However, Mark thinks making it happen would “probably take the country’s biggest banks working together”. I wonder if there’s a more Web 2.0 social lending approach that would work better.
  • Jeff Atwood calls virtualization as “the next great frontier for computer security”. I agree 100%. But I don’t think the action is going to be in “full-machine” virtualization like Virtual PC. Rather, it’s going to be sandbox virtualization. Jeff mentions GreenBorder (now part of Google) but it’s not the only solution. Some time ago, Microsoft acquired SoftGrid which uses sandbox virtualization for application deployment, but using SystemGuard for security sandboxing seems like a logical step.
  • The WCF LOB Adapter SDK has released. Sonu Arora has the details. As part of the Integration team @ MSIT, I have a feeling we’re going to become fairly familiar with this technology. (via Jesus Rodriguez).
  • Speaking of Jesus, he thinks the six new SCA4SOA committees are “going to help”. Why? Because inventing technology in committee has turned out so well in the past?
  • John deVadoss cements BPM’s fad du jour status by contrasting “big” BPM and “little” BPM. It’s fairly obvious to me that big *anything* just doesn’t work in the enterprise. But I worry that little *anything* doesn’t work that well either. So how long until someone (probably Nick) starts arguing for “middle out” BPM?
  • David Bressler wonders “What is it about registries that everyone thinks is a panacea for all things SOA?” Amen, Brother! Joe McKendrick claims it’s required for governance, but then gets to what I think is the *real* reason for focus on registries: the “registry is a tangible offering” that vendors can sell. Just because it’s productizable doesn’t mean you need it.
  • Hartmut Wilms responds to my retire the tenets post, but he seems to contradict himself. On the one hand, he suggests that “the four tenets just expressed, what “almost” everybody outside the MS world knew already”. But then he goes on to dispute that the SO paradigm shift has even occurred! Hartmut, I’ll grant you that WCF (among other similar stacks) are way too focused on “you write the classes, we’ll handle the contracts and messages”. On the other hand, if you don’t provide a productive interface that most everyone can pick up and run with, the technology won’t get adopted in the first place.