How to: Create Rules Extensions from Multiple Sources

Updated: February 16, 2009

One limitation of rules extensions for the Forefront Identity Manager Synchronization Service (FIM Synchronization Service) database (metaverse) is that all the work is done in only one assembly. This makes it difficult for a team of developers to work on a metaverse rules extension. This topic presents one technique that you can use to assign multiple developers to a metaverse rules extension.

The strategy behind this technique is to create additional assemblies that other developers can work on. We strongly recommend that, however you partition the work, you should ensure that each provisioning extension operates on separate, disjoint objects. Failure to follow this rule can result in unpredictable provisioning.

For example, you could create two additional assemblies, MV_Extension_MA1.dll and MV_Extension_MA2.dll, through which you provision objects to management agents MA1 and MA2, respectively.

To identify your assembly as the metaverse rules extension, compile your code into an extension DLL and configure that DLL as the metaverse extension in the Configure Extensions dialog box.

The following code examples use multiple DLLs that contain classes that implement the IMVSynchronization interface and its methods. The example loads any DLL it finds in the ExtensionsDirectory property that has the prefix MV_Extension and executes each of the DLL methods in the example's corresponding method.

noteNote:
You can use a similar technique in a management agent rules extension if you want to have more than one developer work on the management agent rules extension.

The following example shows how to use a rules extension to use multiple provisioning DLLs.

using System;
using System.IO;
using System.Reflection;
using Microsoft.MetadirectoryServices;
using Microsoft.MetadirectoryServices.Logging;

namespace Miis_Metaverse
{
    public class MVExtensionObject : IMVSynchronization
    {
        IMVSynchronization [] myMVDlls;
        string PREFIX = "MV_Extension";

        void IMVSynchronization.Initialize ()
        {

            // Get list of files that start with PREFIX and have a .dll extension.
            string[] fileNames =
                Directory.GetFiles(
                Utils.ExtensionsDirectory,
                PREFIX + "*.dll");

            int numFiles = fileNames.Length;

            // Create the array the size of the number of files we found.
            myMVDlls = new IMVSynchronization[numFiles];

            string   fileName;
            Assembly assem;
            Type[]   types;
            Object   objLoaded = null;

            // Load the extension files into the array.
            for(int i = 0; i < numFiles; i++)
            {

                // Load the assembly.
                fileName = fileNames[i];
                assem    = Assembly.LoadFrom(fileName);

                types = assem.GetExportedTypes();

                // Examine all the object types in the assembly for
                // ones that starts with "MVExtension". We assume
                // this object type is an MV extension object type.
                foreach(Type type in types)
                {
                    if(type.GetInterface("Microsoft.MetadirectoryServices.IMVSynchronization") != null)
                    {

                        // Create an instance of the MV extension object type.
                        objLoaded = assem.CreateInstance(type.FullName);
                        break;
                    }
                }

                // If an object type starting with "MVExtension" could not be found,
                // or if an instance could not be created, throw an exception.
                if(null == objLoaded)
                {
                    throw new UnexpectedDataException("Found MV extension " +
                        "DLL (" + fileName + ") without an " + PREFIX + "* type");
                }

                // Add this MV extension object to our array of objects.
                myMVDlls[i] = (IMVSynchronization)objLoaded;

                // Call the Initialize() method on each MV extension object.
                myMVDlls[i].Initialize();
            }
        }

        void IMVSynchronization.Terminate ()
        {

            // Call the Terminate() method on each MV extension object.
            foreach(IMVSynchronization mvextension in myMVDlls)
            {
                mvextension.Terminate();
            }
        }

        void IMVSynchronization.Provision (MVEntry mventry)
        {

            // Call the Provision() method on each MV extension object.
            foreach(IMVSynchronization mvextension in myMVDlls)
            {
                mvextension.Provision(mventry);
            } 
        }

        bool IMVSynchronization.ShouldDeleteFromMV (CSEntry csentry, MVEntry mventry)
        {
            bool shouldDelete = false;

            // Call the ShouldDeleteFromMV() method on each MV extension object.
            foreach(IMVSynchronization mvextension in myMVDlls)
            {
                if(mvextension.ShouldDeleteFromMV(csentry, mventry))
                {
                    shouldDelete = true;
                    break;
                }
            }

            return(shouldDelete);
        }
    }
}

See Also

Show: