private async Task Init(CMMNExecutionContext executionContext, TimerEventListener elt, CancellationToken token) { var currentDateTime = DateTime.UtcNow; var elapsedTime = ISO8601Parser.ParseTime(elt.TimerExpression.Body); var repeatingInterval = ISO8601Parser.ParseRepeatingTimeInterval(elt.TimerExpression.Body); if (repeatingInterval != null) { if (currentDateTime >= repeatingInterval.Interval.EndDateTime) { return; } var startDate = currentDateTime; if (startDate < repeatingInterval.Interval.StartDateTime) { startDate = repeatingInterval.Interval.StartDateTime; } var diff = repeatingInterval.Interval.EndDateTime.Subtract(startDate); var newTimespan = new TimeSpan(diff.Ticks / (repeatingInterval.RecurringTimeInterval)); for (var i = 0; i < repeatingInterval.RecurringTimeInterval; i++) { currentDateTime = currentDateTime.Add(newTimespan); var newInstance = elt; if (i > 0) { newInstance = executionContext.Instance.TryCreateInstance(elt) as TimerEventListener; } await TrySubscribe(executionContext, newInstance, CMMNConstants.ExternalTransitionNames.Occur, token); await _messageBroker.ScheduleExternalEvt(CMMNConstants.ExternalTransitionNames.Occur, executionContext.Instance.AggregateId, newInstance.Id, currentDateTime, token); } } if (elapsedTime != null) { if (currentDateTime >= elapsedTime) { return; } await TrySubscribe(executionContext, elt, CMMNConstants.ExternalTransitionNames.Occur, token); await _messageBroker.ScheduleExternalEvt(CMMNConstants.ExternalTransitionNames.Occur, executionContext.Instance.AggregateId, elt.Id, elapsedTime.Value, token); } }
public virtual DateTime?Evaluate(HumanTaskDefinitionDeadLine deadLine, BaseExpressionContext expressionContext) { DateTime?nextUTC = null; if (!string.IsNullOrWhiteSpace(deadLine.Until)) { var interval = ISO8601Parser.ParseTimeInterval(deadLine.Until); if (interval != null) { nextUTC = interval.EndDateTime; } } if (nextUTC == null && !string.IsNullOrWhiteSpace(deadLine.For)) { nextUTC = ExpressionParser.GetDateTime(deadLine.For, expressionContext); } return(nextUTC); }