SVN Merge Headaches

03.05.10

Problem: You work on a team using svn source repository and you are plagued with merge conflicts.

Solution: Simply put use ignore. All team members need to have the ignore list setup so that only developer generated content is being submitted. User files and compiled project files should be omitted.

In my development environment I use Visual Studio 2008(C# mostly) and Resharper. My automated builds compile to a folder called “build.”

My ignore list:

.DS_Store _ReSharper.* Thumbs.db obj bin *.suo build *.user buildout.txt

PBA.com Rewrite From ASP Classic to ASP.Net MVC

03.03.10

PBA.com had become a maintenance issue with majority of the code base written under ASP classic by programmers who no longer worked in the organization.

Requirements:

  • Use a current language/framework that promotes best practices such as unit testing, separation of concerns, and  DRY code.
  • Framework needed to provide complete control over HTML giving Web designers easier means to create clean CSS/HTML design templates.
  • Search engine optimization friendly.
  • Business logic must be decoupled from the database.
  • Old URLs must give a 301 status code and be correctly routed to the new standard.

Technology Overview:

PBA.com was rewritten from ASP Classic to ASP.Net MVC. The MVC framework provided us with good base for the best practice we needed, improving the maintainability of the site. The MVC routing engine enabled us with a means to route old URLs to their new MVC counter part properly. For the Model in MVC we choose Nhibernate. Nhibernate proved to be both performant and flexible, giving PBA not just PBA.com  a reusable stable business logic layer.

Before:

After:

WPF – Tournament Presenter

02.22.10

Tournament Presenter is a customized score board display written for the PBA to allow onsite fans to quickly gauge the state of a bowling tournament.

Requirements:

  • The display needed to be Extendable. PBA host many different styles of tournaments, Tournament Presenter needed an easy method of adding functionality for the new tournament formats.
  • Screen Resolution independents. None of the target display  hardware  was guaranteed to  use the same resolution. Displays needed to look the same on all sizes.
  • Displays needed to look sharp be capable of animation, graphics and color.
  • Data source for displays needed to be small and work disconnected.

Technology Overview:

The displays where written in C# on .Net 3.5 platform. WPF was leverage  for rendering GUI, XML for the data source, Clickonce for publishing, NUnit for testing and MEF for Extendibility.

 

Tournament Presenter On ESPN

Look to the seek times at 00:22, 1:08, 3:40, 4:20, 5:40, 6:50, and 7:19 these will give a good idea of how they are used in production.
ESPN Video

User Generated Html Content

10.22.09

Problem: You need to handle user generated html content from an unknown source for display in your webapp.

Solution: Well this is alwasy a moving target due to cross site scripting, but my approach is the following.

1. I use MarkItUp to allow users an easy way to format their html.

2. After users has submitted his changes I run it through an HTML Sanitizer (Scroll to the bottom) that users a white list approach. For asp.net mvc you will need to mark your controller as [ValidateInput(false)]

2. If the Sanitization process has removed any user created content I do not save the content.  I then Return there modified content with a warning message, "Some illegal content tags where detected and removed double check your work and try again."  

3. If the content passes through the sanitization process cleanly, I save the raw html content to the database.

4. When rendering to the client I just pass the raw html out of the db to the page.

More Info:

StackOverflow.com

Safer Deletes and Updates on Live DataBase

05.21.09

Problem: You need to change production data from a database.

Solution: Use Transations.

Its always scary working with live data I found that I feel more confident when I take the following measures.

Do a Select first to check the where clause:

SELECT * FROM Foo WHERE FooID = 1000

Wrap your changes in a Transaction and roll it back if you did not get the expected result.

Begin Transaction
  DELETE FROM Foo WHERE FooID = 1000
IF @@RowCount <> 1 BEGIN
  Rollback Transaction
END
ELSE
  Commit Transaction

Visual Studio Throws an Error When Trying to Connect/Open an .mdf File

04.11.09

Problem: You try to open a .mdf file in visual studio and you get one of the following errors.

Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly.  Please verify the installation of the component or download from the URL:  http://go.microsoft.com/fwlink/?LinkId=49251

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

Solution: Open Server Explorer add Data Connection. Make sure the Data Source = Microsoft SQL Server Database File (SqlClient) and browse to the .mdf file located in your source directory(There maybe on located in the bin directory but this will get copied over by what is in src on a build). Click the Advance button. In order to work I needed to switch the Data Source to .\SQLEXPRESS2005 (This will be different for each computer).

Final connection string should look something like this:

Data Source=.\SQLEXPRESS2005;AttachDbFilename=|DataDirectory|\NerdDinner.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True

ASP.Net MVC And Ninject

04.10.09

Problem: You want to be able use the Ninject frame work with the new and shiny ASP.Net MVC framework.

Solution: Assembly: Ninject.Framework.MVC Contains an Abstract Base class you can Inherit from to do most of your heavy lifting.

Some Code

Global.asax.cs

public class MvcApplication : NinjectHttpApplication
{
      private static IKernel _kernal;
      protected override void RegisterRoutes(RouteCollection routes)
      {                 
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
          routes.MapRoute("Default", // Route name
                          "{controller}/{action}/{id}", // URL with parameters
                          new { controller = "Home", action = "Index", id = "" } // Parameter defaults
                         );
      }                 
     protected override IKernel CreateKernel()
     {
         if (_kernal == null)
         {
             var modules = new IModule[]
             {
                 new AutoControllerModule(Assembly.GetExecutingAssembly()),
                 new DemoModual()
             };                
             _kernal = new StandardKernel(modules);
         }              
         return _kernal;         
      }
}

Inversion of Control vs Dependency Injection vs Strategy Pattern

02.18.09

Warning this my understanding as of today, who knows what tomorrow will bring.

I often hear the terms Inversion of Control(IOC), Dependency Injection(DI) and the Strategy Pattern thrown around in the same context, this was getting really confusing for me. So, I spent a couple of hours trying to clarify the differences.

IOC vs DI: Basically DI is a type of IOC. IOC is a broad abstract principle that covers not only DI but Event-Driven programming and numerous others.

So What is DI? DI is the way you provide the implementation for a dependent service. There are a number of DI frameworks out there I have recently been playing with Ninject mostly because I like ninjas... and the flow syntax for wiring up the dependencies looks nice.

DI vs Strategy Pattern: For a while now I have been using the Strategy pattern thinking it was the same as DI. I know, "Gosh such an idiot :p", but DI assembles the appropriate algorithms for the calling class. Strategy is just one of the patterns that lends itself well to DI.

More Info:

Dependency injection

Inversion of control

Inversion of Control Containers and the Dependency Injection pattern by Martin Fowler

Inversion of Control vs Strategy Pattern

IoC containers are not about a design pattern

Thank you, Eric Ridgeway for answering my 200 questions.

Unhandled Error in Silverlight 2 Application Code: 2104

02.17.09

Problem: After deploying your silverlight application to your Web server you get the following error.

Error: Unhandled Error in Silverlight 2 Application
Code: 2104   
Category: InitializeError
Message: Could not download the Silverlight application. Check web server settings    
Source File: TestPage.html
Line: 53
 

Solution: The MIME types on your webserver are not setup correctly to host your silver light application. The MIME types needed are:

.xaml    application/xaml+xml
.xap    application/x-silverlight-app
.xbap    application/x-ms-xbap

Hack: If you are like me and have your silverlight hosted on a shared hosting environment like godaddy you cannot change your MIME types. Instead change the .xap to .zip you must also change the source parameter value inside your page to match.

<object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
    <param name="source" value="Microsoft.Windows.Controls.Samples.zip"/>
    <param name="onerror" value="onSilverlightError" />
    <param name="background" value="white" />
    <param name="minRuntimeVersion" value="2.0.31005.0" />
    <param name="autoUpgrade" value="true" />
    <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
        <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
    </a>
</object>

Generic List Operations

02.04.09

Problem: You need a quick and easy way to manipulate elements contained in a list.

Solution: Lambda Expression, these expressions are used in the same fashion you would use anonymous methods but are less wordy.

Anonymous methods:

employees.FindAll(delegate(employee e1)
{ 
    return e1.Name == "Dave"; 
})

Lambda Expression:

employees.FindAll(e1 => e1.Name == "Dave");
employees.Sort((e1,e2) => e1.LastName.CompareTo(e2.LastName));

For more complex expression use the syntax like (params) => {statment}.

employees.Sort((e1, e2) =>
{                                      
    if (e1.LastName.CompareTo(e2.LastName) == 0)
    {
        return e1.FirstName.CompareTo(e2.FirstName);
    }
    else
    {
        return e1.LastName.CompareTo(e2.LastName);
    }
});

For more Info: MSDN