pmMDA.NET applications


The applications which are used to run the generated artefacts are not generated by the pmMDA explorer. But pmMDA.NET Framework provides base classes for these applications to make it easy to implement pmMDA.NET applications such as server or client.
For more information about the farmework for applications see the PmMda.Net.Application namespace in the API or the examples provided within the pmMDA source code.

Structure of an application

Base class Locator

The server or client application needs to implement a Locator class. To run the application one single instance of this class is created and registered.

A data object manager must be created and registered.


The NHibernate configuration and repository files are only used if the persistence handler is used as data object handler.

NHibernate configuration

The NHibernate configuration is specified in the app.config file.

NHibernate repository files

The application (normaly the server, except in a standalone client application) which is responsible for persisting the data objects must contain the NHibernate repository files (*.hbm.xml). These files can be embedded differently.
pmMDA.NET recommend to compile the repository files as resource files. Add the repository_do.hbm.xml and repository_lw.hbm.xml files to the Visual Studio project and set the "Build Action" to "Embedded Resource".

NHibernate config files in Visual Studio

Note: Visual Studio 2003 doesn't embedd the resource files to the assembly while building, if no source code has changed. If you change just the configuration files manually, choose "Rebuild Solution" or change some source files before building the solution.


Standalone application

This example shows how to implement a standalone application

  1. Create a Visual Studio solution witch contains an empty project with name "StandaloneApplication"
  2. Add references to the assemblies pmMDA.NET.dll, NHibernate.dll, MySql.Data.dll and Iesi.Collections.
  3. Add an App.config file to the project and fill it with the following content.
    <?xml version="1.0" encoding="utf-8" ?>
          <section name="nhibernate"
                      type="System.Configuration.NameValueSectionHandler, System"/>
          <section name="log4net"
          <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
          <add key="hibernate.connection.isolation" value="ReadCommitted"/>
          <!-- This is the ByteFX.Data.dll provider for MySql -->
          <add key="hibernate.connection.driver_class" value="NHibernate.Driver.MySqlDataDriver"/>
          <add key="hibernate.connection.connection_string"
                  value="Database=OJB;Data Source=localhost;User Id=nhibernate;Password=nhibernate"/>
          <add key="hibernate.dialect" value="NHibernate.Dialect.MySQLDialect"/>
  4. Add the class StandaloneApp to the project.
  5. Copy the following code to the StandaloneApp.cs file.
    /* **********************************************************************
     * Copyright 2005 BBV Software Services AG (
     * Licensed under the Apache License, Version 2.0 (the "Licence");
     * you may not use this file except in compliance with the License.
     * **********************************************************************/
    using System;
    using NHibernate;
    using NHibernate.Cfg;
    using PmMda.Net.Application;
    using PmMda.Net.Dog;
    using PmMda.Net.Dog.Persistence;
    namespace StandaloneApplication {
       public class StandaloneApp : Locator {
          static void Main(string[] args) {
             new StandaloneApp();
          public StandaloneApp() {
             // Configure NHibernate.
             // This will add the content of all *.hmb.xml files in the assemby "StandaloneApplication",
             // which are compiled as resource files, to the NHibernate configuration.
             Configuration configuration = new Configuration();
             // Initialize pmMDA
             DataObjectManager manager = new DataObjectManager(new PersistenceHandler(configuration));
             TypeFactory typeFactory = new TypeFactory(manager);
             // Here starts your application
             // Read data object example
             // MyDataObject myDataObject =
             //    DataObjectManager.DataObjectHandler.Retrieve(typeof(MyDataObject), 123);
             // Modify data object example
             // myDataObject.MyProperty = "Hello world";
             // Save the data object
             // try {
             //    this.DataObjectManager.DataObjectHandler.Store(myDataObject);
             // } catch(PersistenceException e) {
             //    // TODO: error handling; optimistic concurrency violation
             // }