I didn't work on the business logic addins that we support in the product, but they have a very interesting model to allow addins to be called before saving/deleting an account or document. The bad thing is we didn't ship a sample in our SDK and I just did a quick search and couldn't find any out there. I'm going to implement this by tranforming the UIAddIn sample in our SDK (download and install it here). I'm using SBA with Service Pack 3 and the sample product company. Let's start.
1. Open the UIAddIn project. 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.cs we need to return a new myDriverInfo for the business logic addin. I added this code in line 42.
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.cs 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.cs 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.