How to: Create Management Agent Rules Extensions in Visual Basic
You can use Microsoft Visual Studio 2008 to create a management agent rules extension for Forefront Identity Manager Synchronization Service (FIM Synchronization Service). There are two ways to create the project files for rules extensions:
Use Synchronization Service Manager to create a Visual Studio 2008 project.
Use Visual Studio 2008 to create the project.
Using Synchronization Service Manager is the easiest way to create the project. Synchronization Service Manager creates the necessary files and automatically makes the reference to the Microsoft.MetadirectoryServices.dll assembly. However, using the Synchronization Service Manager to create your project files limits you to creating your rules extension on the same system where Forefront Identity Manager (FIM) is installed. For more information about using Synchronization Service Manager to create the project files, see Forefront Identity Manager Technical Reference.
If you want to create your rules extension on a different system, you can use Visual Studio 2008 to create the project files. You must copy the Microsoft.MetadirectoryServices assembly to your development system and manually create a reference to the assembly. You can find the assembly in the bin\assemblies folder of the FIM Synchronization Service program folder. The default folder for FIM Synchronization Service is %ProgramFiles%\Microsoft Forefront Identity Manager\2010\Synchronization Service\bin\assemblies\.
To create a rules extension using Visual Studio 2008, you must follow these steps:
Create a new Visual Basic class library project.
Add a reference to the Microsoft.MetadirectoryServices assembly.
Copy the code to the code pane and make changes to the code.
Build the class library.
Install the rules extension in the rules extensions folder (optional).
To create a new Visual Basic class library project using Visual Studio 2008
Click Start, point to All Programs, and then click Microsoft Visual Studio 2008.
The Visual Studio development environment appears.
On the File menu, point to New, and then click Project.
In the New Project dialog box, under Project Types, click Visual Basic.
On the Template menu, click Class Library.
In the Name box, type the name of your rules extension, and then click Browse.
Browse to the location where you want to store the project files, click Open, and then click OK. Your project name now appears in Solution Explorer.
Note
We recommend that you store the project on your local computer instead of a network location.
To add a reference to the Microsoft.MetadirectoryServices assembly
In Visual Studio 2008, on the Project menu, click Add Reference.
In the Add Reference dialog box, on the .NET tab, click Microsoft.MetadirectoryServices, and then click OK. If the file does not appear in the Component Name list, click the Browse tab. Browse to the folder that contains the assembly file, click Microsoft.MetadirectoryServices, and then click Open.
Click OK to close the Add Reference dialog box.
In Solution Explorer, Microsoft.MetadirectoryServices now appears as one of the references.
To copy the code to the code pane and make changes to the code
Delete the existing code in the code pane, and then copy and paste the following example in the code pane.
Imports Microsoft.MetadirectoryServices ' Replace <sample extension object name> with the name of your rules ' extension class. If you do not replace <sample extension object name> ' with the name of your rules extension class, you will not be able to ' compile this file. Public Class <sample extension object name> Implements IMASynchronization Public Sub Initialize() Implements IMASynchronization.Initialize ' TODO: Add initialization code here. End Sub Public Sub Terminate() Implements IMASynchronization.Terminate ' TODO: Add termination code here. End Sub Public Function ShouldProjectToMV(ByVal csentry As CSEntry, ByRef MVObjectType As String) As Boolean Implements IMASynchronization.ShouldProjectToMV ' TODO: Remove this throw statement if you implement this method. Throw New EntryPointNotImplementedException() End Function Public Function FilterForDisconnection(ByVal csentry As CSEntry) As Boolean Implements IMASynchronization.FilterForDisconnection ' TODO: Add stay-disconnector code here. Throw New EntryPointNotImplementedException() End Function Public Sub MapAttributesForJoin(ByVal FlowRuleName As String, ByVal csentry As CSEntry, ByRef values As ValueCollection) Implements IMASynchronization.MapAttributesForJoin ' TODO: Add join mapping code here. Throw New EntryPointNotImplementedException() End Sub Public Function ResolveJoinSearch(ByVal joinCriteriaName As String, ByVal csentry As CSEntry, ByVal rgmventry() As MVEntry, ByRef imventry As Integer, ByRef MVObjectType As String) As Boolean Implements IMASynchronization.ResolveJoinSearch ' TODO: Add join resolution code here. Throw New EntryPointNotImplementedException() End Function Public Sub MapAttributesForImport(ByVal FlowRuleName As String, ByVal csentry As CSEntry, ByVal mventry As MVEntry) Implements IMASynchronization.MapAttributesForImport ' TODO: write your import attribute flow code. Throw New EntryPointNotImplementedException() End Sub Public Sub MapAttributesForExport(ByVal FlowRuleName As String, ByVal mventry As MVEntry, ByVal csentry As CSEntry) Implements IMASynchronization.MapAttributesForExport ' TODO: Add export attribute flow code here. Throw New EntryPointNotImplementedException() End Sub Public Function Deprovision(ByVal csentry As CSEntry) As DeprovisionAction Implements IMASynchronization.Deprovision ' TODO: Remove this throw statement if you implement this method. Throw New EntryPointNotImplementedException() End Function End Class
In the code, replace all instances of
<sample extension object name>
with the name of your rules extension class. Be sure to remove the angle brackets (< >).
To build the class library
On the Build menu, click Build Solution.
If you see the following message, the rules extension was successfully built:
------ Build started: Project: Management Agent Rules Extension, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... Building satellite assemblies... ---------------------- Done ---------------------- Build: 1 succeeded, 0 failed, 0 skipped
The rules extension file, which has a .dll extension, is in the bin\Debug folder of your project folder.
Before using the rules extension, install it in the FIM Synchronization Service rules extensions folder. The default folder for rules extensions is %ProgramFiles%\Microsoft Forefront Identity Manager\2010\Synchronization Service\Extensions.
The following procedure is optional. Alternatively, you can set Visual Studio 2008 to install the rules extension automatically in the rules extensions folder as part of the build process.
To install the rules extension in the rules extensions folder
In Solution Explorer, click your class library project.
On the View menu, click Property Pages.
Select the Compile tab.
In the Configuration drop-down list, click All Configurations.
In the Build Output Path text box, type the name of the rules extensions folder, or browse to the location of the rules extensions folder. The default folder for rules extensions is %ProgramFiles%\Microsoft Forefront Identity Manager\2010\Synchronization Service\Extensions.
Close the Property Pages dialog box.
Keep the following issues in mind when you use the Extensions folder:
Avoid using the Extensions folder to store files that must be kept open or frequently modified, such as log files. The Extensions folder is automatically backed up to the Microsoft SQL Server 2008 database. If any file in this folder is locked, the backup to the SQL Server 2008 database fails.
Avoid making changes to any files in the Extensions folder while you are running a management agent run profile. If you change a file in the Extensions folder while you are running a management agent run profile, the action returns the "stopped-extension-dll-updated-version" value.
Store configuration information that your rules extension requires in an initialization file in the Extensions folder because the Extensions folder is backed up by the SQL Server database. For more information, see How to: Read Settings for Rules Extensions.
See Also
Concepts
How to: Create Management Agent Rules Extensions
How to: Create Management Agent Rules Extensions in C#