Microsoft Identity Integration Server 2003 Developer Reference

Example: Swapping the Order of a Name

Attribute values that are staged in the connector space might need some data transformations before they are flowed into the metaverse. Rules extensions can do these data transformations during import attribute flow. For example, business rules may require that the displayName attribute be stored in the metaverse as the combination of the first and last name of the user. However, the connected data source may provide the data in this attribute with the last name before the first name. To swap these values, you can use a rules extension.

The following example shows how to swap the order of the names:

[Visual Basic .NET]
Public Sub MapAttributesForImport(ByVal FlowRuleName As String, ByVal csentry As CSEntry, ByVal mventry As MVEntry) Implements IMASynchronization.MapAttributesForImport
	Select Case FlowRuleName
		Case "displayName"
			Try
				mventry("fileAs").Value = SwapNames(csentry("displayName").StringValue)
			Catch e As AttributeNotPresentException
				Console.WriteLine(e.ToString())
			Catch e As AttributeNotDefinedAsSourceException
				Console.WriteLine(e.ToString())
			End Try
	End Select
End Sub

Function SwapNames(ByVal Input As String) As String
	Try
		Dim Elements() As String
		Dim Delimiters() As Char

		Delimiters = ",".ToCharArray
		Elements = Input.Split(Delimiters)

		' Verify that the string contains one comma. Any more or any less and this 
		' function will just return the original string.
		If Elements.Length <> 2 Then
			SwapNames = Input
			Exit Function
		End If

		Dim Output As String

		' Get the first string after trimming off any whitespace.
		Output = Elements(1).Trim()

		' Add the space and second string after trimming off any whitespace.
		Output += " " + Elements(0).Trim()

		SwapNames = Output

	Catch ex As Exception
		' If anything goes wrong, just return the original string.
		SwapNames = Input
	End Try
End Function
[C#]
void IMASynchronization.MapAttributesForImport( string FlowRuleName, CSEntry csentry, MVEntry mventry)
{
	switch(FlowRuleName)
	{
		case "displayName":
		{
			try
			{
				mventry["fileAs"].Value = SwapNames(csentry["displayName"].StringValue);
		}
			catch ( AttributeNotPresentException e)
			{
				Console.WriteLine(e.ToString());
		}
			catch ( AttributeNotDefinedAsSourceException e)
			{
				Console.WriteLine(e.ToString());
		}
			break;
	}
}
}
public static string SwapNames(string Input)
{
	try
	{
		string[] Elements;
		char[] Delimiters;

		Delimiters = ",".ToCharArray();
		Elements = Input.Split(Delimiters);
					
		// Verify that the string contains one comma. Any more or any less and this 
		// function will just return the original string.
		if(Elements.Length != 2)
		{
			return Input;
	}

		string Output;

		// Get the first string after trimming off any whitespace.
		Output = Elements[1].Trim();

		// Add the space and second string after trimming off any whitespace.
		Output += " " + Elements[0].Trim();

		return Output;
}
	catch
	{
		// If anything goes wrong, just return the original string.
		return Input;
}
}