# Thursday, May 29, 2008

July 1st is right around the corner and for e-commerce based companies in Washington this means that Senate Bill 5089-2007-08, or the "Stream Lined Sales Tax" bill takes effect.  In short this means that online retailers in Washington need to collect destination based sales taxes.

Washington state is not alone on this.  In fact Washington is joining 21 other states under the Streamlined Sales and Use Tax Agreement (SSUTA).  Notice the "Use Tax" in the wording.  This is what empowers the state to tax based off destination shipping address.  This is just like when you go to register a boat in Washington that you purchased in Oregon, you are paying a use tax, which is legal according to the constitution.

Fortunately the Supreme Court ruled in Complete Auto Transit vs Brady that states cannot tax interstate commerce, which really means that an online retailer in Washington does not have to collect California state sales tax, unless that online retailer also has offices in California

With the passage of Stream Lined Sales Tax bill there are several winners here:

  • Washington state tax coffers.
  • Local brick and mortars.
  • Lawyers and possibly accountants.
  • Tax integration consultants.

Online retailers that only have an online presence previously had a nice loophole around collecting state sales tax since they are generally located in only one or two states.  Chain based brick and mortars (like Barnes and Nobles) that decide to go online are at a district disadvantage since they have presences in most, if not all states, which means they need to collect sales taxes from online sales in just about every state.

The absolutely ridiculous part of this law is the extra complexity to ensure the right local sales tax is collected.  In other words the shipping address dictates the sales tax rate, and in Washington each locality has its own sales tax rate with local governments setting local sales tax.  This means the sales tax rate can vary widely, and you, Mr. e-tailor need to figure it out.

Fortunately we all have zip codes here in the US which we can use to figure out the local sales tax rate, unfortunately we also have zip+4.  Well, zip+4 isn't bad, in fact its actually useful, but most people have no idea with their zip+4 is.  I know I definitely fall into that category.  And wouldn't you know it, the shipping zip code isn't enough to figure out the correct sales tax, you need the zip+4.

We can't start asking customers for their zip+4, since they probably don't have any idea what the last 4 numbers are, but we can ask them for their address and regular zip code which we can then use in a cleansing call to the USPS webtools APIs.  This address cleansing call, as you might now suspect, fills in the zip+4 based off the street address and zipcode.

With zip+4 in hand we can query our local database of sales tax rates and charge the customer the locally correct sales tax rate.

Thursday, May 29, 2008 4:13:03 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, May 28, 2008

Just today I realized that I'm using a fair number of Visual Studio 2008 addins. Visual Studio is starting to look more and more like Eclipse to me, a general work bench of tools. Which is surprising considering how painful it can be to write a Visual Studio addin in the first place.

So what addins am I using today?

  • VisualSVN - Seamless and painless, I almost forget that its there.  If you use SVN and Visual Studio, do yourself a favor and fork over the $50 for it.
  • ReSharper 4.0 - My refactoring/template tool of choice.  Coding without Re# is like digging a hole without a shovel.  I also use it to drive my unit tests, but TestDriven.NET is superior IMO.
  • TargetProcess - This shows all my current tasks and bugs right from within Visual Studio so there's no need to jump over to my web browser to find work or update status.
  • GhostDoc - I use this to bootstrap any XML documentation I might need.
  • ActiveWriter - I just installed this, so we'll see how it goes.  I'm going to use this to map some entities to a new view or two.
Wednesday, May 28, 2008 6:41:00 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, May 23, 2008

Yesterday I blogged about detecting IIS version from MSBuild, or more accurately, OS version.  Detecting whether my MSBuild script was running on XP allowed me to skip the application pool creation that would otherwise error out the build script.

What I didn't expect was that the website creation task would actually succeed in creating a secondary website in IIS 5.1.  I vaguely remember from other blog posts how its possible to programmatically create secondary websites in IIS 5.1, but didn't realize it was so easy.  Just for the record the following snippet also works against IIS 6 and 7.  The following build script does exactly that.

image

That takes care of new site creation, only optionally creating the site if it doesn't already exist, but always modifying it to ensure consistent settings.  The final piece we need is to stop running "Default Web Site" and start the new site.  IIS 5.1 can only run one site at a time so this is why we stop the default site and explicitly start the new site.

image

Once the script finishes we can check in inetmgr to see the new IIS 5.1 site right along side the default web site.

image

Are you wondering why I would go to all this trouble of monkeying around with IIS for development?  Well you should be.  The reason is that the Visual Studio web server does not support ISAPI filters, and since I'm doing URL rewriting at the ISAPI level, running under IIS is the only option.

Friday, May 23, 2008 3:43:45 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, May 22, 2008

I've been using the Microsoft SDC tasks to deploy IIS websites, and for the most part this has worked well once I grabbed the latest source from CodePlex; I ran into a few bugs that have been fixed since the last release.

Anyways, I've run into an annoyance with regards to local development builds on Windows XP.  Most of our devs are still using XP for their development platform which as you may know uses an old version of IIS - IIS 5.1.

  • No app pools
  • Single site only
  • No SSL

So, what does this have to do with the SDC tasks?  Well, I want the MSBuild script to fail gracefully with an intelligent error message when run on Windows XP.  Something like:

This version of IIS is not supported, IIS 6.0+ is required.

I couldn't find a decent built-in supported way in MSBuild to get the IIS version, let alone the operating system version.  You would think this would be supported without resorting to C#, but I couldn't find a way.  So what I ended up doing was using the command line "ver" command and piping that to a text file and then reading it back in.  Here's what that looks like:

MSBuild_OSVer

Thursday, May 22, 2008 4:02:50 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  | 
# Friday, May 16, 2008

I needed to create an xml fragment that had optional elements that was serialized from a class.  The optional elements were integers and decimals, types that are not nullable by default in .NET.  Well, we can wrap those types in Nullable<T> and then add an another ignored property that helps out the .NET serializer.

[XmlElement(Order = 10)]
public decimal? Height
{
    get { return height; }
    set { height = value; }
}

 

[XmlIgnore]
public bool HeightSpecified
{
    get { return height.HasValue; }
}

 

With the additional HeightSpecified property, the XmlSerializer will only write out the Height property element if its non-null.

 

Initially I tried using [XmlElement(IsNullable=false)] on the Height property, but that ended up throwing an InvalidOperationException when I went to serialize my class. 

Friday, May 16, 2008 5:55:11 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, April 28, 2008

I really like what Microsoft has done with the web development capabilities of Visual Studio 2008, they seem so much more mature and refined than in previous versions.

For instance, when you open up a new project in Visual Studio 2008 that has been configured to run under IIS, it now asks you if you would like VS to create the virtual directory for you in IIS.  No need to open up inetmgr and manually type in directory paths and virtual directory names.

Not only that, it creates the virtual directory in the correct place which is source control friendly, i.e. in place, not under some c:\inetpub\wwwroot folder like it used to do with Visual Studio 2003.  Microsoft finally figured out that .NET developers actually use source control.

Additionally you can now apply the settings on a per project basis, not on a per developer basis.  This is very handy when you want to share settings between devs, like when you have tests that are dependant upon web URLs.

VS2008WebSettings

Monday, April 28, 2008 4:29:14 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, April 25, 2008

In my spare time I've been working on a utility for generating SQL scripts and XML data documents.  The utility currently only supports SQL Server 2000/2005, but could easily support any other database that has an OLEDB provider via the MyMeta library.  The main goal of this tool was to produce scripts to be checked into source control, and to generate differential scripts between databases for use in db upgrades (migrations).

 

First and foremost, if you have a migration tool ala RoR ActiveRecord in your environment - use it.  A migrator written in a DSL is going to be much quicker to get going... and since you're working at a higher abstraction level it allows you to target many different databases with the same DSL code.  There are a few out there, so take a look.

 

My first goal was to get a baseline script of our databases.  There are quite a few tools out there for this, but I really wanted the ability to tweak the output of my scripts just so.  I really like scripts that don't error when you run them multiple times, so this generally requires an IF EXISTS before any action.  To get things formatted and written the way I wanted them, I ended up using NVelocity along with a few templates.

 

Secondly, I wanted to use XML to store my data.  I like XML files better than SQL scripts for several reasons:

  1. XML files are easier to edit than a SQL script with a bunch of insert statements.
  2. Its faster to bulk load XML data then run a bunch of SQL inserts (using SQLXmlBulkLoad).
  3. I can edit the XML data in a tabular fashion inside Visual Studio by switching to DataGrid view.
  4. Its easier to produce a diff between a table and an XML document than a SQL script and a table.
  5. XML is meant to transfer data between systems, so why not use it?

To load XML data into SQL Server I created a wrapper around the SQLXmlBulkLoad COM component.  It works good enough for what I need, however it does make some assumptions about the way things are structured, its not quite as general use as BulkXml

The one advantage my implementation has is that when you run the loader, it generates the XSD that the SQL Server bulk load component requires at runtime based off the target table, so there's no need for you to hand write an XSD or worry about checking it into source control.

Here's how you would use SqlMigration to transfer data from one db to another (assuming the target db table is empty):

This creates an XML file for all the data in the customer table on my local machine:
sneal.sqlmigration.console /dir=c:\mydb /xmldata /tables=Customer /server=localhost /db=AdventureWorks

This applies the XML file just generated to my prodsql1 SQL Server.
sneal.sqlmigration.console /server=prodsql1 /db=AdventureWorks /execute=c:\mydb\data\dbo.Customer.xml

Pretty straight forward.  I'm not sure I like the command line syntax since you could potentially run an execute and script command at the same time.  I'm thinking of creating a separate console application for loading data and running scripts, or at least providing a command line switch that sets the mode to either input or output only.

I would like an MSBuild target wrapped around this, but I haven't needed that yet.  Another thing lacking is the ability to point it at a database and say "script everything."  That feature I know I'm going to need here very shortly.  Hopefully I'll have some time to fix the DDL migration portion of the tool, right now only migration (diff) SQL data scripts are supported.

As always, the code can be checked out from Google code via SVN (VS 2005).  Eventually when the tool is a little more mature I'll post a binary.

Friday, April 25, 2008 2:39:16 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, April 07, 2008

It seems like we've all done this a hundred times before.  I know I have.  What I really want is a strongly typed argument object passed in from the command line, but all we get is a bunch of strings to parse through.  Yuck, I hate parsing strings.

There are a few existing command line parsing libraries in .NET.  I thought about using one of them, but I either ran into licensing issues, old .NET 1.1 code, or the library was just too big and over complicated for what I wanted.

Needing this functionality yet again, I decided to create a re-usable library that allows me to create my command line arguments via property attributes.  To create a new argument class I just apply a SwitchAttribute to each property I want settable from the command line.

    public class Options
    {
        private int port;
 
        [Switch("Port", "Sets the IP Address port of the server.")]
        public string Port
        {
            get { return port; }
            set { port = value; }
        }
    }

 

Then to use this options class from my console application, I only need to:

    private static int Main(string[] args)
    {
        CommandLineParser parser = new CommandLineParser(args);
        Options options = parser.BuildOptions(new Options());
 
        if (options.Port != 0)
        {
            // ...
        }
    }

 

As you can see, this is nothing fancy, but it makes building new console apps a little easier, and more importantly it makes adding or changing command line arguments much more maintainable since I only need to modify a single property forgoing any string parsing.  I can also get a nicely formatted list of what command line arguments are available along with their descriptions.

    foreach (string line in CommandLineParser.GetUsageLines(new Options()))
        System.Console.WriteLine(line);

 

Outputs:

/Port    Sets the IP sddress port of the server.
/Server   Sets the name of IP address of the server.
...

 

If you interested in using the library, its available in my Google code SVN repository under the Apache 2.0 license.

Monday, April 07, 2008 6:11:50 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |