Example: Moving Objects for Metaverse Object Changes
The following example shows how to move an object within a hierarchy because of a change in a metaverse object. The example moves the object according to the value of the department attribute.
Public Sub Provision(ByVal mventry As MVEntry) _
Implements IMVSynchronization.Provision
Dim Container As String
Dim ManagementAgent As ConnectedMA
Dim RDN As String
Dim DN As ReferenceValue
Dim Connectors As Integer
Dim csentry As CSEntry
If mventry("EmployeeStatus").IsPresent Then
If mventry("EmployeeStatus").Value.Equals("active") Then
' Create the container string based on the value of
' the department attribute.
Select Case mventry("department").Value
Case "Sales"
Container = "ou=Sales,dc=fabrikam,dc=com"
Case "Marketing"
Container = "ou=Marketing,dc=fabrikam,dc=com"
Case "Development"
Container = "ou=Development,dc=fabrikam,dc=com"
Case Else
Container = "ou=Pending,dc=fabrikam,dc=com"
End Select
End If
' Get the management agent connectors
ManagementAgent = mventry.ConnectedMAs("Fabrikam AD MA")
Connectors = ManagementAgent.Connectors.Count
' Construct the distinguished name.
RDN = "CN=" & mventry("cn").Value
DN = ManagementAgent.EscapeDNComponent(RDN).Concat(Container)
Connectors = ManagementAgent.Connectors.Count
' If there are no connectors, start creating the new connector.
' Set the distinguished name attribute and then finish
' creating the new connector.
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.
ElseIf 1 = Connectors Then
' Get the first connector and assign a new DN.
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
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"))
{
// Create the container string based on the value of
// the department attribute
switch(mventry["department"].Value)
{
case "Sales":
Container = "ou=Sales,dc=fabrikam,dc=com";
break;
case "Marketing":
Container = "ou=Marketing,dc=fabrikam,dc=com";
break;
case "Development":
Container = "ou=Development,dc=fabrikam,dc=com";
break;
default:
Container = "ou=Pending,dc=fabrikam,dc=com";
break;
}
// Get the management agent connectors.
ManagementAgent = mventry.ConnectedMAs["Fabrikam AD MA"];
Connectors = ManagementAgent.Connectors.Count;
// Construct the distinguished name.
RDN = "CN=" + mventry["cn"].Value;
DN = ManagementAgent.EscapeDNComponent(RDN).Concat(Container);
// If there are no connectors, start creating the new connector
// Set the distinguished name attribute and then finish
// creating the new connector.
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(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
Send comments about this topic to Microsoft
Build date: 2/16/2009