DotNetNuke's IUpgradeable interface for module controllers...
I was going through the ASP.NET Forums for DotNetNuke and came across this post from "Sponge_Bob".
Is there anyway that I could run my own custom code on installation of my own PA's. I have a Module the need to be able to check and see if a certain Dll file is installed on the server before installing. Also I need the install to be able to check the version of the Dll file on the server an make certain the it is of the required version. Finally if the Dll not of the required version I want to point the person installing the PA to the place where to get the latest version of the install.
I have the option here to use Code (Preferred) or Sql to accomplish this task as I can make it so the required Dll I need to check for has its version entered into the database as it will be originally installed as a skin object.
It would be really sweet if Dnn could check the version of a Dll file before overwriting it with a dll file from a PA to make certain the it is not installing a Dll File of a lesser version. I am more that willing to write the code to accomplish this if the core team is willing to implement it.
So - I took a few minutes to help "Sponge_Bob" out. Here's my response...
I have to answer a question from Sponge_Bob. Dig yer username.
DotNetNuke provides an interface called IUpgradeable. The interface is implemented on your controller class for you module, similar to the way IPortable and ISearchable are implemented. There's very little written about this interface, however. The interface contract contains one method definition -
Function
UpgradeModule(ByVal Version As String) As String
So digging a little deeper...
The the lastest version of the Private Assembly Installer (V3) will check to see if your BusinessController class supports the IUpgradeable interface. If it does support it, it will iterate through an ArrayList of versions and call your UpgradeModule implementation for each version.
So - similar to the way DNN does version control - you can handle each incremental upgrade... a nice litte switch / case statement on the version string sent in to your method.
Now if a needed DLL is not there - you could always throw an error... OR - use your string return to add an error to the module install... (that would be the kindler, gentler approach). Use HTML within the string to color the text red so it stands out. Well - you should always return a string at least letting the user know that each upgrade was successful. Any string you return will be added to the module install / parsing results.
Seeing that this is done during install of your module or module upgrade - I wouldn't recommend putting any code in here to check for latest version or anything like that. However, what I would recommend is creating a separate edit control for "Check for New Version" which can do that. Unless it is mission critical to push latest versions (i.e. OS Security Patches, Virus Software) I personally prefer choosing an option like that.