Karisma: Our Surprise Baby!

clip_image002At 3 am on the morning of October 31st, my wife Zuzana delivered our second child: Karisma Sarah Elizabeth Sneed. To everyone’s amazement, the baby arrived while we were still at home, before we had the chance to get in the car and go to the hospital! In fact, she arrived even before the paramedics came on the scene, leaving it to myself and Delilah, our birth assistant (called a “doula”) to catch the baby. When Zuzana’s water broke and her contractions were coming about every 3 minutes, I asked her to get in the car and leave. But, recalling the length or her first labor, she refused, and the doula was backing her up.

Outnumbered two to one, I acquiesced. Finally, when the contractions were growing more intense and lasting over two minutes, I issued an ultimatum: we are leaving NOW! She was in the bath tub, so I opened the drain plug to let the water out. As we were lifting her out of the tub (she could not get up on her own strength), she exclaimed, “Baby!” Sure enough, the baby’s head was starting to come out. I immediately called 911. Then as I looked down, I saw the baby’s whole head pop out. Before I knew it, the doula caught the baby and we both lifted her up, placing it on Zuzana so she could bond and start breast feeding.

The 911 dispatcher had me tie off the umbilical cord with a shoe string. By the time the paramedics arrived, Zuzana was sitting with the baby in her arms on a small ledge inside our bath tub (it’s a large garden style type). The baby was crying and Zuzana was doing fine, relieved that the whole thing was pretty much over. The paramedics allowed me to cut the umbilical cord with a scalpel. Then they loaded her on a gurney and into the ambulance. After a about a 20 minute ride (averaging 70 mph), we arrived at the hospital, Medical Center of McKinney (Texas), where our doctor was waiting for us. Even with all the commotion, I managed to click off a few photos using my cell phone.

clip_image004

clip_image006

clip_image008

clip_image010

clip_image012

Although unexpected, the experience was not as traumatic as I thought it would have been. I’m just grateful we did not have to deliver the baby in the car! All in all, a home birth was a refreshing experience. However, I would recommend at least a midwife. That said, our OB-GYN, Dr. Jennifer Allen, did a great job with the latter parts of the delivery and repairing the minor injuries Zuzana sustained as a result of the fast delivery. After a day of recovery at the hospital, Zuzana, Kerrigan and I are looking forward to integrating Karisma into our expanding family.

Posted in Personal | 11 Comments

The WPF Data Grid – Finally!

Microsoft has just released a full-fledged data grid for WPF, along with date picker and calendar controls. There is also a WPF Office Ribbon control. To get the binaries (and source code!), go here:

http://www.codeplex.com/wpf/Release/ProjectReleases.aspx?ReleaseId=15598

Enjoy.

Posted in Technical | Leave a comment

PDC 2008 Sessions – Live!

For anyone unable to attend the Microsoft Professional Developers Conference (PDC) this week in Los Angeles, it is possible to view live recordings of the sessions here:

https://sessions.microsoftpdc.com/public/timeline.aspx

Just select the session you want to view, and then click the play button to view the recording.

I’ve also started collecting some of my favorite sessions (like the one by Anders Hejlsberg on C# 4.0) on my delicious web site:

http://delicious.com/tonysneed_wni3/pdc

Enjoy.

Posted in Technical | Leave a comment

Configure WCF for Legacy ASMX Clients

The nice thing about WCF is its ability to reach all types of clients, including those set up for communication with a traditional ASMX web service. In many cases, those clients reference a URL ending with an .asmx extension, and it’s not always practical to re-configure clients to use a WCF service that ends with .svc. It would be great if you could configure a WCF service with a basic http binding to respond to requests ending with .asmx.

There is quite good support for this scenario in WCF, and here is a blog post describing how to change web.config:
http://blogs.msdn.com/wenlong/archive/2007/09/18/how-to-use-asmx-extension-to-handle-wcf-requests.aspx

The key here is to specify the WCF ServiceBuildProvider to the .asmx extension, which enables you to create a WCF service file that includes a ServiceHost directive, but end it with .asmx instead of .svc. Note that if you are running IIS is ASP.NET compatibility mode, you’ll also want to change the HttpHandler for .asmx to the WCF HttpHandler. You can download a sample project here.

Posted in Technical | 2 Comments

What’s Going on with our Economy?

Unless you’ve been living in a cave, you’ve undoubtedly heard about the turmoil in the global financial markets and the dramatic plunge in stock prices that took place over the past week. But while there are a lot of big, scary headlines out there, I haven’t seen very much in-depth analysis to help folks get a better understanding of what’s happening and, more importantly, figure out what to do with savings and retirement accounts that include stock-owning mutual funds. Because I have some brokerage accounts at Charles Schwab, I receive articles from their staff which I have found informative. Here are links to two of the articles, which can help you get a better handle on what’s happening and determine how best to respond.

Big TARP Over Credit Circus, written by Liz Ann Sonders on Oct 9, 2008
Depression Fears Overblown, written by Mark Riepe on Oct 9, 2008

The first article is the best analysis I’ve seen on the current financial crisis and what’s driving it. The second article compares this crisis to the Great Depression, to give some perspective on what we’re going through. The bottom line is that, while we’re probably in for some tough times ahead, there’s no reason to think we’re headed for a depression. The reason is that many more safeguards exist today than were in place prior to the Great Depression (including FDIC insurance for bank deposits), and, more importantly, our government is willing to use some big guns to avert a real calamity.

If you haven’t done so already, you may want to consider moving some of your investments from stocks into bank CD’s, at least for the short-term. I say “some investments” because selling stocks now will lock in current losses and you may lose out on a rebound. That said, I believe we have yet to see the bottom of the market crash and are probably at least 2-3 months away from the point at which the credit markets are going to start flowing again, which is key to both an economic recovery and an increase in stock prices. On the other hand, if I were contributing to a retirement account (and still 15-20 years away from needing the money), I would probably start buying some equities, because last week’s correction, if nothing else, probably put stock prices closer to their true value, which was inflated due to the over-availability of easy credit.

The scary part to all this is how the general economy will fare and whether measures taken by the Treasury and Federal Reserve will have their desired effect. Most of us will need to live more prudently, cutting back on unnecessary expenses, reducing debt levels and increasing personal savings. That will also have an impact on the economy, which has become overly dependent on consumer spending, but it is probably the best strategy for buttressing your household finances in times of economic uncertainty.

Posted in Personal | 1 Comment

Managing Conflicts in LINQ to SQL

There are a couple of gotchas when managing concurrency issues with LINQ to SQL. First, when you catch a ChangeConflictException and allow the other user’s changes to win by calling ResolveAll on the DataContext’s ChangeConflicts property and passing RefreshMode.OverwriteCurrentValues, other non-conflictual changes will not be persisted because LINQ to SQL will roll back the transaction it started whenever there is an exception. To avoid this behavior, you need to wrap the call to SubmitChanges inside a “using” block that creates a new TransactionScope. Then right before the ending brace, you need to call Complete on the TransactionScope, which will ensure that the changes you tried to persist when calling SubmitChanges will in fact commit, even when you catch a ChangeConflictException.

// Persist non-conflict changes even when catching an exception
using (TransactionScope txScope = new TransactionScope())
{
    try
    {
        db.SubmitChanges
            (ConflictMode.ContinueOnConflict);
    }
    catch (ChangeConflictException)
    {
        Console.WriteLine("Re-submit changes? {Y/N}");
        ConsoleKey key = Console.ReadKey().Key;
        if (key == ConsoleKey.Y)
        {
            //Keep local data
            //db.ChangeConflicts.ResolveAll
                //(RefreshMode.KeepCurrentValues);
            foreach (ObjectChangeConflict conflict
                in db.ChangeConflicts)
            {
                conflict.Resolve
                    (RefreshMode.KeepCurrentValues);
            }
            // Overwrite other users' changes
            db.SubmitChanges();
        }
        else
        {
            // Refresh local data from the database
            db.ChangeConflicts.ResolveAll
                (RefreshMode.OverwriteCurrentValues);
        }
    }

    // Commit transaction
    txScope.Complete();
}

As you can see from this code, there are two ways you can resolve a change conflict. You can allow the other user’s changes to overwrite your own (shown in the ‘else’ block), or you can keep your current values and attempt to re-submit your changes to the database (as shown in the ‘if’ block), overwriting the other user’s changes with your own. As indicated, there is a problem lurking here. The ResolveAll method has a bug that refreshes database values, not just for the change conflicts, but for all updates in the change set, which results in an InvalidOperationException when you try to invoke SubmitChanges. The exception states that the timestamp property (which you are using for optimistic concurrency checking) is a computed value and cannot be changed. The answer is to iterate each change conflict and call Resolve on them individually. Thus, we avoid refreshing items for which there is not a change conflict, because those changes were applied the first time we called SubmitChanges.  You can download the full VS project here.

Posted in Technical | 1 Comment

How We Foiled Summer Heat

Soon after we purchased our home in a suburb of Dallas, Texas, I started to investigate how to make the house more energy efficient, and in particular how to protect ourselves against excess heat from the sun during summer months. So I started looking into radiant heat barriers. Some companies spray on Aluminum based paint to the underside of the attic rafters. Others will lay out aluminum foil on the attic floor. These approaches are mostly ineffective, but companies sell them because they don’t require much labor and are therefore less expensive and easier to sell. But the best way to install foil is tacked to the underside of the attic rafters, with good ventilation at the top and bottom to direct heated air up and out of the attic.

The best companies out there offer to install the foil for about $1.50 per square foot, which on our home would amount to almost $4,000! This was way out our budget, so I decided to buy the material over the Internet at atticfoil.com. The cost was only $400, and I was able to hire an off-duty fireman to help me install it – I got his name and phone number from this same web site. The final bill was about a third the cost of the original estimate, and I had extra insulation laid down at the same time.

We installed the foil at the height of summer and saw our electric bills come down as a result. The house is cooler, and we’ve only had to run one of our air conditioning units to keep the place at 78 degrees when it’s over 90 degrees outside. Please feel free to share your experiences with attic foil here.

Posted in Personal | 1 Comment

Posting Code to a WordPress Blog

I just found a great post on how to format code sections in a WordPress blog:

http://www.thomasclaudiushuber.com/blog/2008/01/07/give-your-blog-code-the-visual-studio-look

Now the code in my blog should look a lot prettier.

static void Foo()
{
    // This is a comment
    Console.WriteLine("Print something to the console.");
}

Posted in Technical | Leave a comment

Visual Studio and ESET’s NOD32

I’ve been using NOD32 as my anti-virus for quite some time now, and I’ve been quite pleased with it. For the most part it runs silently in the background and does not impact system performance. However, I’ve discovered there are some issues related to running Visual Studio and its interaction with NOD32.

First of all, if you develop web applications with VS, you may run into trouble. After creating a web app based on the “File System” (using the ASP.NET development web server), I would not be able to run the app from Visual Studio. When pressing F5 or Ctrl+F5, Internet Explorer would state plainly that it could not display the web page. But on closer inspection, I noticed that the port number had been decremented by 2 from that used by the development web server.

I ran across a forum post, which referenced a blog post detailing the problem and how to solve it. It turns out NOD32 Protocol Filtering is the culprit. What you need to do is disable this feature for the ASP.NET development server. Open NOD32, press F5 to show advanced settings, then in the tree-view on the left expand Web Access Protection / HTTP / Web Browsers. Click the Add button to add WebDev.WebServer.EXE, located here:
C:\Program Files\Common Files\microsoft shared\DevServer\9.0

Click the checkbox until a Red X is displayed. This will solve the problem. As a postscript, I also had to add an exclusion for MS Word in order to publish this blog post. J

Posted in Technical | Leave a comment

Fixing the WCF Proxy

If you’ve been programming WCF for a while, you’re probably used to the convenience of using the proxy class generated by svcutil.exe when you add a Service Reference to a Visual Studio project. You’re also probably used to creating the proxy within a using block, so that its Dispose method is called and cleanup can take place in a robust fashion.

However, you may not be aware that closing the proxy at the end of the using block could result in an exception (for example, a Timeout or Communication exception) and that you should catch this exception and call Abort on the client channel, as described in this MSDN topic: http://msdn.microsoft.com/en-us/library/aa355056(VS.85).aspx.

using (MyServiceClient proxy = new MyServiceClient())
{
    proxy.SomeOperation();
} // Could throw an exception here

To remedy this, I wrote a code snippet that creates a partial class to extend the generated proxy class by implementing IDisposable and properly handling the cleanup. Although there are other approaches you could take, what I like about the code snippet is that it doesn’t require you to change the code that creates and uses the proxy. Here’s the code that the snippet produces:

namespace Client.MyService
{
    public partial class MyServiceClient : IDisposable
    {
        bool disposed;

        public void Dispose()
        {
            if (!disposed)
            {
                CloseChannel();
            }
            disposed = true;
        }

        void CloseChannel()
        {
            try
            {
                if (base.InnerChannel.State
                    != CommunicationState.Closed)
                {
                    this.InnerChannel.Close();
                }
            }
            catch
            {
                this.InnerChannel.Abort();
            }
        }
    }
}

The code snippet has placeholders for both the namespace name and the class name, which reflect what you specified when adding the Service Reference. You can download the code snippet here. To install it, place it in the My Code Snippets folder: …\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets. Enjoy.

Posted in Technical | Leave a comment