A couple months ago I posted a step by step process for doing a Business Logic Add-in Sample in C#, so finally here is the second part for doing this in VB.NET. The instructions are pretty much copied from the original post but I have translated the code to VB and verified it.
1. Open the UIAddIn project (from VB.NET Samples)2. Add a new class that implements the ISdkAddInDriver interface. I got the basic code from the Concepts Manual of our SDK. I'm going to post the code here:
3. Now we need to hook the business logic addin so it can be registered and instantiated by SBA. Here's what I have to do:
In DriverRegistration.vb we need to return a new myDriverInfo for the business logic addin. I added this code in line 37 (in the GetDriverInfos method)
I'm just creating a new guid because I will only have one business logic on this assembly. The last parameter uses BusinessLogic which is the name of my class implementing the ISdkAddInDriver.
In DriverRegistration.vb I need to instantiate my business logic addin. I change the LoadSdkAddInDriver to return a new instance of my BusinessLogic class. This is my new implementation:
Finally, in MyDriverInfo.vb we need to support the AppliedTypes property. In this case, I'm simple going to change the property directly just to make this addin work.
4. I'm going to put a simple validation for customers so we can test this business logic addin. If the addin wants to cancel the save event (from the PreSave handler), it needs to throw an exception. The message shown to the user will be an ugly technical message, so I would personally suggest to show a friendly message before that. Here is my code:
GotchasEach time you modify the code in the UIAddIn project, the assembly version will change so you would need to reinstall you addin again or change the AssemblyInfo.cs to have a fixed version number. This was the only issue I ran into. Then, I just have to copy the UIAddin.dll to the SBA location and install it. If you were to ship a business logic, I would suggest you add it to your GAC and install in a separate folder.
You can download my sample here.