Friday, September 28, 2007
So know that we got our class up and running (unit test and all) we want to connect it to a database. At first this class will look like a DTO but it could be more. So don't let yourself be fooled.

First of all I needed to change the properties to make them virtual (C#) or better overridable (VB.Net). Why? Because I didn't know better and I did what it told me to do. But now I understand. It needs this for its lazy loading. That way it can make a sub class of your class and it just needs to overload the properties. At the mean while it also overloads the compareto method which was un unwanted side effect for me. It overloads it so that it starts sorting on the Id field.

Now for the mapping.
NHibernate like Hibernate uses mapping files to map the properties to columns in the database. But some nice guy also provided us with attributes to make it eassier to make the mapping files or make no mapping files at all.

So the attributes you see are from that.

I used nHibernate 1.2.1 for this

Enjoy

Imports NHibernate
Imports NHibernate.Mapping.Attributes

Namespace Model
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
<CLSCompliant(True)> _
<NHibernate.Mapping.Attributes.JoinedSubclass(0, table:="tbl_Person", lazy:=False)> _
Public Class Person2
Implements IComparable

#Region " Private members "
''' <summary>
''' A local variable called _id of type Guid
''' </summary>
''' <remarks>Has Property Id</remarks>
Private _id As Guid
''' <summary>
''' A local variable called _firstName of type String
''' </summary>
''' <remarks>Has Property FirstName</remarks>
Private _firstName As String
''' <summary>
''' A local variable called _lastName of type String
''' </summary>
''' <remarks>Has Property LastName</remarks>
Private _lastName As String
#End Region

#Region " Constructors "
''' <summary>
''' Default empty constructor
''' </summary>
''' <remarks></remarks>
Public Sub New()
'TODO : Implement default constructor
End Sub

''' <summary>
''' Constructor with all the fields
''' </summary>
''' <param name="Id">DataType = Guid</param>
''' <param name="FirstName">DataType = String</param>
''' <param name="LastName">DataType = String</param>
''' <remarks></remarks>
Public Sub New(ByVal Id As Guid, ByVal FirstName As String, ByVal LastName As String)
Me.Id = Id
Me.FirstName = FirstName
Me.LastName = LastName
End Sub
#End Region

#Region " Public properties "
''' <summary>
''' This is the Id property.
''' </summary>
''' <value>Guid</value>
''' <returns>Guid</returns>
''' <remarks></remarks>
<NHibernate.Mapping.Attributes.Id(0, typetype:=GetType(Guid), Name:="Id") _
, NHibernate.Mapping.Attributes.Generator(1, Class:="guid.comb")> _
<NHibernate.Mapping.Attributes.Key()> _
Public Overridable Property Id() As Guid
Get
Return _id
End Get
Set(ByVal Value As Guid)
_id = Value
End Set
End Property

''' <summary>
''' This is the FirstName property.
''' </summary>
''' <value>String</value>
''' <returns>String</returns>
''' <remarks></remarks>
<NHibernate.Mapping.Attributes.Property()> _
Public Overridable Property FirstName() As String
Get
Return _firstName
End Get
Set(ByVal Value As String)
_firstName = Value
End Set
End Property

''' <summary>
''' This is the LastName property.
''' </summary>
''' <value>String</value>
''' <returns>String</returns>
''' <remarks></remarks>
<NHibernate.Mapping.Attributes.Property()> _
Public Overridable Property LastName() As String
Get
Return _lastName
End Get
Set(ByVal Value As String)
_lastName = Value
End Set
End Property
#End Region

#Region " Overrides ToString "
''' <summary>
''' Overridden ToString method for this class
''' </summary>
''' <returns>String</returns>
''' <remarks>The String value of this class represented by the ToStrings of all it's private members</remarks>
Public Overrides Function ToString() As String
Dim ReturnString As New System.Text.StringBuilder()
ReturnString.Append("[Id: " & _id.ToString() & "]")
ReturnString.Append(" - [FirstName: " & _firstName.ToString() & "]")
ReturnString.Append(" - [LastName: " & _lastName.ToString() & "]")
Return ReturnString.ToString()
End Function
#End Region

#Region " Overrides Equals "
''' <summary>
''' Overridden Equals method for this class
''' </summary>
''' <returns>Boolean</returns>
''' <remarks>The Boolean value indictaing if this is equal to the other class</remarks>
Public Overrides Function Equals(ByVal obj As Object) As Boolean
If obj.GetType Is Me.GetType Then
Return Me._id.Equals(CType(obj, Person2)._id)
Else
Return False
End If
End Function
#End Region

#Region " Overrides CompareTo "
''' <summary>
''' Overridden CompareTo method for this class
''' </summary>
''' <returns>Integer</returns>
''' <remarks></remarks>
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
If obj.GetType Is Me.GetType Then
Return Me._id.CompareTo(CType(obj, Person2)._id)
Else
Return -1
End If
End Function
#End Region
End Class
End Namespace

9/28/2007 3:30 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
Today I decided to change mailserver. up untill now I had been using my companies SMTP server to send all the notifcation mails. But I decided that it was time for some more control so I installed hMailServer.

Since all my notification are internal installing an emailserver just for this seemed more appropriate and now it even seemed easy. And I no longer hold all the other users up when everything goes wrong at the same time.

You have to know that I have 4 programs sending me mail every day. Namely Backu exec. to tell me that the backup went ok or not. Finalbuilder to tell me the build was ok or not. SQlserver with a story or two and the UPS that seem to loose connection once in a while.

At least it makes me feel important.


9/28/2007 2:09 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
For the last few days I have been testing this.
And believe me it's wonderfull. Its' a lot eassier then making MSBuild or nAnt files and I believe it is even more versatile.

It is especially usefull if you have no real person in the team that is resmonsible for the builds.

Finalbuilder is ideal for all you .Net building works.

Now let's build.

However it not free.

9/28/2007 2:00 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
 Sunday, September 09, 2007
Process explorer

Get it while it's hot.


9/9/2007 2:20 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, September 03, 2007
In the beginning of this year (april) I started using nHibernate. Having some experience in Hibernate (Java) I knew what to expect. So without RTFM or not enough anyway I started implementing it. And I used the attribute framework that came with it (version 1.2 beta 3) at the time. The learning curve was a bit high and over the next few posts you will understand why.

First of all I will start with a simple example which works well. In the beginning I couldn't find any good example in VB.Net using the attributes all were in C#.

nHibernate can be downloaded here

So this is what a normal class would look like in the Chrissie1 universe. Nothing special a person with a firstname and lastname. And you will notice that I already added an Id In a perfect world I wouldn't need an Id since firstname and lastname togther would make for a perfect id, but since the perfect world only exists on TV I add it since the beginning. I can always add comparers/constraints later. In the next post I will change it to suit the needs of nHibernate. But for now enjoy it's beauty.
Namespace Model
''' <summary>
''' A normal person
''' </summary>
''' <remarks>For testing purposes</remarks>
Public Class Person
Implements IComparable

#Region " Private members "
''' <summary>
''' A local variable called _id of type String
''' </summary>
''' <remarks>Has Property Id</remarks>
Private _id As Guid
''' <summary>
''' A local variable called _firstName of type String
''' </summary>
''' <remarks>Has Property FirstName</remarks>
Private _firstName As String
''' <summary>
''' A local variable called _lastName of type String
''' </summary>
''' <remarks>Has Property LastName</remarks>
Private _lastName As String
#End Region

#Region " Constructors "
''' <summary>
''' Default empty constructor
''' </summary>
''' <remarks></remarks>
Public Sub New()
Me.New(Guid.NewGuid, "", "")
End Sub

''' <summary>
''' Constructor with all the fields
''' </summary>
''' <param name="Id">DataType = String</param>
''' <param name="FirstName">DataType = String</param>
''' <param name="LastName">DataType = String</param>
''' <remarks></remarks>
Public Sub New(ByVal Id As Guid, ByVal FirstName As String, ByVal LastName As String)
Me.Id = Id
Me.FirstName = FirstName
Me.LastName = LastName
End Sub
#End Region

#Region " Public properties "
''' <summary>
''' This is the Id property.
''' </summary>
''' <value>Guid</value>
''' <returns>Guid</returns>
''' <remarks></remarks>
Public Property Id() As Guid
Get
Return _id
End Get
Set(ByVal Value As Guid)
_id = Value
End Set
End Property

''' <summary>
''' This is the FirstName property.
''' </summary>
''' <value>String</value>
''' <returns>String</returns>
''' <remarks></remarks>
Public Property FirstName() As String
Get
Return _firstName
End Get
Set(ByVal Value As String)
_firstName = Value
End Set
End Property

''' <summary>
''' This is the LastName property.
''' </summary>
''' <value>String</value>
''' <returns>String</returns>
''' <remarks></remarks>
Public Property LastName() As String
Get
Return _lastName
End Get
Set(ByVal Value As String)
_lastName = Value
End Set
End Property
#End Region

#Region " Overrides ToString "
''' <summary>
''' Overridden ToString method for this class
''' </summary>
''' <returns>String</returns>
''' <remarks>The String value of this class represented by the ToStrings of all it's private members</remarks>
Public Overrides Function ToString() As String
Dim ReturnString As New System.Text.StringBuilder()
ReturnString.Append("[Id: " & _id.ToString() & "]")
ReturnString.Append(" - [FirstName: " & _firstName.ToString() & "]")
ReturnString.Append(" - [LastName: " & _lastName.ToString() & "]")
Return ReturnString.ToString()
End Function
#End Region

#Region " Overrides Equals "
''' <summary>
''' Overridden Equals method for this class
''' </summary>
''' <returns>Boolean</returns>
''' <remarks>The Boolean value indictaing if this is equal to the other class</remarks>
Public Overrides Function Equals(ByVal obj As Object) As Boolean
If obj.GetType Is Me.GetType Then
Return Me._id.Equals(CType(obj, Person)._id)
Else
Return False
End If
End Function
#End Region

#Region " Overrides CompareTo "
''' <summary>
''' Overridden CompareTo method for this class
''' </summary>
''' <returns>Integer</returns>
''' <remarks></remarks>
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
If obj.GetType Is Me.GetType Then
Return Me._id.CompareTo(CType(obj, Person)._id)
Else
Return -1
End If
End Function
#End Region

End Class
End Namespace

9/3/2007 12:38 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
 Sunday, September 02, 2007
I like the articles on the code project most of them are high quality and to the point.

This i one that could be usefull in the future.

http://www.codeproject.com/useritems/Code_Quallity_Assurance.asp

The only problem I have when seeing this kind of tools is, when do they find the time to code ;-).

9/2/2007 12:25 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, September 01, 2007
If like me you like the sidebar in IE (yuck) then this is the one to go for in firefox, it's even better then yu imagined. It just creates an empty window when you download, but you can just ignore that (actually I think it's firfox that creates it.

Sidebar

9/1/2007 2:25 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
A couple of weeks ago I installed a program to share my bookmarks between several computers I first started out with ZinkMo but it was to unstable. And then I tried FoxMarks, which only works on firefox, which works great. Of course I forgot it's name when today I wanted to install it on my desktop and had to startup the laptop to find it's name. But here it is.

FoxMarks

9/1/2007 2:18 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
Apparently the spellchecker on dasblog will only work on IE. So no spellchecking for me since I use firefox. I know you guys are going to read this anyway. And if you like you can always mail me with any good tips.

9/1/2007 1:59 PM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback
On my search for a blog-engine I found this little beauty

csharp-source.net


9/1/2007 11:38 AM Romance Daylight Time  #    Disclaimer  |  Comments [0]  |  Trackback