Technology behind the scenes

In this post we will go more in detail on how we handle the synchronization. In
some solutions we end up with around +10 mb assembly files that we would only
like to upload to the solution (cloud can be slow) if it’s strictly necessary.

Synchronization steps

1) Hash of the assembly

We start by getting the hash of the assembly we are building. You might think
that can’t be that difficult right? Well it’s not, but you need to have in mind
that you can’t just make an SHA-1 checksum om the builted binary as due to
non-deterministic compiler optimizations, you will not end up with the same bits
everytime. Therefore we inspired ourselves in Gustavo Guerra - ovatsusSetup.fsx which we modified so it will
retrieve all the files and binaries related to the project itself as well as all
the related projects. The final hash is just the combination of all the other
hashes (fold):

Note: As related binaries, which are retrieved from NuGet, always have the
same bits, we can just SHA-1 checksum them as well.

2) Upload the assembly if none

In order to do the synchronization we will need to have an assembly to compare
to. Therefore, the next thing we do is to ensure that there actually is an
assembly in MS CRM. It’s important to store the calculated hash value from the
previous step pa.Attributes.Add(“sourcehash”, hash) as it will be
the value we will compare the local assembly in order to decide if we need to
upload a newer version of the assembly.

3) Parse plug-in Steps and Types from local assembly

As mentioned in the previous blog post, we 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:

So the way MS CRM plug-in registration work is that in order to remove a plug-in
you must first remove all of it’s types (subclasses in C#). Before you can
remove a type, you will have to remove all of the steps (Create, Update, …)
from each type. And finally, before you can remove a step, you will have to
remove all of the images (Pre or Post) from all of the steps.

Once this is done, you can now upload a newer version of the assembly and then
you would go the other way around. Create the types, then the steps and finally
the images.

Note: I will not go into deeper code details here as the blog post would
become to large. Besides, the code is Open Source, so feel free to look at It
if you find the topic interesting.

Summary

By having this approach, everyting related to plug-in are stored as code, we can
ensure that who ever retrieves the latest built from the source control. Will
be able to synchronize the desired state of the MS CRM kernel expansion that is
implemented for a given solution. This is normally the approach you have when
you make other kind of software solutions. Therefore I must go back to our
motto: “We don’t make MS CRM solutions, but software solutions”.

Kudos to our M.Sc. students

As we tend to code Daxif based on computer science principles, we would really
like to thank DTU Compute, Department of Applied Mathematics and Computer Science
for having provided us with three very skilled students that currently maintain
and expands the tool with new features as Microsoft add new functionallity to
MS CRM. We are also thankful for them to choose to stay with us when they finish
their education.