Sunday, December 13, 2009

Inversion of Control

With the latest Genwise Software factory project we are using a pattern that is called Inversion of Control, or also known as Dependency Injection (what's in a name). Getting our heads around this pattern took a while and it was hard to find a simple sample that just demonstrates the simplest implementation of this technique. (more complex implementations using service locators can be found elsewhere). In this simplest sample a movie database printer prints movies from different movie sources. One is supposed to be memory and the other a text file.

You can download the sample here

Friday, November 20, 2009

GSF beta 1 approaching

After our DSL research and string templating adventures we are now at the point to almost release a public beta for the GSF. (GenWise Software Factory) We have decided to create DSL's for the Data modeling and Business Object modeling. We have created templates for the Domain (Traditional Business Objects) , the DAO (Data access object layer) and some example code how to use it all in a WPF application. Below is an example Database scheam imported with one of our import utilities.



Basically what you get when you use GSF are the following modules:
- VS 2005 integration
- Database modeling with import schema from SQl-server or Oracle
- Business object class diagram created from the Datamodel but extendable with OO features
- DOA and Domain generation with partial classes and partial methods
- MVVM framework (Model view - View model pattern)
- Made for WPF binding but not limited to WPF.

Saturday, November 29, 2008

Microsoft DSL Tools

At GenWise we are currently investigating using the Microsoft DSL tools for code generation. I must say I am really impressed by what Microsoft has done with this tool. Not only make it possible to model your ideas, but also to instantiate that model and make incarnations for the real world. It is highly customizable and expandable. Together with string templating you can make very useful code generation environments. It takes a specific way to look at your implementation though if you want to preserve your own additions to he generated code. You will have to implement lots of base classes and code for partial class use from the beginning.
In general the extensibility is not so well documented, and there seems to be only a few specialists around. I do not know if we will come to a marketable product at this point in time, but I'm sure if you keep an eye on Genwise.com that sooner or later you will be able to find more about our DSL adventures.

Tuesday, February 19, 2008

Dicom the easy way

I have been searcing for a while for an open source DICOM library. The thing I hate the most about open source is that many things are started by one man shops, and after a while development stops. A good example of a nice Dicom library is OpenDicom. See www.opendicom.org. Problem is that development is stopped and the documentation is not that great.

I wanted to report on a great Dicom library I came across today. It is called ClearCanvas See www.clearcanvas.ca

It is unbelievable how accessible thay made dicom file access and dicom file viewing.
I wanted to modify some dicom file programmatically in VS 2005. You can do this very easily with the Clearcanvas SDK. The SDK is vary well documented and it took me about 30 minutes to get code going to change a patient Id in a dicom image, somthing I was not able to do very easily with other open source dicom libraries.

The library is also documented very well, with sample code, and the site has a good forum.

Here is the code:


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using ClearCanvas.Dicom;

namespace CCDicom

{

    public partial class DicomAttibuteViewer : Form

    {

        public DicomAttibuteViewer()

        {

            InitializeComponent();

        }

 

        private void btGo_Click(object sender, EventArgs e)

        {

            DicomFile _df = new DicomFile(@"C:\user\DotNet\OpenDicom\DicomSampleFiles\00000014.dcm");

            _df.Load(DicomReadOptions.Default);

            DicomAttributeCollection _ds = _df.DataSet;

            foreach (DicomAttribute _da in _ds)

            {

                if (_da.Tag.Group == 16 && _da.Tag.Element == 32)

                {

                    // Patient ID

                    _da.SetString(0, "mypatientid");

                }

                if (_da.Tag.Group == 10)

                {

                }

                this.listBox1.Items.Add(_da.Tag +"->" + _da.ToString());

            }

            _df.Save(@"c:\user\DotNet\OpenDicom\DicomSampleFiles\erik1.dcm");

 

        }

    }

}

Wednesday, January 23, 2008

Using Log4net in a Winforms Application

I was trying to use log4 net in my Winforms application and could not get it to work that easily. Here are the steps i performed to get it to works.

1. Offcourse first add the log4net dll to your application as a reference.
2. Then initiate logging as following:

public ILog log;
public void InitiateLogging()
{
log4net.Config.XmlConfigurator.Configure();
this.log = LogManager.GetLogger("user");
}

3. Do not forget to make a log4 net section in your application config file. Here is my config file (my application is named IMSBEWFM. The config file is named: ImsBeWfm.EXE.config

< ?xml version="1.0" encoding="utf-8" ?>
< configuration>
< configSections>
< section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
< /configSections >
< appSettings file="" >
< clear />
< add key="log4net.Internal.Debug" value="true"/>
< /appSettings>
< log4net>
< appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
< file value="general.txt"/>
< appendToFile value="true"/>
< maximumFileSize value="100KB"/>
< rollingStyle value="Size"/>
< layout type="log4net.Layout.PatternLayout">
< conversionPattern value="%d{HH:mm:ss} [%t] %-5p %c - %m%n"/>
< /layout>
< /appender>
< root>
< level value="DEBUG"/>
< appender-ref ref="GeneralLog"/>
< /root>
< logger name="NHibernate" additivity="false">
< level value="DEBUG"/>
< appender-ref ref="GeneralLog"/>
< /logger>
< /log4net>
< /configuration>


4. Notice the:
< add key="log4net.Internal.Debug" value="true"/ >

That line is very usefull in the debug output window of your application log4net will tell you any errors while initializing, tracking down problems. Later when it works you can remove that line.

Now to log someting is quite easy:

log.Debug("Sucessfull login");

Be carefull if you want to log for a released application, then you will have to change level value = "DEBUG" to level value = "INFO" and use log.info in your code to log to the released application.

Excelent reference is: here

Sunday, August 19, 2007

Starting an external program from C# procedure

We are working on Source Control integration for GenWise and needed some code to start an external process, and read the output or errors from the process. After some trials we found this is the best way to do it:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.WorkingDirectory = this.WorkingFolder;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName = this.VSSClientProgram;
proc.StartInfo.Arguments = pArguments;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
string Error = proc.StandardError.ReadToEnd();
int ExitCode = proc.ExitCode;
proc.Close();

The CreateNoWindow sees to it that you will not see some Window popping up from your own program normally with no contents. The UseShellExecute = false makes it so you can redirect the standard outpout, input and error streams.

Saturday, July 7, 2007

GenWise 1.09 Released !

We have released version 1.09. It was a long cycle. It has proven difficult to get rid of our threading and events scheduling issues. But we feel very comfortable now that this release is very stable. We now use the latest NHibernate version (1.2GA). In the mean while we have also been developping our own applications and fixed many practical issues in working with GenWise. With this version full ASP.NET applications can be developped in record time.