I have seen all of the custom rules execute correctly. This is the only rule that I have not seen execute correctly. Possibly if there is one rule that is incorrect it would stop personalization running altogether?
public class AptifyMemberDuesPaidThruCondition<T> : OperatorCondition<T> where T : RuleContext
{
private readonly IAptifyAuthenticator _aptifyAuthenticator;
public AptifyMemberDuesPaidThruCondition() : this(ServiceLocator.ServiceProvider.GetService<IAptifyAuthenticator>())
{ }
public AptifyMemberDuesPaidThruCondition(IAptifyAuthenticator aptifyAuthenticator)
{
_aptifyAuthenticator = aptifyAuthenticator;
}
public string DuesPaidThru { get; set; }
/// <summary>
/// This function will be called to test the condition
/// </summary>
protected override bool Execute(T ruleContext)
{
//Check if the user is logged in, otherwise return false
if (!_aptifyAuthenticator.UserAptifyAuthenticated())
return false;
DateTime dateTime = DateUtil.ParseDateTime(this.DuesPaidThru, DateTime.MinValue);
if (dateTime.Kind != DateTimeKind.Utc)
{
string str = string.Concat("AptifyMemberDuesPaidThruCondition<T> expects UTC date, but date with different kind has been assigned to Now property: ", this.DuesPaidThru);
Log.Warn(str, this);
}
var actualDuesPaidThru = _aptifyAuthenticator.GetUserCustomerPropertyDate(AuthenticatedPropertyName.DuesPaidThru);
if (!actualDuesPaidThru.HasValue)
return false;
return DateComparer(actualDuesPaidThru.Value, dateTime, GetOperator());
}
private bool DateComparer(DateTime date1, DateTime date2, ConditionOperator conditionOperator)
{
switch (conditionOperator)
{
case ConditionOperator.Equal:
return date1.Equals(date2);
case ConditionOperator.LessThan:
return date1 < date2;
case ConditionOperator.LessThanOrEqual:
return date1 <= date2;
case ConditionOperator.GreaterThan:
return date1 > date2;
case ConditionOperator.GreaterThanOrEqual:
return date1 >= date2;
case ConditionOperator.NotEqual:
return !date1.Equals(date2);
default:
return false;
}
}
}
Any ideas where to troubleshoot?