Shoutcast, flixster, maps, Shop Savvy on my phone

Thats it, the tmobile G1 is officially awesome.  Not the best phone out there, but, Android is a killer app imho.  Open Source Phone Stack.  Its going to lay waste to all other Phone OSes.  All other manufacturers should immediately open source their phone os or face the consequences of the open source revolution being brought to the masses.  I would write more, but, I am streaming BassDrive…

Exceptions leading to failure in AdonetAppender.DoAppend: Pattern layout in log4net

If you use log4net then you have to be careful of using patternlayouts for parameters for Adonetappenders.  Log4net can work with all native .net datatypes including nullables.  However, a layout like this:
<parameter>
        <parameterName value=”@UidSubmission”/>
        <dbType value=”Int32″/>
        <layout type=”log4net.Layout.PatternLayout”>
          <conversionPattern value=”%X{uidsubmission}” />
        </layout>
      </parameter>

while valid for a simple type like an int, may generate an exception if it is a nullable or reference type.  This is because patternlayout infers a cast to string when binding parameters.  If the value of the parameter is null, that tostring cast will fail.  They make no mention of that in the patternlayout documentation that is here.  For reference types and nullables you would be better served by using a rawpropertylayout.  This binds directly to the datatype and does not do any casting.  The syntax is a bit unusual (it helps to bind to the log4net.xsd so you can see how to use this).  An example of such a parameter is below:
   <parameter>
        <parameterName value=”@DischargeDate”/>
        <dbType value=”DateTime” />
        <layout type=”log4net.Layout.RawPropertyLayout”>
          <key value=”dischargedate”/>
          </layout>
      </parameter>    
The error you will get in your log4net logs will look like this:
og4net:ERROR [AdoNetAppender] Failed in DoAppend
System.Data.SqlClient.SqlException: Error converting data type nvarchar to datetime.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
   at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events)
   at log4net.Appender.BufferingAppenderSkeleton.Append(LoggingEvent loggingEvent)
   at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)

Dumb VS Errors: LinqToSQL DBML Unspecified error

If you ever get an unspecified error when modifying a dbml file for a linq to sql class one of the possible problems is that you specified using statements outside the name space.  ie.  the following code will cause the error: 

using log4net;

namespace DQR
{
    using ValidationUtility;
    using System.Linq;
    using System;
    partial class tblTimeFrame
    {

The fix is to move the using statements inside the namespace:

namespace DQR
{
    using ValidationUtility;
    using System.Linq;
    using System;
    using log4net;
    partial class tblTimeFrame
    {

Believe it or not.  This fixes the problem and you can click the “View Code” link inside the dbml and be presented with the class.  Its not a major flaw, but, it is annoying when you have several classes in the dbml and navigating through the cs file becomes tedious.

Asynchronous Form Validation Using Windows Workflow

Just completed work on a Asp.Net validation framework using Windows Workflow for a client.  The client maintains a host of medical related data collection applications and needed a unified framework for validations for them for the client and code behind.  They wanted to write validation rules once and use them in multiple contexts:  client side via Javascript and in code behind as plain C# web service calls.  I designed and built for them a validation framework that consisted of

   1. asynchronous javascript validation using custom validators
   2. an XML web service that is called by javascript to execute validation rules that are expressed as workflow rules conditions (Business Rules Execution Service)
   3. ORM data mapping objects that workflow rule conditions are mapped to
   4. a business rules editor that leveraged the ruleset dialog editor to provide for editing rules.

The system is in the final test phases now.  I am writing an article on it that I hope gets picked up by someone if not I will post here.

This approach works for several key scenarios:

1.  Complex validations that are difficult to express in just javascript.
2.  There is a need to store validation rules in the database
3.  There is a need to use the same validation rules in multiple contexts:  client side, code behind, web service, etc.

Performance considerations are not what you might think.  A form with 50 elements and dozens of validation rules still takes about 200 ms round trip for the Business Rules service.  Workflow rules conditions have execution times approaching those of plain C#.  LinqToSQL mapping classes (what the rules conditions are bound to) have good hydration times from the db (100 ms or less for even large data mapped objects).

For inquiries or more specifics either look for my article when it is somewhere or email me.

MsBuild, CCNet, VS2008

If you ever want to get this all working. Please ignore all the blogs that try to indicate that somehow you can use a custom task library or maybe some feature of msbuild to do deployments. The best blog I have found on getting this all to work including deployment is here. Lets face it. Unless you have Team Foundation running, Microsoft wants you to jump through hoops to get continuous integration to work. Depend on CCNet and ignore having too much in MSBuild.

Creating Custom Activities can make you rich

After pulling out my hair to understand what it takes to make an activity without code-behind appear in the toolbar of Visual Studio 2008, I resigned myself to inevitability: ○ Unless you want to write your own XOML then you better use the code-behind format if you want to create a workflow. ○ Creating a custom activity is easy. Creating a custom activity that will have behavior and attributes like built in activities will take a little more time. ○ Most things you want to do in workflow can be accomplished using the default activities so don’t create your own custom activities if you don’t have to. ○ There is no such thing as truly dynamic properties in workflow. You will have to use any of the patterns for state (like State for example). I’ve finally been able to coble together a workable solution for a client that needed dynamic logic and dynamic variables. They also wanted to create the workflows graphically. The solution we proposed was to use custom activities that are arranged into a workflow using Visual Studio 2008. The clients would drop our custom activities onto a Sequential Workflow with code behind. They would then use the Rules Editor to define conditions that were a requirement of the Decision type activities. The client would then automatically create a XOML and a .rules file directly from inside Visual Studio 2008. The XOMl, .rules, and our activity library dll would be all that is required for another developer to create our workflow inside any Workflow container. This is powerful stuff because that is allowing custom logic and rules to be embedded into any system with

XML source and multiple data outputs for elements.

If you have ever had to deal with a typical XML file for data loading for ETL tasks in SSIS then  you have encountered its default behavior of creating an output for every element.  This is not the nicest behavior because it is doubtful that anyone would have a database so normalized.  While working on such an issue we discovered a useful trick.  First off, SSIS has not left you in no mans land.  If you have generated outputs for each element you can write all the elements to a Data Destination and use a SQL join statement to reconstitute the data in whatever way you want.  SSIS automatically adds IDs to all the tables it creates so that you can do join statements based on the hierarchy of the XML.  For example, if your xml hierarchy looks like this:

Parent Element->

                                Child Element->

                                                              Inner Child Element

 

Then the tables that SSIS would create will have an ID element for InnerChildElement that makes it joinable to Child Element and an ID field inside Child Element that makes it joinable to Parent Element.  This can be a life saver as you will just have to do one join to get the data back in a form that is interpretable as hierarchy.  This added ID field allows a second possibility:  Using Merge Joins on the output to create denormalized tables.  The SSIS Team actually have a blog entry that goes over this (http://blogs.msdn.com/mattm/archive/2007/12/11/using-xml-source.aspx).

Long story short, XML source does exactly what you will want it to for importing XML data.  That and the XSD validation capability of XML Task (note watch your constraints after the XML task to ensure that if you are validating xml you will get the proper success result) makes SSIS a complete XML handling solution.                    

 

Windows Workflow for the rest of us

First off, get a good book. Workflow is too encompassing for you to pick up in a tutorial. Forget about learning it all in a weekend. Pick up a good book written by one of the original WF developers. My first choice was Essential Workflow by Shukla and Schmidt. More of a developer reference than anything else. There are other books for other users, but, you definitely need a book. Second, go ahead and move to Vista and Visual Studio 2008. Sure, you can do WF development in 2005 and XP, but, thats like desiging a Formula one race track when you have only driven Yugos: You can imagine what it feels like and if you have an excellent knowledge of race track design you can pull it off, but, for mere mortals its going to suck. Third, there is plenty of MS documentation on the MSDN site, but, you could just ignore all that and proceed to write some terrible implementations. Forth, the killer app for me of the moment is designing workflows using a Domain Specific Language. Fifth, profit.

WatinTest Recorder is brilliant

Watin is an amazing testing suite for web applications.  If you have not tried it immediately go here and watch how easy it is to create end user unit tests for web applications. Now if that isn’t amazing enough there is the WatinTestRecorder.  View the video here that shows how to create Watin tests for a full page of a web application in about 5 minutes.

SubTyping in ActiveRecord isn’t too clear.

I’ve spent quite a lot of time messing around the methods for subtyping in ActiveRecord.  The clearest method I’ve found is using concrete classes (what Fowler calls them).  For this to work you simple have a inheritance relationship between the base type and the subclasses and have the AR attribute on all the classes (I get a weird error if the base class doesn’t have this attribute).

E.g. 
[ActiveRecord(“BaseType”)]
public class BaseType
{}

[ActiveRecord(“FirstSubType”)]
public class FirstSubType:BaseType
{}

[ActiveRecord(“SecondSubType”)]
public class SecondSubType:BaseType
{}

You end up with a little bloat in terms of sourcefiles and database tables, but, at least you have a very clear subtyping relationship.  I had wasted a lot of time with the AnyToAny relationship syntax.  Note:  There is no documentation whatsoever for how to use AnyToAny relationships in AR.  I reccomend searching the Subversion repository test cases for examples of how to use that.  Even the forums lacked any good description of how to code it.  Honestly this is one of those features that I would almost switch to NHibernate if I can’t work it.