Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Soft Gallery
    • autosvnbackup.sh
    • VBScript Snippets
  • Contact Me
  • Welcome

Assembly Initialization

Nicolas Galler | December 31, 2006

It appears that there is no facility in .NET to automatically call an initialization method when the assembly is loaded. This is a bit annoying for libraries since they will often require some initialization. So far I have found 2 work-around, neither of which are terribly satisfying:

  • Have a static initializer on the classes that are going to be called first when using the library. Obviously this is not usable in every case…
  • Register a handler for the assembly load event – this handler could then check the assembly for an initializer class. The easiest way I have found to achieve that was to define the initializer (with initialization done either in the constructor or in a static initializer) as an assembly level attribute, stick it on the assembly for the library, and have the assembly load event handler call the GetCustomAttributes method. I was actually hoping that .NET would be tricked into calling my attribute since it was an assembly attribute, sadly it seems it does not actually instantiate those attributes until someone tries reading them… So with this method I still need to have one initializer called manually to initialize the event handler.

There was a 3rd alternative which would be to just load all the types in the assembly whenever it is loaded (i.e. from the Load event handler)… then any static initializer would be called… seems like it could be a performance hit though so I decided to go with the more explicit approach.

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

NAnt Weird Crashes

Nicolas Galler | December 29, 2006

I like NAnt but lately it has been giving me a few problems. Apparently the assembly it compiles just mysteriously fail to load in NUnit. Compiled via VS, they work fine. Anyway, it seems like I spend way too much time maintaining build files also. I think it may be time to look into msbuild again!

Update (12/31/2006):
Started looking at msbuild, seems like it will let me do the same as nant, with a bit less configuration work. Works for me!

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

IronPython

Nicolas Galler | December 28, 2006

Just making a post to remind myself to check IronPython + Saleslogix

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

Data Access in .NET

Nicolas Galler | December 6, 2006

In the last few months I have been working on our biggest Saleslogix ASP.NET module to date. As such I have decided to take a good look at the best way to design these in the future in order to make them easily adaptable to other customer’s web sites.

The first step I need to take is evaluate the data access strategy. The schema will almost always have slight variation from customer to customer so it is important we get that one right so that it is flexible enough.

Criteria for evaluating data access methods (in order of importance, the first 5 being strictly required):

  1. Can’t break polymorphism: if I need to add a field to the data object, the existing methods on the service should still work with the new object, without modification. This is because I will need “customized” versions of the service for various customers, but want to keep a common trunk for the shared functionality. For example, using the VS interface to generate typed dataset won’t work, because I will end up with completely different types. Basically this means the mapper needs to support inheritance, which pretty much makes it a requirement for it to be a full fledged ORM framework like nhibernate.
  2. Must be switchable with another data access method without a major hassle (ie, without affecting the service objects)
  3. Allows for custom generation of the primary key… ya that one would be a show stopper unfortunately since I have to generate Saleslogix ids
  4. Not requiring the presentation layer to deviate from the ASP.NET standard practices (e.g. monorail will be out, sadly)
  5. No or little code needed (or, automatic generation generation of that code)
  6. Standard, widespread use – we’ll have to stay away from some interesting but not well known frameworks, this may sounds silly but a name like dOOdads does not look too serious on a resume (I will still be evaluating dOOdads, though, I think it looks very promising)
  7. Simple concepts to grasp (I don’t mind spending a week learning how to use a particular framework but I need to be able to get my coworker up to speed fast enough!)
  8. Allows for the “special” Saleslogix cases: for example the link Contact.Addressid pointing to Address, and Address.Entityid pointing to contact. If this is not possible out of the box then we’ll have to be able to emulate it in the DAO.
  9. Performance (running, not startup)
  10. Weight (e.g. NHibernate is great but may be a bit heavy to deploy on a desktop application… of course this is where the switch-ability can come into play to offset this) – this would mainly affect the startup performance for web apps, which is important since we usually runs on a shared server)
  11. Weight of DTO (would prefer not to have a Dataset there as they are not great to store in a session)
  12. A package that also exists in Java would be nice

Here are the systems I would like to evaluate, I don’t know yet if I will have time to check them all out, but I would like to at least see if they pass #1 to 5:

  1. nhibernate (I actually already implemented the site with this one). It is a very complete framework, the biggest argument I have against it is that it is fairly heavy and complex, but it will do all we need. It is not very flexible, it is hard to do the mapping when the objects have a different structure than the database (which will almost always be the case when we work with the SLX db), but we can work around that with code at the DAO layer. It also has a few rigidities that get in the way when dealing with legacy data (for example, missing foreign keys cause an exception, obviously the ideal solution would be to implement constraints all over the place, but this is not always practical when we have to deal with remotes or non-customizable code). Also has the advantage of being a pretty cool “resume” item.
  2. dOOdads. Ya the name is stupid but it looks like a simple, honest mapping tool – it won’t support inheritance OOB though, so I have to see if there is a way to get around that
  3. DAAB (from Microsoft) – this is probably a bit too heavy for what I want to do, and seems to be still changy/experimental, but I might take a look
  4. Straight ADO.NET – problem is I can’t use the built-in interface because the objects are not extensible, and it won’t support the Saleslogix ids. So I guess I could use MyGeneration to write a code template for the DAO and DTO, but without a whole lot of hassle it will break #1 above (since the code generator will produce 2 different types). Of course it would not be that much work to just hand-code everything, but still seems like a waste of time compared to nhibernate. Here is a description of how to get it done in a somewhat organized way: http://www.microsoft.com/belux/msdn/nl/community/columns/hyatt/ntier2.mspx. Advantages of this approach: no 3rd party component to deploy, easier to debug, easier to tweak, don’t have to worry about a massive startup time.
  5. ibatis – this is lighter weight than nhibernate (it is really just a data mapper rather than a full fledged ORM framework), but would still do all that we need. The SQL statement are usually hand-crafted so we can have them perform any little trick needed on the SLX db. There is a DAO framework (in addition to the datamapper itself) but it seems like it might be limited when dealing with objects distributed between separate assemblies, because it will create one manager per assembly rather than having the possibility to share them (to avoid the problem of nested transactions, I think). All in all, there doesn’t seem to be much advantage of using that rather than straight ADO.NET for small projects, and I am not convinced it can scale well to more complex projects.
  6. ActiveRecord – looks really cool, basically this is like nhibernate but you stick attributes on the properties instead of writing a mapping file. Of course I use mygeneration to generate the mapping file anyway so this is not that big of a deal. I am mostly concerned about the weight added by this, and also the fact that it is not as standard as nhibernate – between this and nhibernate I would probably stick with nhibernate.

At this point I think ibatis and nhibernate are the most promising since they claim to support object inheritance mapping (well, I know that nhibernate does, at least). ActiveRecord is based on nhibernate and it does look really easy to use. I may still give a shot to the dataset approach since it has the advantage of being simple, easy to deploy, and also be applicable to the Pocket PC.

I have prepared a simple test case consisting of the Contact with multiple Addresses domain, a simple “service” which returns a concatenation of the addresses within a contact, and then an “extended” service which adds a few fields to the contact: Salutation (stored in the Address table, in the primary address), Notes (stored in C_CONTACT_EXT) and Birthday (stored in Contact). All fields (except the keys) are nullable. I am going to write the test app for ibatis and nhibernate and post a followup with the results.

Update (12-28-2006)

Here are my conclusions on the solutions above:

NHibernate

This is massive. It works well, but it is very complex, the documentation is not great, although I have found the doc in the most recent version (1.2.0 beta 2) to be a lot better. I think this will be the best option for bigger projects. Besides it is the best option if I want to upgrade to monorail later on.

iBatis

I can see how this one would be useful if you had to have DBA prepare all the SQL statements. Otherwise, the benefits are fairly minimal compared to the amount of extra work.

Straight dataset

This starts to break down a bit once you want to do complex relationships, inheritance, etc. Might still be OK for a quick app.

d00dads

I felt this didn’t give much benefit over using a straight dataset so I didnt really look at it deeper.

SubSonic

Had to mention that one because it looks so cool, unfortunately the rules are not as configurable so I don’t think it can handle all of the Saleslogix legacy schema weirdness. Too bad! I listened to the presentation from Rob Conery on .netrocks today and it sounds awesome, so I definitely want to try that, just maybe not on a Saleslogix project…

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

Source Control

Nicolas Galler | November 22, 2006

I have been evaluating source control solutions for Visual Studio 2005 this last week. I went through the exercise of setting up VSS 2005. What a pain that was. First of all SourceSafe is slow. Very slow. It is not just slow when accessing data through a slow connection (which is really near impossible – it seems to refresh a lot of data every time you click on a file so it takes forever), or when checking out a large number of files. Everything is just painfully slow, even just browsing the repository on a local link. In addition the VSS integration is terrible. Admittedly I stumbled a bit when designing the repository layout and had to rename some folders. The problem is the path information is embedded in so many places in the VS project file it was almost impossible to get it out – I ended up having to recreate the solution files from scratch (wasn’t a big deal in this case but this shows how much of a royal pain this could be to manage). Also the whole lock/modify/commit process is very hard to get used to… basically VS will tend to automatically check out some files like the project file and then screw me if I try to modify the project on another machine and forgot to check it in.

Anyway out of despair I decided to give a try to subversion, although I really would have liked to stick with a Microsoft technology for once. This little guy is lightning fast, and absolutely not picky about what you do to the file. I installed the TortoiseSVN interface to manipulate the repository and I love it. Main thing missing right now is integration with Visual Studio. Also so far I have not had to deal with merges so I don’t know how good it is at that but I don’t think it can be as bad as VSS. I might install the AnkhSVN plugin to see how well that work – but I will just skip on the integration for now so I can get some work done!

Comments
3 Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

Decimal.Parse -> "Invalid Input String"

Nicolas Galler | November 15, 2006

Found out that Decimal.Parse would not handle scientific notation.
Instead I had to use:

(decimal)Double.Parse(...)

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

NHibernate + SLX

Nicolas Galler | November 12, 2006

The last project was porting the SLX leads management module to the web. Obviously I did not want to have to deal with the SLXWEB development environment so I have developed it as an ASP.NET website. I am using NHibernate 1.0.2 for object persistence. Of course there were a few rough patches but overall it went in pretty well, doesn’t seem to have any problem chatting with the SLX OLEDB provider and generating SLX ids. I have yet to decide, however, if it is actually worth the hassle vs creating my own DAO from scratch! The hope I have is that some of the performance features (caching, lazy loading) will pay off. A lot of the “plumbing” is implemented in a shared assembly so we will also be able to reuse it for future projects (including a MyGeneration template that generates the code automatically, though I need to change this one to take advantage of the JOINDATA table instead of using the SQL constraints since SLX “forgot” to implement those).

I just found out about the ISession.FlushMode property. Set that to commit and it seemed to yield a big performance improvement (though actually it seems a bit too big to be true and I think what happened is my laptop was bogged down when I ran a performance test last week… it went from 2 minutes to 10 seconds). Anyway this is a good thing considering I will only call Save from my DAO objects, to ensure everything is consistently wrapped in transactions.

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

.NET Composite Control

Nicolas Galler | September 8, 2006

Seems the events are not firing correctly unless you implement the INamingContainer interface (this is a tag interface, nothing to implement).

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

Little tips from the old blog

Nicolas Galler | January 2, 2006

Enable NTP On Windows 2003

  • use the group policy object snap-in, go to Computer Configuration/Administrative Templates/System/Windows Time Service/Time Providers, configure the stuff in there
  • use w32tm /resync to force a sync
  • (I think the client is enabled by default on domain members? not sure.)


Random notes on ASP:

  • You can use WSH to get registry. You can’t access HKCU from ASP, even if IIS is configured with a user.
  • To show error on the browser (instead of just “error 500″) there needs to be an error handling page (this is created by default but if you create a new web site it wont be copied). Solution = create a virtual dir on the website, make it point to \Winnt\Help\IISHelp, then go to the custom error handling and set the 500-100 error to \iishelp\common\500-100.asp (trick = this has to be URL, not File)

Some notes about Soap, Soap::Lite

Many more hours of fighting between SOAP::Lite and .NET later…

I think I am beginning to get the ‘feel’ of SOAP::Lite. Looking at the output (WSDL and XML) of a .net web server, I managed to hack the serializer to make it similar (thus it is using the ‘literal’ encoding instead of the RPC type). I don’t know if this is still going to go through a SOAP::Lite client now but it is not an issue right now. It will break Apache SOAP clients I think but thats not really an issue either since we are only going to use the service with our .net client… we can have the handler dispatch to a different server (serializer) according to client type, if needed. Unfortunately I never got the .net client to grok the Rpc-encoded output, although it was doing great on the google service… all kind of strange bugs started popping, so I gave up on that.

A lot of the info was on the SOAP::Lite mailing list, I figured the rest out from looking at the SOAP::Lite code and the output from the .net server. Basically the only function of the serializer is to strip all the attributes except the namespace (also I turned autotype off). The .net client figures all the types and shit from the WSDL (which I adapted from the .net server example).

As it is now I have a service sending back an array of pairs. I am probably still going to use only array of strings anyway but heh its good to know I can do it :) It’s really pretty simple I wish this info was on the SOAP::Lite page.

Oh yeah this page was a real lifesaver also: article by Byrne Reese on SOAP::Lite

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

A7N8X / Sata/ Ghost

Nicolas Galler | January 2, 2006

Use a boot floppy to start Ghost (I created the floppy from Win XP). Start ghost with argument:
ghost -fni -noide

Comments
No Comments »
Categories
Programming
Comments rss Comments rss
Trackback Trackback

Categories

  • Dojo (1)
  • Experiments (4)
  • Force.com (2)
  • Interesting (1)
  • Javascript (3)
  • MSCRM (1)
  • Programming (63)
  • Rant (3)
  • Saleslogix (41)
  • Tricks (8)
  • Uncategorized (32)

Post History

  • 2011
    • January (3)
    • February (2)
    • March (1)
  • 2010
    • January (3)
    • March (3)
    • April (2)
    • August (2)
    • October (4)
    • November (1)
    • December (2)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox