2007-12-14

A code story staring MVP.NET - Environment

Previously

A code story staring MVP.NET - Introduction

Development Environment

Even in a solo developer project, I believe a source control system is extremely important. There are several free options to choose from (A few of them are SourceForge, CodePlex and Google Code), I created a new Google Code Project called phogaldotnet with LGPL as license.

googlecode

Ideally I would want a Build Server and do Continuous Integration, but since I don't have a server, I can only set it up on my own machine. This is less optimal for a number of reasons (dependencies are already on my machine, its not online all the time etc.), so I have decided to skip this.

Tools

To start I will only be using the following tools:

VS 2008

Tortoise SVN

If/when new tools are relevant, I will install them.

Mappings

I usually keep all OSS projects in this folder "c:\oss\", so I have created a folder for "phogaldotnet" so the full path is "c:\oss\phogaldotnet", and done "SVN Checkout" from "https://phogaldotnet.googlecode.com/svn/trunk/".

Additional installation

Download and install ASP.NET Extension 3.5 Preview for full VS 2008 support.

Solution and project structure

I like to have a folder called "Dependencies"(some call it "bin") with all the 3rd party dll's.

Also I downloaded the MVCToolkit and copied the dll and pdb files to the Dependencies folder.

A a SVN Add on the Dependencies folder and then a SVN Commit.

svndependencies

Creation of the Visual Studio solution and MVC project.

vssolution

SVN Add (not the bin and obj folder) and SVN check in.

Namespaces

I named the solution "PhogalDotNet" and the web project "PhogalDotNetWebAccess", because I usually don't like sticking everything into 1 namespace (i.e."PhogalDotNet"). Application and components are two different things. Application is a single use of components configured for a specific need, and components are self contain units of logic that any number of applications can use.

The idea is that I want a separate project with the name "PhogalDotNet", that contains all the logic. I will hopefully end up with an application, that is consists of a web.config file with HTTPHandlers and HTTPModules and a connection string to a database. So I will slowly be refactoring towards that.

More than that, I don't like when types in a namespace reference types in deeper namespace. Ex.: "Root.Core" types should not reference types in "Root.Core.Specialized". But a reverse dependency from "Root.Core.Specialized" to "Root.Core" is fine.

I am even suspicious about cross references within the same root. Ex.: "Root.FeatureA" should not reference "Root.FeatureB".

Morten Lyhrs rules for namespaces:

  1. Don't mix application and component namespace root names.
  2. Every application should have it's own namespace root.
  3. Components can share a root.
  4. Types in a namespace should not reference types in a namespace below it's own.
  5. No cross references within the same namespace root.

For simple components I usually end up with the following namespace structure:

"ComponentRoot"

"ComponentRoot.Infrastructure"

"ComponentRoot.Infrastructure.Facade"

All types in "ComponentRoot" are POCO, I try to keep this as fat as possible. Ideally all if/else, loops and as much logic as possible should live here. Unit test(Fast tests) is min. 100% coverage! Extension points for non logic are created via interfaces or virtual/abstract methods.

Types in "ComponentRoot.Infrastructure" is the default infrastructure provided. It implements the extension points in in "ComponentRoot". Ex.: "ComponentRoot.MailService" interface is implemented by "ComponentRoot.Infrastructure.SmtpService". Unit tests don't make much sense here, but integration tests(Slow tests) do.

If "ComponentRoot.Infrastructure.Facade" is used directly it might be a DSL, else it could be a implementation for a given framework (HTTPModules and HTTP Handlers come to mind). This is the classic "Service Layer".

Anyone can extend the component with their own infrastructure, but the core logic is unmodifiable and rigorously tested.

2007-12-13

A code story staring MVP.NET - Introduction

Why

I want to write a journal where all the decisions, problem evaluation and errors are a part of the story. So instead of focusing on the end result, this code story will focus on the journey. Actually there might never be a end result or the end result could/will change during the journey.

How

Instead of inventing a problem domain, I choose to make a photo gallery. Wife Lyhr and you(the reader) will act as customers, and your feedback decide where the journey goes.

What
Version 1.0
Goals Requirements
Privacy  
  Authentication
  Authorization
  Users
  Groups
  Roles
Content discoverability  
  Albums
  Labels
  Metadata
  Searchable
  Easy human direct access
Community feedback  
  Comments
  Rating
  Favorites

 

Goals should be fairly static, and all requirements should fit into a goal. Every code story episode will break down a requirement into specifications, the specification might never be implemented or change any number of times.

Technical Restrictions
  • The project is developed in .NET, and the code is written in C#.
  • A webserver running ASP.NET MVC.NET is the main interface for the user, and the webserver owns all data. No other application can have direct access to any data.
  • Photos can be placed in a database or in a folder.
  • Must support multiple databases (MSSQL and MySQL as a minimum).
Project Name

Every project should have a name, and I am usually very bad at picking them. Since its based on the .NET framework, and one of the top domains is .net, I choose the name phogal.net (short for "Photo Gallery Dot Net").

Quality

The output of this should be production quality, and you can hopefully help/guide me when I am on a wrong track. I not saying that everybody will be happy with my decisions, but I will try to explain why I choose as I do. Debate about the decisions are more than welcome.

Next

A code story staring MVP.NET - Environment

2007-12-12

How to get syntax highlighting in Blogger with SyntaxHighlighter

Syntaxhighlighter is a cool JS library for syntax highlighting on a web page.

  1. Download the latest version
  2. Unrar to a temp folder. ex: c:\temp\syntaxhighlighter
  3. Transfer the folders (Scripts and Styles) to a web server. I use google code to host my files.
  4. Open blogger.com and sign in.
  5. Goto "Template" and choose "Classic" layout.
  6. Goto Edit Html.
  7. After <head> insert the following:
    <link href="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Styles/SyntaxHighlighter.css" type="text/css" rel="stylesheet" /></link>
    <script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shCore.js"></script>
    <script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushCSharp.js"></script>
    <script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushXml.js"></script>
    <script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushCss.js"></script>
    <script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushJScript.js"></script>
    <script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushSql.js"></script>

  8. And before </body> insert:
    <script language="javascript">
      dp.SyntaxHighlighter.ClipboardSwf = 'http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/clipboard.swf'; 
      dp.SyntaxHighlighter.HighlightAll('code'); 
    </script>
    

2007-12-11

How to restore to another database

That is take a backup of database A and restore the .bak file to database B.

By far the easiest way is to do it in script:

restore database myDatabase from disk = 'C:\mybackup.bak' with replace

No more opening of SSMS (yawn), replacing file paths and remember to set a overwrite flag.

2007-12-10

How to turn of JIT optimizations on a release compiled exe

Basically create a ini file with the same name as the exe with the following content

[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0

Perhaps if an unrecoverable errors occurs in a program, it can create the ini file and restart the application. The user can the redo the action(s) to create the error, and a full-stack trace can be created.