Example: Creating a New Connector or Renaming an Existing Connector

When you project, join, or disconnect a CSEntry object to the metaverse or import attribute flow changes to the attribute values on the metaverse, the IMVSynchronization.Provision method provides you with the opportunity to react to those changes. The method hosts the logic to create a connector to an MVEntry object, to rename or move a connector to an MVEntry object, or to disconnect and deprovision a connector to an MVEntry object.

The following example shows how to use the Visual Basic .NET and C# programming languages to rename an existing connector or create a new connector for a CSEntry object by constructing a distinguished name based on attributes on the MVEntry object.

    Public Sub Provision( _
        ByVal mventry As MVEntry) _
        Implements IMVSynchronization.Provision
    
        Dim container As String
        Dim rdn As String
        Dim FabrikamADMA As ConnectedMA
        Dim numConnectors As Integer
        Dim myConnector As CSEntry
        Dim csentry As CSEntry
        Dim dn As ReferenceValue
    
        ' Ensure that the cn attribute is present.
        If Not mventry("cn").IsPresent Then
            Throw New UnexpectedDataException("cn attribute is not present.")
        End If
    
        ' Determine the container and relative distinguished name 
        ' of the new connector space entry.
        container = "CN=users,DC=fabrikam,DC=com"
        rdn = "CN=" & mventry("cn").Value
    
        FabrikamADMA = mventry.ConnectedMAs("Fabrikam AD MA")
        dn = FabrikamADMA.EscapeDNComponent(rdn).Concat(container)
    
        numConnectors = FabrikamADMA.Connectors.Count
    
        ' If there is no connector present, create a new connector.
        If 0 = numConnectors Then
            csentry = FabrikamADMA.Connectors.StartNewConnector("user")
            csentry.DN = dn
            csentry.CommitNewConnector()
    
        ElseIf 1 = numConnectors Then
            ' Check if the connector has a different DN and rename if necessary.
            ' Get the connector.
            myConnector = FabrikamADMA.Connectors.ByIndex(0)
    
            ' Microsoft Identity Integration Server<entity type="nbsp"/>2003 will rename/move if different, if not, nothing will happen.
            myConnector.DN = dn
        Else
            Throw New UnexpectedDataException("multiple connectors:" + numConnectors.ToString)
        End If
    End Sub
    void IMVSynchronization.Provision(MVEntry mventry)
    {
        string container;
        string rdn; 
        ConnectedMA FabrikamADMA; 
        int numConnectors;
        CSEntry myConnector;
        CSEntry csentry; 
        ReferenceValue dn; 
    
        // Ensure that the cn attribute is present.
        if(!mventry["cn"].IsPresent)
        {
            throw new UnexpectedDataException("cn attribute is not present.");
        }
    
        // Determine the container and relative distinguished name 
        // of the new connector space entry.
        container = "CN=users,DC=fabrikam,DC=com";
        rdn = "CN=" + mventry["cn"].Value;   
            
        FabrikamADMA = mventry.ConnectedMAs["Fabrikam AD MA"];
        dn = FabrikamADMA.EscapeDNComponent(rdn).Concat(container);
    
        numConnectors = FabrikamADMA.Connectors.Count;
            
        // If there is no connector present, create a new connector.
        if (numConnectors == 0)
        {
            csentry = FabrikamADMA.Connectors.StartNewConnector("user");
            csentry.DN = dn;
            csentry.CommitNewConnector();
        }
    
        else if (numConnectors == 1)
        {
            // Check if the connector has a different DN and rename if necessary.
            // Get the connector.
            myConnector = FabrikamADMA.Connectors.ByIndex[0];
            
            // Microsoft Identity Integration Server<entity type="nbsp"/>2003 will rename/move if different, if not, nothing will happen.
            myConnector.DN = dn;
        }
        else
        {
            throw(new UnexpectedDataException("multiple connectors:" + numConnectors.ToString()));
        }
    }

Send comments about this topic to Microsoft

Build date: 2/16/2009