You can duplicate the hierarchy of one connected data source in another connected data source during the provisioning phase of synchronization in Forefront Identity Manager Synchronization Service (FIM Synchronization Service). The following example shows how you can do this. This example requires that you flow the distinguished name (DN) into the objectDN attribute in the metaverse during import attribute flow.

Visual Basic  Copy Code
Dim AFGALContainer As String

Public Sub Provision(ByVal mventry As MVEntry) _
	Implements IMVSynchronization.Provision

	Try
		Dim containerInfo As String

		Dim dn, finalValue	 As ReferenceValue
		Dim myConnector, csentry As CSEntry
		Dim numADConnectors	As Integer

		Dim JDPMA As ConnectedMA = mventry.ConnectedMAs("AD-AMC")

		Dim dnValue As ReferenceValue = JDPMA.CreateDN(mventry("objectDN").Value)

		Dim depth As Integer = dnValue.Depth

		' If there is no connector present, add a new AD connector
		' and call a subroutine to set the initial values on the CS Object.
		numADConnectors = JDPMA.Connectors.Count

		If 0 = numADConnectors Then
			Dim adObjectType As String

			Select Case mventry.ObjectType.ToLower
				Case "person"
					adObjectType  = "contact"
					finalValue	= dnValue.Subcomponents(1, depth - 1)
					containerInfo = finalValue.ToString
					containerInfo = containerInfo.ToUpper
					containerInfo = containerInfo.Replace("CN=", "OU=")

					dn = JDPMA.CreateDN("CN=" + mventry("cn").Value + "," + containerInfo + "," + AFGALContainer)

				Case "container"
					adObjectType  = "organizationalUnit"
					finalValue	= dnValue.Subcomponents(0, depth - 1)
					containerInfo = finalValue.ToString
					containerInfo = containerInfo.ToUpper
					containerInfo = containerInfo.Replace("CN=", "OU=")

					dn = JDPMA.CreateDN(containerInfo + "," + AFGALContainer)

				Case "organizationalunit"
					adObjectType  = "organizationalUnit"
					finalValue	= dnValue.Subcomponents(0, depth - 1)
					containerInfo = finalValue.ToString
					containerInfo = containerInfo.ToUpper

					dn = JDPMA.CreateDN(containerInfo + "," + AFGALContainer)
			End Select

			csentry	= JDPMA.Connectors.StartNewConnector(adObjectType)
			csentry.DN = dn
			csentry.CommitNewConnector()
		ElseIf 1 = numADConnectors Then
			' Check if the connector has a different DN and rename if necessary.

			' First get the connector.
			myConnector = JDPMA.Connectors.ByIndex(0)

			' MMS will rename or move if different.
			myConnector.DN = dn

		Else
			Throw New UnexpectedDataException("multiple AD connectors:" + numADConnectors.ToString)
		End If

	Finally
		' Add cleanup code.
	End Try

End Sub
C#  Copy Code
string AFGALContainer = "";

void IMVSynchronization.Provision (MVEntry mventry)
{
	try
	{
		string containerInfo;
		ReferenceValue dn = null, finalValue;
		CSEntry myConnector, csentry;
		int numADConnectors;

		ConnectedMA JDPMA = mventry.ConnectedMAs["AD-AMC"];

		ReferenceValue dnValue = JDPMA.CreateDN(mventry["objectDN"].Value);

		int depth = dnValue.Depth;

		// If there is no connector present, add a new AD connector
		// and call a subroutine to set the initial values on the CS Object.
		numADConnectors = JDPMA.Connectors.Count;

		if(numADConnectors == 0)
		{
			string adObjectType = "";

			switch(mventry.ObjectType.ToLower())
			{
				case "person":
					adObjectType  = "contact";
					finalValue	= dnValue.Subcomponents(1, depth - 1);
					containerInfo = finalValue.ToString();
					containerInfo = containerInfo.ToUpper();
					containerInfo = containerInfo.Replace("CN=", "OU=");

					dn = JDPMA.CreateDN("CN=" + mventry["cn"].Value + "," + containerInfo + "," + AFGALContainer);
					break;

				case "container":
					adObjectType  = "organizationalUnit";
					finalValue	= dnValue.Subcomponents(0, depth - 1);
					containerInfo = finalValue.ToString();
					containerInfo = containerInfo.ToUpper();
					containerInfo = containerInfo.Replace("CN=", "OU=");

					dn = JDPMA.CreateDN(containerInfo + "," + AFGALContainer);
					break;

				case "organizationalunit":
					adObjectType  = "organizationalUnit";
					finalValue	= dnValue.Subcomponents(0, depth - 1);
					containerInfo = finalValue.ToString();
					containerInfo = containerInfo.ToUpper();

					dn = JDPMA.CreateDN(containerInfo + "," + AFGALContainer);
					break;
		}

			csentry	= JDPMA.Connectors.StartNewConnector(adObjectType);
			csentry.DN = dn;
			csentry.CommitNewConnector();
	}
		else if(numADConnectors == 1)
		{
			// Check if the connector has a different DN and rename if necessary.
			// First get the connector.
			myConnector = JDPMA.Connectors.ByIndex[0];

			// <tla rid="fim_sync_short"/> will rename or move if different.
			myConnector.DN = dn;
	}
		else
		{
			throw new UnexpectedDataException("multiple AD connectors:" + numADConnectors.ToString());
	}
}
	finally
	{
		// Add cleanup code.
}
}

See Also

[an error occurred while processing this directive]