Skip to content

Getting Started

João Romeiro edited this page Apr 23, 2023 · 3 revisions

Setting up the rules engine

  1. Define your content types (suggestion: use an enum).
internal enum ContentTypes
{
    BodyMassIndexFormula = 1
}
  1. Define your condition types (suggestion: use an enum).
internal enum ConditionTypes
{
    MassUnitOfMeasure = 1,
    HeightUnitOfMeasure = 2
}
  1. Build a rules engine.
RulesEngine<ContentTypes, ConditionTypes> rulesEngine = RulesEngineBuilder.CreateRulesEngine()
    .WithContentType<ContentTypes>() // Your content types.
    .WithConditionType<ConditionTypes>() // Your condition types.
    .SetDataSource(rulesDataSource) // A rules data source instance implemented by you OR using one of the available providers.
    .Build();

Evaluating rules

NOTE: You should add rules before proceeding with evaluation. Please refer to add rules documentation to find out how to do that.

  1. Set the conditions to supply to the engine.
Condition<ConditionTypes>[] expectedConditions = new Condition<ConditionTypes>[]
{
    new Condition<ConditionTypes>
    {
        Type = ConditionTypes.MassUnitOfMeasure,
        Value = "pounds"
    },
    new Condition<ConditionTypes>
    {
        Type = ConditionTypes.HeightUnitOfMeasure,
        Value = "inches"
    }
};
  1. Set the date at which you want the rules set to evalutated.
DateTime date = new DateTime(2019, 1, 1);
  1. Set the content you want to fetch.
ContentTypes contentType = ContentTypes.BodyMassIndexFormula;
  1. Evalutate rule match.
Rule<ContentTypes, ConditionTypes> ruleMatch = await rulesEngine.MatchOneAsync(contentType, date, conditions);