Background
As stated in previous post, our XrmFramework is based on Developer Toolkit for Microsoft Dynamics CRM. It has a really good user interface to create plug-ins and at the same point register them:
The main issue here is that the register information is stored as XML and it’s not possible to edit afterwards with the same user interface, which makes not very user friendly.
The other alternative, is to use the PluginRegistration Tool, located in the SDK: Tools\PluginRegistration\PluginRegistration.exe, which once again have a very good user interface but you have to do three manual steps:
1) Register the assembly:
2) Register all the plug-ins steps (events):
3) And finally go into to the MS CRM and add the assembly and the steps as part of the solution that you will deploy from DEV to TEST and PROD.
What we have seen is that the third step is forgotten a lot and therefore we can’t ensure a valid TEST deploy, and sometimes PROD deploy.
Plug-in synchronization
This is the reason we decided to create this functionality so we can determine from our code, what will be synchronized with the MS CRM Solution.
We still rely on the Plugin base class that is part of the Developer Toolkit, but we have expanded it (several times) so we can parse the neccesary information to register events on the solution:
-
Version 1.3.0.7 - Oct 06 2014: Plugin.cs
-
Version 2.1.0.0 - Jul 16 2015: Plugin.cs
-
Version 2.2.0.7 - Feb 22 2016: Plugin.cs
For more information on usage, please read the following: Plugin Registration Setup.
Example:
Based on the following file, we added three events: Update and creation/deletion of many-2-many relations (Associate/Disassociate).
Note: When Associating/Dissociating you will have to listen on all entites.
AccountPostPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class AccountPostPlugin : Plugin
{
public AccountPostPlugin()
: base(typeof(AccountPostPlugin))
{
RegisterPluginStep<AnyEntity>(
EventOperation.Associate,
ExecutionStage.PostOperation,
ExecuteAccountPostPlugin);
RegisterPluginStep<AnyEntity>(
EventOperation.Disassociate,
ExecutionStage.PostOperation,
ExecuteAccountPostPlugin);
RegisterPluginStep<Account>(
EventOperation.Update,
ExecutionStage.PostOperation,
ExecuteAccountPostPlugin);
}
...
}
DG.Delegate.HowToDaxif.PluginsSyncDev.fsx
We execute the following Daxif script, without having to leave Visual Studio:
1
2
3
4
5
6
7
8
9
10
11
12
13
#load @"DG.Delegate.HowToDaxif.Config.fsx"
module cfg = DG.Delegate.HowToDaxif.Config
open DG.Daxif.Modules
let dll = cfg.rootFolder + @"\..\Plugins\bin\Debug\ILMerged.Delegate.Delegate.HowToDaxif.Plugins.dll"
let proj = cfg.rootFolder + @"\..\Plugins\Plugins.csproj"
Plugins.syncSolution
cfg.wsdlDev' cfg.solution proj dll
cfg.authType cfg.usrDev cfg.pwdDev cfg.domainDev
cfg.log
Daxif output on the first run:
Producing the following output:
AccountPostPlugin.cs (with outcommented steps)
If we now outcomment the steps run the Daxif script again.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class AccountPostPlugin : Plugin
{
public AccountPostPlugin()
: base(typeof(AccountPostPlugin))
{
//RegisterPluginStep<AnyEntity>(
// EventOperation.Associate,
// ExecutionStage.PostOperation,
// ExecuteAccountPostPlugin);
//RegisterPluginStep<AnyEntity>(
// EventOperation.Disassociate,
// ExecutionStage.PostOperation,
// ExecuteAccountPostPlugin);
//RegisterPluginStep<Account>(
// EventOperation.Update,
// ExecutionStage.PostOperation,
// ExecuteAccountPostPlugin);
}
...
}
Daxif output on the first run:
Producing the following output:
Note: Remember to re-compile the plug-in project for each time you make changes to the code.
Conclusion
We have provided a more robust interface to make the synchronization of plug-ins, which ensures that code saved in the source control of the events that should be registred in MS CRM. As we use scripts, these can easily be built-in to the current built-script of the solution for deploy automation.
Note: We ensure that plug-in steps are enabled by running the following functionality, Solution.pluginSteps, after the solution is deployed.
1
2
3
4
5
6
7
8
9
10
11
...
Solution.import
cfg.wsdlTest' cfg.solution zip true
cfg.authType cfg.usrTest cfg.pwdTest cfg.domainTest
cfg.log
Solution.pluginSteps
cfg.wsdlTest' cfg.solution true
cfg.authType cfg.usrTest cfg.pwdTest cfg.domainTest
cfg.log
More info:
- NUGET package: https://www.nuget.org/packages/Delegate.Daxif/
- Github website with documentation and API Description: http://delegateas.github.io/Delegate.Daxif/
- Is constantly being developed: http://delegateas.github.io/Delegate.Daxif/RELEASE_NOTES.html