June 2006 Entries

Downloads, Downloads Everywhere

A real programmer on the Win-OT list has been waxing eloquently about apt-get. He does have a point. apt-get is one of the command line tools that can administer software packages on Linux distros. apt-get manages all the gnarled dependencies and makes installing new software on Linux mostly a breeze. Throw on one of the GUI front ends for apt-get, and new software is only a few clicks away. Want to program in Ruby? Click - click. Want a web server? Click - click. It's cool (and by cool I mean totally sweet). The equivalent to apt-get on a Windows desktop is, I guess, a combination of...

Page Scraping

Q: I want to programmatically retrieve a web page and parse out some information inside. What's the best approach? A: For fetching the contents of a page, the simplest class to use is the System.Net.WebClient class. For more advanced scenarios that require cookies and simulated postbacks to the server, chances are you'll have to graduate to the System.Net.WebRequest and WebResponse classes. You'll find a lot of material on the web that demonstrate how to use these classes. If you have to pull specific information out of a page, then the "best approach" will depend on the complexity of the page...

Importance: High

It's a quiet day. Too quiet - you think to yourself. Then it happens…. A message arrives in your Inbox, but not just any message. This message is adorned with the Red Exclamation of Importance! You can feel the adrenaline in your fingers as they snap the mouse into position. A breathless moment during the double-click, and the message is now in front of your eyes: Hi everyone! Just a little reminder to get those TPS status reports in by next week. Also, we've change the passcode for next month's conference call – it is now 6661212. Thanks! :) Oh. It's from that...

Themes For ASP.NET User Controls

Q: I can't apply a Theme attribute to my user control. How am I supposed to theme and skin my user controls? A: User Controls don't have a theme property, but when you assign a theme to a page, the theme does influence all of the controls in the page. A user control uses the theme of its page. If the theme includes CSS files, then ASP.NET will link to the CSS files. Any styles inside the CSS that are applicable to classes, names, and markup in the user control will style the user control. If the theme includes skins,...

URL-Rewriting breaks my HREFs

Q: I've been using the RewritePath method of the HttpContext class to rewrite URLs since ASP.NET 1.1. Everything was working until I moved my CSS files inside an ASP.NET 2.0 Theme directory. ASP.NET automatically writes out link tags for my stylesheets, but the href inside is broken. How do I fix this problem? A: When rewriting URLs, don't use the RewritePath method that only accepts a path parameter, use the new overload that accepts a path parameter and a rebaseClientPath parameter. Pass a value of false for rebaseClientPath and the auto-magic injection of stylesheets will work. Full explanation: The href...

Software Librarian

One of the nice benefits of an MSDN subscription is having a boatload of software for development, test, and experimentation. The drawback is the boatload of discs that accumulate during the year. Consonica Software has a product they call the “Software Librarian for MSDN”. After a quick install, you tell the software what type of subscription you have, and what products you use, and then it tells you which discs to feed into the computer. Sometime later, everything you use is now copied to a hard drive. The monthly updates are a breeze, and no more fumbling around for discs. Watch...

The Base Activity Library in Windows Workflow

The latest OdeToCode article covers the base activity library in Windows Workflow. We look at the activities to communicate with local and remote services, evaluate rules, listen for events, and every other activity that ships in the WF toolbox. Read it here: Windows Workflow: The Base Activity Library As always, I appreciated any feedback you can offer.

The System.Exception to the Rule

Two weekends ago, I did presentations on ASP.NET master pages and Windows Workflow at the MAD Code Camp in Reston, Virginia. A bit of .NET trivia came up during the workflow session when we talked about fault handlers and the types of exceptions we can throw and catch in .NET. Despite the fact that this code: static void Main(string[] args){    throw "You've done sometihng wrong!";} .. results in a compiler error (The type caught or thrown must be derived from System.Exception), the CLR itself has no such restriction. I planned on doing some research and putting together a blog post, but Jason...

This Post Has No Name

One of the hardest tasks in software is finding a good name. Names for variables, classes, libraries, and products requires countless mental cycles - as it should. Names are a serious business. In software, names bring imaginary things to life. Good names lead to readability, shared vocabularies, and emotional attachments. Bad names lead to confusion, pain, and assistance from highly paid consultants. The Art of Naming Variables Have you ever wondered how many hours the software world has spent inventing naming standards? You know the "prefix this" and "suffix that" and "start all of these with a capital C" documents. These...

The Mysteries Of System.Messaging

The majority of the .NET base class library feels clean and intuitive. Every so often though, you come across some oddballs. For instance… Given a MessageQueue object named queue, what does the following code produce at compile time? foreach (Message message in queue){    // ...} The code results in a warning: 'System.Messaging.MessageQueue.GetEnumerator()' is obsolete: 'This method returns a MessageEnumerator that implements RemoveCurrent family of methods incorrectly. Please use GetMessageEnumerator2 instead.' Wow! Deprecating the GetEnumerator method is serious business. Using foreach is now out of the question. The AcknowledgeTypes enum baffles me. There seems to be a lack of symmetry in the names....

No Love from Word

One of the features in Word 2007 Beta 2 is the ability to author blog posts. Joe Friend announced the feature, and there have been a number of follow up posts:  Word Blog HTML  Quality XHTML In Word 2007's blogging tool  Word XHTML - Compliance and Styles Authoring blog posts from Word is a great feature, but I hope Word 2007 will also include the ability to export any document into a clean, trim XHTML file. A tall order, I'm sure, but I'd take this feature over PDF export any day of the week (and twice on Sundays). I tried to setup a blog...

Part II of How To Screw Up HandleExternalEvent Activities in Windows Workflow

We left off in Part I with a contract, an event args class, and all the metadata we need to raise events to a workflow. As Captain Hazelwood once said, what could possibly go wrong? Let's start with an implementation of our payment processing contract. The code has a subtle problem, and will cause an exception. class PaymentProcessingService : IPaymentProcessingService{    public void ProcessPayment(Guid id, double amount)    {        // ... do some work work work                // ... then raise an event to let everyone know        PaymentProcessedEventArgs args;        args = new PaymentProcessedEventArgs(id, amount);                EventHandler<PaymentProcessedEventArgs> evh;        evh = PaymentProcessed;        if (evh != null)            evh(this,  args); // boom!    }    public event EventHandler<PaymentProcessedEventArgs>         PaymentProcessed;} The exception is an EventDeliveryFailedException,...

Part I of “How To Screw Up HandleExternalEvent Activities in Windows Workflow”

In learning Windows Workflow with Beta 2.2, I’ve managed to foul up events in every possible way. Well, perhaps not every possible way, I’m sure I’ll find a few more techniques as time goes on. Here are some pointers for anyone else who runs into problems raising events with WF. First, it helps to have a firm grasp of how events reach a workflow. Events are one of the mechanisms we can use to communicate with a workflow instance. An event can tell a workflow that something interesting has finally happened, like when a check arrives to pay the balance...

Branching and Merging Anti-Patterns

Chris Birmele has only posted once, but the document he authored is a good read. The document is a tool agnostic Branching and Merging primer. Excerpt: Using branches provides better isolation and control of individual software assets and increases productivity because teams or individuals can work in parallel. But it also implies an increase of merge activities and therefore risk because branches have to be reassembled into a whole at some point in time. Chris goes on to describe common branching strategies, and names some anti-patterns. Some of his anti-patterns that I’ve witnessed include: Merge Paranoia - because the company spent a massive amount of...