I will use this post to use as a base for all future and previous extensions written to be used for Management Agents in your environment.
The post that will reference this post will focus on individual sections of the extension allowing this post to focus on the extension as a whole so you can see how it works all together.
Additionally I am writing this 1 MA Extension to be used across all my Management Agents in my Environment, instead of writing individual extensions for each MA.
Additional links for understanding rules extensions
Management Agent Rules Extensions
3/25/2016 12:45 PM Central Time
using System;
using Microsoft.MetadirectoryServices;
using System.Globalization;
namespace Mms_ManagementAgent_MAExtension
{
/// <summary>
/// Summary description for MAExtensionObject.
/// </summary>
public class MAExtensionObject : IMASynchronization
{
public MAExtensionObject()
{
//
// TODO: Add constructor logic here
//
}
void IMASynchronization.Initialize ()
{
//
// TODO: write initialization code
//
}
void IMASynchronization.Terminate ()
{
//
// TODO: write termination code
//
}
bool IMASynchronization.ShouldProjectToMV (CSEntry csentry, out string MVObjectType)
{
//
// TODO: Remove this throw statement if you implement this method
//
throw new EntryPointNotImplementedException();
}
DeprovisionAction IMASynchronization.Deprovision (CSEntry csentry)
{
//
// TODO: Remove this throw statement if you implement this method
//
throw new EntryPointNotImplementedException();
}
bool IMASynchronization.FilterForDisconnection (CSEntry csentry)
{
//
// TODO: write connector filter code
//
throw new EntryPointNotImplementedException();
}
void IMASynchronization.MapAttributesForJoin(string FlowRuleName, CSEntry csentry, ref ValueCollection values)
{
//
// TODO: write join mapping code
//
values.Add(csentry[“samAccountName”].StringValue.Replace(“SP_”, “”));
//throw new EntryPointNotImplementedException();
}
bool IMASynchronization.ResolveJoinSearch(string joinCriteriaName, CSEntry csentry, MVEntry[] rgmventry, out int imventry, ref string MVObjectType)
{
//
// TODO: write join resolution code
//
throw new EntryPointNotImplementedException();
}
void IMASynchronization.MapAttributesForImport(string FlowRuleName, CSEntry csentry, MVEntry mventry)
{
//
// TODO: write your import attribute flow code
//
switch (FlowRuleName)
{
#region connected->mv.person:GetDate
case “connected->mv.person:getdate”:
if (mventry.ConnectedMAs[“Contoso ADMA”].Connectors.Count == 0)
{
if (mventry[“deprovisionDate”].IsPresent)
{
DateTime depoDate;
if(!DateTime.TryParse(mventry[“deprovisionDate”].Value, out depoDate))
{
//mventry [“deprovisionDate”].Value = DateTime.Now.AddDays(90).ToString(“yyyy’-‘MM’-‘dd’T’HH':’mm':’ss’.000′”);
mventry[“deprovisionDate”].Value = DateTime.Now.AddDays(90).ToString(“yyyy-MM-ddTHH:mm:ss”);
}
else
{
mventry[“deprovisionDate”].Value = DateTime.Now.AddDays(90).ToString(“yyyy-MM-ddTHH:mm:ss”);
}
}
}
break;
#endregion // connected ->mv.person.GetDate
#region connected->mv.person:RemoveDate
case “connected->mv.person:RemoveDate”:
if (mventry.ConnectedMAs[“Contoso ADMA”].Connectors.Count == 1)
{
if (mventry[“deprovisionDate”].IsPresent)
{
mventry[“deprovisionDate”].Values.Clear();
}
}
break;
#endregion // connected ->mv.person.GetDate
#region cd.user:accountExpires->mv.person:employeeEndDate
case “cd.user:accountExpires->mv.person:employeeEndDate”:
if (csentry[“accountExpires”].IntegerValue == 0 || csentry[“accountExpires”].IntegerValue == 9223372036854775807)
{
// This is a special condition, do not contribute and delete any current value
mventry[“employeeEndDate”].Delete();
}
else
{
DateTime dtFileTime = DateTime.FromFileTime(csentry[“accountExpires”].IntegerValue);
mventry[“employeeEndDate”].Value =
dtFileTime.ToString(“yyyy’-‘MM’-‘dd’T’HH':’mm':’ss’.000′”);
}
break;
#endregion // cd.user:accountExpires->mv.person:employeeEndDate
#region cd.user:pwdLastSet->mv.person:pwdLastSet
case “cd.user:pwdLastSet->mv.person:pwdLastSet”:
if (csentry[“pwdLastSet”].IsPresent && csentry[“pwdLastSet”].IntegerValue != 0)
mventry[“pwdLastSet”].Value = ConvertFileTimeToFimTimeStamp(csentry[“pwdLastSet”].IntegerValue);
else
mventry[“pwdLastSet”].Delete();
break;
#endregion // cd.user:pwdLastSet->mv.person:pwdLastSet
#region cd.user:lastLogonTimestamp->mv.person:lastLogonTimestamp
case “cd.user:lastLogonTimestamp->mv.person:lastLogonTimestamp”:
if (csentry[“lastLogonTimestamp”].IsPresent && csentry[“lastLogonTimestamp”].IntegerValue != 0)
mventry[“lastLogonTimestamp”].Value = ConvertFileTimeToFimTimeStamp(csentry[“lastLogonTimestamp”].IntegerValue);
else
mventry[“lastLogonTimeStampString”].Delete();
break;
#endregion // cd.user:lastLogonTimestamp->mv.person:lastLogonTimestamp
}
}
private static string ConvertFileTimeToFimTimeStamp(long fileTime)
{
return DateTime.FromFileTimeUtc(fileTime).ToString(“yyyy-MM-ddTHH:mm:ss.000″);
}
void IMASynchronization.MapAttributesForExport(string FlowRuleName, MVEntry mventry, CSEntry csentry)
{
//
// TODO: write your export attribute flow code
//
//
// TODO: write your export attribute flow code
//
switch (FlowRuleName)
{
#region cd.user:accountExpires<-mv.person:employeeEndDate
case “cd.user:accountExpires<-mv.person:employeeEndDate”:
CultureInfo provider = CultureInfo.InvariantCulture;
if (mventry[“employeeEndDate”].ToString() != “”)
{
//DateTime dtFileTime = DateTime.ParseExact(mventry[“employeeEndDate”].Value, “yyyy’-‘MM’-‘dd’T’HH':’mm':’ss’.000′”, provider);
DateTime dtFileTime = DateTime.Parse(mventry[“employeeEndDate”].Value, provider);
csentry[“accountExpires”].IntegerValue = dtFileTime.ToFileTime();
}
break;
#endregion
}
}
}
}