Where’s the bug?

Where’s the bug?

public virtual void RemoveOfferItems()
{
    for ( int i = 0; i < offerItems.Count; i++ )
    {
        OfferItem offerItem = offerItems[i];
        log.Trace( "offer item: {0}, {1}", offerItem.Id, offerItem.Description );

        offerItems.Remove( offerItem );
        offerItem.Delete();
    }
    Save();
}

But don’t write a test for this…

Advertisements

NVelocity over Spark

Ever since I started to build web applications using Castle Monorail, I used NVelocity as view engine.

I know many think is not powerful enough and that there are view engines better than NV. Still, for our projects, NV was just enough.

For Storingen project I decided to user Spark v1.0, a new view engine built initially for MS-MVC. Now that the project was launched to production, I though I’d share some thoughts on Spark vs. NVelocity.

1. For a view engine having the slogan “less is more”, Spark is way too verbose.

Compare this:

Spark:

<test if="PropertyBag['actionResult'] !=null">
    <p style="color:red"> ${PropertyBag['actionResult']}</p>
</test>

NV:

#if ($actionResult)
    <p style="color:ff0000"> $actionResult</p>
#end

2. Try to debug this:

Dynamic view compilation failed.

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\my.project\f6ea7153\3708dd9104e947bd8207471079fe1268-1.cs(151,138):

error CS0103: The name ‘pipeLocations’ does not exist in the current context

True, Spark too throws the error + code line in the face in some situations, but I didn’t figured out which ones.

3. Spark was built with MS MVC in mind thus its integration with Monorail is not entirely functional.

For example, ${Form.DisableValidation()} does not work.

4. Another annoying thing is that I have to declare the <viewdata Cities=”List<Storingen.Model.Cities>/> although I have already added the Cities in the PropertyBag in the controller.

The only advantage with Spark is that I can use C# code directly in views while in NV I had to build some helpers.

In Spark though, I have to declare the variables that I need in the view: <var Format=new FormatHelper()/>.

In the end, I have to admit that switching from NV to Spark was quite a shock for me…

P.S. for the next projects I’m heading to AspView, then for Brail… or the other way around..

Remember password for Outlook Web Access

When we’re working outside the office, we’re using the web interface to access the company’s email.

Because of some "security" reasons, the "autocomplete" property of the password field is set to "off" so browsers don’t offer you to remember the password.

When I login several times a day to check the email, entering the password each time becomes very annoying.

 

outlook-web-access

 

So… using Firebug you can set this property to "on", login and the browser will ask you whether to remember the user name and password.

firebug-password-autocomplete

Unfortunately this works only in Firefox. Both Chrome and IE 8 ignore this change, so you can’t use it.

But.. are there browsers other than Firefox?

SecureQueryStrings mania

I have inherited a web project, from a former coleague, that “senior” developer.

He’s a big fan of secured query strings, because he says, “Session is crap. It can be hijacked and your server put to its knees”.

This project has a wizard through which the user must go, about 7 pages. All communication between these pages is done with secure query strings.

Like this:

/// <summary>
/// Gets the project id.
/// </summary>
/// <value>The project id.</value>
private int projectId
{
    get
    {
        if ( this.PageParams != null && this.PageParams["projectId"] != null )
            return Convert.ToInt32( this.PageParams["projectId"] );
        else
            throw new NullReferenceException( "this.PageParams[projectId]" );
    }
}
/// <summary>
/// Gets the topic id.
/// </summary>
/// <value>The topic id.</value>
private int topicId
{
    get
    {
        if ( this.PageParams != null && this.PageParams["topicId"] != null )
            return Convert.ToInt32( this.PageParams["topicId"] );
        else
            throw new NullReferenceException( "this.PageParams[topicId]" );
    }
}

Each page has between 7 and 11 such properties, simply pasted from one page to the other.

Imagine a change of the business entities or a change in the workflow of the wizard. (I think “Find and Replace” is a very used feature of this guy :D)

Oh, and the comments, are generated automatically, using a dreaded tool – I shall not utter its name. Even though they don’t tell anything useful, they will not make the help file red.

This is what I consider a really bad example of how to build an application.

The right web.config for the right server

We have to manage 3 pretty large projects for a customer. The customer wants to test first, then say “ok, deploy it to production”.

There are about 16 settings per project, which are different for each of the 3 environments. Yes, I forgot to add that we have also the development area, where we publish bleeding edge features.

This scenario brings a problem, how to have the right config settings for the right server, without headaches.

The build is done automagically, through CruiseControl.NET, after each developer commits its part. Now back to web.config.

In trunk we have the good-for-dev version, which is the same for all developers.

Then we have an xml, which contains the good values for each server, then we have the keys and the new values that must be added to the file, overwriting the default ones:

 
<project name="Delta" configuration="PR" xmlns="http://www.delta.com/map.config.xsd" >
	<!-- RequestsConnectionString -->
	<key xpath="/configuration/appSettings/add[@key='RequestsConnectionString']/@value"
		   newValue="application name=huis-req;server=pr-server;database=Live_Delta;uid=****;pwd=****;Connect Timeout=100" />
	<key xpath="/configuration/system.web/compilation/@debug"
		   newValue="false" />
</project>

Then, a nant target loads the xml and the web.config and and replaces the values:

 
<!-- replaces certain fields in web.config with production values -->
<target name="prepare.web.config" description="replace certain fields with production values in web.config" >
	<xml-foreach file="${map.file}" xpath="/project/key" >
		<xmlpropertybinding>
			<get xpath="@xpath" property="xpath" />
			<get xpath="@newValue" property="newValue" />
		</xmlpropertybinding>
		<do>
			<xmlpoke file="${web.config.file}" xpath="${xpath}" value="${newValue}" verbose="false" />
		</do>
	</xml-foreach>
</target>

This target is called within the main target that wraps the whole project build task:

<!-- prepare Delta web.config in deployment directory -->
<target name="prepare.Delta.config">
	<property name="map.file" value="Delta.${db.type}.config.xml" />
	<property name="web.config.file" value="${kit.dir}\Delta\Web.config" />
	<call target="prepare.web.config" />
</target>
<!-- build Delta -->
<target name="Delta" >
	<call target="update.dependencies" cascade="false"/>
	<call target="startup" cascade="false"/>
	<call target="ms.build" />
	<call target="make.Delta.kit" />
	<call target="prepare.Delta.config"/>
	<call target="zip.Delta" />
	<echo message="Build finished." />
</target>
So, within seconds from clicking the "Force Build" or from last commit in svn, we have a package ready to be deployed to either DEV, TEST or PR environments ;).

ccnet

Connection timeout because of FasterFox

So, I have installed FasterFox, hoping for a faster FireFox and I configured the add-on. Is not very clear from the text near the option "Disable IPv6 DNS lookups" whether this should be disabled or not.

So I checked the option.

This however led to localhost IIS being unavailable: "The connection has timed out".

Also, if the you have IPv6 (installed by default in Vista and Windows 7) you must have the following line in hosts file, otherwise you won’t be able to access your localhost.

::1             localhost    # IPv6 version of 127.0.0.1

 

fasterfox

Project management

I found this in a book (The leader’s toolkit) and I think is very funny and very deep and very suited for a team lead and his/her team:

Everything I need to know, I learned from Noah’s Ark:

  1. Don’t miss the boat.
  2. Remember that we are all in the same boat.
  3. Plan ahead. It wasn’t raining when Noah built the Ark.
  4. Stay fit. When you’re 600 years old, someone may ask you to do something really big.
  5. Don’t listen to critics; just get on with the job that needs to be done.
  6. Build your future on high ground.
  7. For safety’s sake, travel in pairs.
  8. Speed isn’t always an advantage. The snails were on board with the cheetahs.
  9. When you’re stressed, float a while.
  10. Remember, the Ark was built by amateurs; the Titanic by professionals.
  11. No matter the storm, when you are with God, there’s always a rainbow waiting.

— Author Unknown