Microsoft Identity Integration Server 2003 Developer Reference

Example: LDAP-based Connected Data Sources

LDAP-based connected data sources require a unique distinguished name for each object. The following example can be used to provision the connector space for these management agents:

[Visual Basic .NET]
Public Sub Provision( _
   ByVal mventry As MVEntry) _
   Implements IMVSynchronization.Provision

   Dim ManagementAgent As ConnectedMA  ' Management agent object
   Dim Connectors As Integer		 ' Management agent connectors
   Dim DN As ReferenceValue			' Distinguished name attribute
   Dim Container As String			 ' Container name
   Dim RDN As String				 ' Relative distinguished name strings
   Dim csentry As CSEntry			' Connector space entry object

   ' Determine the state of the metaverse object.   
   If mventry("EmployeeStatus").IsPresent _
	AndAlso mventry("EmployeeStatus").Value.Equals("active") Then

	' Get the management agent connectors.
	ManagementAgent = mventry.ConnectedMAs("LDAP-based MA")
	Connectors = ManagementAgent.Connectors.Count

	 ' Construct the distinguished name.
	Container = "CN=users,DC=fabrikam,DC=com"
	RDN = "CN=" & mventry("cn").Value
	DN = ManagementAgent.EscapeDNComponent(RDN).Concat(Container)

	' If there are no connectors, create the connector, set the distinguished
	' name attribute, and then add the new connector to the collection.
	If 0 = Connectors Then
		 csentry = ManagementAgent.Connectors.StartNewConnector("user")
		 csentry.DN = DN
		 csentry.CommitNewConnector()

	' If a connector exists, get the existing connector and assign the new 
	' distinguished name value. If the original attribute value is the same
	' as the new distinguished name, then the original attribute value 
	' remains the same.
	ElseIf 1 = Connectors Then
		 csentry = ManagementAgent.Connectors.ByIndex(0)
		 csentry.DN = DN

	' Throw an exception if more than one connector exists.
	Else
		 Dim ExceptionMessage As String
		 ExceptionMessage = "Multiple Connectors on Management Agent"
		 Throw New UnexpectedDataException(ExceptionMessage)
	End If

   End If

End Sub
[C#]
void IMVSynchronization.Provision(MVEntry mventry)
{
	ConnectedMA ManagementAgent;  // Management agent object
	int Connectors = 0; 	 // Management agent connectors
	ReferenceValue DN; 		// Distinguished name attribute
	string Container; 		 // Container name
	string RDN ; 			// Relative distinguished name strings
	CSEntry csentry; 		// Connector space entry object

	// Determine the state of the metaverse object.   
	if(mventry["EmployeeStatus"].IsPresent)
	{
		if(mventry["EmployeeStatus"].Value.Equals("active"))
		{
			// Get the management agent connectors.
			ManagementAgent = mventry.ConnectedMAs["LDAP-based MA"];
			Connectors = ManagementAgent.Connectors.Count;

			// Construct the distinguished name.
			Container = "CN=users,DC=fabrikam,DC=com";
			RDN = "CN=" + mventry["cn"].Value;
			DN = ManagementAgent.EscapeDNComponent(RDN).Concat(Container);

			// If there are no connectors, create the connector, set the distinguished
			// name attribute, and then add the new connector to the collection.
			if(0 == Connectors)
			{
				csentry = ManagementAgent.Connectors.StartNewConnector("user");
				csentry.DN = DN;
				csentry.CommitNewConnector();
		}

			// If a connector exists, get the existing connector and assign the new 
			// distinguished name value. If the original attribute value is the same
			// as the new distinguished name, then the original attribute value 
			// remains the same.

			else if(1 == Connectors)
			{
				csentry = ManagementAgent.Connectors.ByIndex[0];
				csentry.DN = DN;
		}

			// Throw an exception if more than one connector exists.

			else
			{
				string ExceptionMessage; 
				ExceptionMessage = "Multiple Connectors on Management Agent";
				throw new UnexpectedDataException(ExceptionMessage);
		}
	}
}
}

See Also

Provisioning Objects in the Connector Space, ConnectorCollection.StartNewConnector, ManagementAgent.EscapeDNComponent, CSEntry.DN, CSEntry.CommitNewConnector