-
Notifications
You must be signed in to change notification settings - Fork 20
Classification
A classification is a piece of code that runs over the event stream for an entity in order to decide whether that entity instance is included or excluded from the group rule of the classifier
For each event in the stream it needs to decide (a) am I interested in this kind of event and if so (b) what does this mean to group classification.
The following classification runs over the event stream for a command to classify if the command is completed.
/// <summary>
/// A classification to denote that a command execution has completed
/// </summary>
public class Completed
: ClassificationBase,
IClassifyEventType<CommandHandler.Events.Completed>
{
public Classification.ClassificationResults ClassifyEventInstance(Events.Completed eventInstance)
{
return Classification.ClassificationResults.Include;
}
}
A classification is run by a Classification Processor and you can specify the Event Stream and classifier to use by parameter binding with a Classification attribute.
In order to turn a classification into a group we need to get the complete list of all the Entity Instance Identifier of a particular Entity Type to run a classification over.
The Classification class provides a GetAllInstanceKeys
method to do this. For example to list all the bank account numbers:
[FunctionName("GetAllAccounts")]
public static async Task<HttpResponseMessage> GetAllAccountsRun(
[HttpTrigger(AuthorizationLevel.Function, "GET", Route = @"GetAllAccounts/{asOfDate?}")]HttpRequestMessage req,
string asOfDate,
[Classification("Bank", "Account", "ALL", nameof(InterestAccruedToday))] Classification clsAllAccounts)
{
// Set the start time for how long it took to process the message
DateTime startTime = DateTime.UtcNow;
IEnumerable<string> allAccounts = await clsAllAccounts.GetAllInstanceKeys(null);
System.Text.StringBuilder sbRet = new System.Text.StringBuilder();
if (null != allAccounts )
{
foreach (string accountNumber in allAccounts)
{
if (! (sbRet.Length == 0))
{
sbRet.Append(",");
}
sbRet.Append(accountNumber);
}
}
return req.CreateResponse<FunctionResponse>(System.Net.HttpStatusCode.OK,
FunctionResponse.CreateResponse(startTime,
false,
$"Account numbers: {sbRet.ToString()} "),
FunctionResponse.MEDIA_TYPE);
}