Name Latest Version
C# strongly-typed resources and helper classes generators 1.1

Description

Set of scripts to create C# wrappers for strongly-typed resources (RmPerson, RmGroup etc) and other helper classes, reading types and attributes definitions in FIM.
Generating the C# files from the schema, rather than getting some C# files directly, allows to include user-defined types and attributes.
The generated files can be included in a project to provide

Requirements

To run the scripts you need

fim-resource - added in version 1.1

Creates a C# file with the definition of a strongly typed resource, i.e. a class extending RmResource for a particular FIM resource definition.
The scripts reads the type definition from the FIM schema and then expands some templates, which are text files located under the "fim-resource-templates" folder.

Important:After generating a new class, you must modify the CreateResource method of the DefaultResourceTypeFactory class. For example, to add support for the RmSet class, you could do as follows:
public virtual RmResource CreateResource(string resourceType) {
    if (String.IsNullOrEmpty(resourceType)) {
        return new RmResource();
    }
    String upperCaseResourceType = resourceType.ToUpperInvariant();
    switch (upperCaseResourceType) {
    case @"GROUP":
        return new RmGroup();
    case @"PERSON":
        return new RmPerson();
    // add this case statement to add support for strongly-typed sets.    
    case @"SET":
        return new RmSet();
    default:
        return new RmResource();
    }
}
For more details, you can have a look at this post.

About template files:
Please note that the classes are generated as partial classes; therefore, if for example you want to add a method to a particular class, you can do so in a separate file, so that if you re-generate the automatically created part, your custom method is not lost.

Example (much code and comments omitted for clarity):
public partial class RmPerson : RmResource {

    public string AccountName {
        get {
            return GetString(AttributeNames.AccountName);
        }
        set {
            base[AttributeNames.AccountName].Value = value;
        }
    }
    
    public DateTime? EmployeeStartDate {
        get {
            return GetNullable<DateTime>(AttributeNames.EmployeeStartDate);
        }
        set {
            base[AttributeNames.EmployeeStartDate].Value = value;
        }
    }
    
    // more attributes and code...        

fim-attribute-names

Creates a C# file containing a class with constants for FIM attribute names.

Example:
public static class AttributeNames {

    /// <summary>
    /// Account Name
    /// User's log on name
    /// </summary>
    public const string AccountName = "AccountName";
    // more attributes...

}

fim-attribute-values

Creates a C# file containing classes with constants for FIM attribute values; the attributes considered are those having a validation string (StringRegex attribute) in the form ^(value1|value2|valueN)$.
If an empty string is a valid value for the attribute, i.e. the validation string is in the form
^(value1|value2|valueN)?$
then also a costant with an empty string is generated.

Example:
public static class EmployeeTypeValues {
    public const string EmptyEmployeeType = "";
    public const string Contractor = "Contractor";
    public const string Intern = "Intern";
    public const string FullTimeEmployee = "Full Time Employee";
}

fim-type-names

Creates a C# file containing a class with constants for FIM type names.

Example:
public static class TypeNames {
    /// <summary>
    /// User
    /// This resource defines applicable policies to manage incoming requests. 
    /// </summary>
    public const string Person = "Person";
    
    // more definitions...        
}

Usage

All the script display an help message if invoked with the -help switch.
The most relevant parameters are the following:

Download

To download this script, use this link.
To get to the FIM ScriptBox, use this link.


Paolo Tedesco - http://espace.cern.ch/idm