Example: Reading Settings for Rules Extensions

If your rules extension requires configuration information, you can store this information in an initialization file. We recommend that you use an XML file for storing configuration information. This file should be stored in the extensions folder of the Microsoft Identity Lifecycle Manager 2007, Feature Pack 1 installation folder. By storing your initialization files in the installation folder, you automatically save your initialization files in the Microsoft Identity Integration Server 2003 database along with your rules extension assemblies.

This example assumes that your initialization file uses the following XML configuration file:

    <rules-extension-properties>
    <account-provisioning>
        <container>
            <root>DC=fabrikam,DC=com</root>
            <active-users>OU=People</active-users>
            <inactive-users>OU=People (inactive)</inactive-users>
            <groups>OU=Groups</groups>
        </container>
    </account-provisioning>
    <management-agents>
        <fabrikam-ad-ma>
            <mail-suffix>@fabrikam.com</mail-suffix>
        </fabrikam-ad-ma>
    </management-agents>
    </rules-extension-properties>

The following example shows how to read an initialization file. Note that you need to make a reference to System.xml in this application.

    Imports Microsoft.MetadirectoryServices
    Imports System.Xml
    
    Public Class HRGroupProvisioning
        Implements IMVSynchronization
    
        ' If the variables declared in the Initialize() method will be used by  
        ' other methods, then you will need to declare them at the start of the  
        ' application so that they can be used as global variables.
        ' Dim fabrikamUsersContainer As String
        ' Dim fabrikamInactiveUsersContainer As String
        ' Dim fabrikamGroupsContainer As String
        ' Dim fabrikamMailSuffix As String
    
        Public Sub Initialize() Implements IMVSynchronization.Initialize
            ' These  variables are initialized based on a xml configuration file
            ' The values are read during the Initialize() method of the Rules Extension
            Dim fabrikamUsersContainer As String
            Dim fabrikamInactiveUsersContainer As String
            Dim fabrikamGroupsContainer As String
            Dim fabrikamMailSuffix As String
    
            Try
                Const XML_CONFIG_FILE = "\rules-config.xml"
    
                Dim config As XmlDocument = New XmlDocument()
                Dim dir As String = Utils.ExtensionsDirectory
                config.Load(dir + XML_CONFIG_FILE)
    
                Dim rnode As XmlNode = config.SelectSingleNode("rules-extension-properties/account-provisioning/container")
                Dim node As XmlNode = rnode.SelectSingleNode("root")
                Dim rootContainer As String = node.InnerText
        
                ' The following will return "OU=People".            
                node = rnode.SelectSingleNode("active-users")
                fabrikamUsersContainer = node.InnerText + "," + rootContainer
      
                ' The following will connect to the inactive-users node and return "OU=People".            
                node = rnode.SelectSingleNode("inactive-users")
                fabrikamInactiveUsersContainer = node.InnerText + "," + rootContainer
    
                ' The following will connect to the groups node and return "OU=Groups".            
                node = rnode.SelectSingleNode("groups")
                fabrikamGroupsContainer = node.InnerText + "," + rootContainer
    
                rnode = config.SelectSingleNode("rules-extension-properties/management-agents/fabrikam-ad-ma")
    
                ' The following will connect to the groups node and return "@fabrikam.com".            
                node = rnode.SelectSingleNode("mail-suffix")
                fabrikamMailSuffix = node.InnerText
            Catch nre As NullReferenceException
                'If a tag does not exist in the xml, then the stopped-extension-dll 
                'error will be thrown.
                ' You could log the exception before rethrowing.
                throw nre
    
            Catch e As Exception
                ' You could log the exception before rethrowing.
                throw e
    
            End Try
    
        End Sub
    End Class
    using Microsoft.MetadirectoryServices;
    using System.Xml;
    
    public class HRGroupProvisioning : IMVSynchronization
    {
        // If the variables declared in the Initialize() method will be used by  
        // other methods, then you will need to declare them at the start of the  
        // application so that they can be used as global variables.
        // string fabrikamUsersContainer;
        // string fabrikamInactiveUsersContainer;
        // string fabrikamGroupsContainer;
        // string fabrikamMailSuffix;
    
        void IMVSynchronization.Initialize ()
        {
            // These  variables are initialized based on a xml configuration file
            // The values are read during the Initialize() method of the Rules Extension
            string fabrikamUsersContainer;
            string fabrikamInactiveUsersContainer;
            string fabrikamGroupsContainer;
            string fabrikamMailSuffix;
    
            try
            {
                const string XML_CONFIG_FILE = @"\rules-config.xml";
                XmlDocument config  = new XmlDocument();
                string dir = Utils.ExtensionsDirectory;
                config.Load(dir + XML_CONFIG_FILE);
    
                XmlNode rnode  = config.SelectSingleNode
                    ("rules-extension-properties/account-provisioning/container");
                XmlNode node  = rnode.SelectSingleNode("root");
                string rootContainer  = node.InnerText;
    
                // The following will return "OU=People".
                node = rnode.SelectSingleNode("active-users");
                fabrikamUsersContainer = node.InnerText + "," + rootContainer;
    
                // The following will connect to the inactive-users node and return "OU=People".
                node = rnode.SelectSingleNode("inactive-users");
                fabrikamInactiveUsersContainer = node.InnerText + "," + rootContainer;
    
                // The following will connect to the groups node and return "OU=Groups".
                node = rnode.SelectSingleNode("groups");
                fabrikamGroupsContainer = node.InnerText + "," + rootContainer;
    
                rnode = config.SelectSingleNode("rules-extension-properties/management-agents/fabrikam-ad-ma");
    
                // The following will connect to the groups node and return "@fabrikam.com".
                node = rnode.SelectSingleNode("mail-suffix");
                fabrikamMailSuffix = node.InnerText;
            }
            catch(NullReferenceException nre)
            {
                // If a tag does not exist in the xml, then the stopped-extension-dll 
                // error will be thrown.
                // You could log the exception before rethrowing.
                throw;
            }
            catch (Exception e)
            {
                // You could log the exception before rethrowing.
                throw;
            }
        }
    }

Send comments about this topic to Microsoft

Build date: 2/16/2009