Blog from June, 2011

Release Flow
Testing log4Net log messages.

How can you assert that some code generates a log message?
Like this:

 TestHelper.AssertLogMessageIsGenerated(() =>
                                                       {
                                                           Log.Debug("Hello");
                                                       }, "Hello");

The first argument of the method is an Action. The second part is the expected message. The testhelper executes the action and verifies the logmessage was found.

How to create a OpenDA model runner with deltashell

This article describes what needs to be done if you want to create an application that uses the OpenDAModelProvider interface of deltashell to work with DS models. I created a windows forms application using the 'zip' file from the nightly build. Use at least revision 12906 (this is the revision I used). There was a bug in earlier build

Setup

1 Create a folder called D:\ODA
2 Download deltashell.zip and extract it to D:\ODA\shell. Now you should have a folder D:\ODA\shell\plugins and D:\ODA\shell\release

Creating the application

3 Create a windows forms application called 'Runner' in D:\ODA\Runner
3.1 Add references to the following assemblies :

from D:\ODA\shell\plugins\DeltaShell.Plugins.OpenDA
DeltaShell.Plugins.OpenDA
OpenDA.DotNet.AdditionalInterfaces

from D:\ODA\shell\release
OpenMI.Standard2
DelftTools.Shell.Core
DelftTools.Units
DelftTools.Utils
DeltaShell.Core

So your references look like this

Add a button to the form and add the following code to click event handler:

                var provider = new DeltaShell.Plugins.OpenDA.DeltaShellOpenDAModelProvider();
                provider.Initialize(@"D:\ODA", "settings.xml");
                var instance = provider.CreateInstance();
                provider.SaveInstance(instance);

Creating the model.

1 Start the loader in D:\ODA\shell\release\DeltaShell.Loader.exe. Do not use a different version of DS to create the model. You might get versioning problems with the file
2 Add a demo flow model via menu development->'flow model 1d (demo network)'.
3 Rename the model to 'model'.
4 Save the project as model.dsproj in d:\ODA and close DeltaShell

The settings file

Create a text file named settings.xml in D:\ODA. These are the contents:

<?xml version="1.0"?>
<DeltaShellOpenDAModelProviderSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ProjectPath>D:\ODA\model.dsproj</ProjectPath>
  <FullyQualifiedModelWrapperType>DeltaShell.Plugins.DelftModels.WaterFlowModel.OpenMI2.OpenMI2WaterFlow1DWrapper, DeltaShell.Plugins.DelftModels.WaterFlowModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</FullyQualifiedModelWrapperType>
  <ModelName>model</ModelName>
  <DeltaShellLoaderFolder>D:\ODA\shell\release</DeltaShellLoaderFolder>
</DeltaShellOpenDAModelProviderSettings>

Running it.

Start the runner application and click the button. If all goes well your model.dsproj project will contain a model called Calibrated model. This is the model that was passed in to the SaveInstance method of the provider.

Validation library in DS

Validation via aspect (should be attributes)

The ValidationAspects library defines an Extension method on object:

public static ValidationResult Validate(this object instance);

This method uses attributes like

[GreaterThan] and [ValidationMethod]

To create a ValidationResult with validation errors. So you can validate any object and all the validation rules defined on that object with be tested.

Using PostSharp with these aspect enables throwing validation expections on setter.

FileImporters in DS

Deltashell currently has two interfaces that should be used to implement import functionality

IFileImporter : Can add items to a folder or can replace value of dataitem if that value matches the supported datatypes of the IFileImporter.

ITargetItemFileImporter : mutates it's TargetItem by importing stuff into it if TargetItem is set. If targetitemisRequired is false this importer can also function as a regular IFileImporter

These interface need review (wink)