private DateTime?GetNextExecutionDateTime(TimerDefinition timerDefinition, ProcessInstance processInstance = null) { var timerValueParameterName = GetTimerValueParameterName(timerDefinition); if (timerDefinition.Value.Equals(ImmediateTimerValue) || timerDefinition.Value.Equals(InfinityTimerValue)) { if (processInstance == null) { return(null); } if (!processInstance.IsParameterExisting(timerValueParameterName)) { return(null); } return(processInstance.GetParameter <DateTime?>(timerValueParameterName)); } if (processInstance != null && processInstance.IsParameterExisting(timerValueParameterName)) { var value = processInstance.GetParameter <DateTime?>(timerValueParameterName); if (value != null) { return(value); } } switch (timerDefinition.Type) { case TimerType.Date: var date1 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture); return(date1.Date); case TimerType.DateAndTime: var date2 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture); return(date2); case TimerType.Interval: var interval = GetInterval(timerDefinition.Value); if (interval <= 0) { return(null); } return(_runtime.RuntimeDateTimeNow.AddMilliseconds(interval)); case TimerType.Time: var now = _runtime.RuntimeDateTimeNow; var date3 = DateTime.Parse(timerDefinition.Value, _runtime.SchemeParsingCulture); date3 = now.Date + date3.TimeOfDay; if (date3.TimeOfDay < now.TimeOfDay) { date3 = date3.AddDays(1); } return(date3); } return(_runtime.RuntimeDateTimeNow); }
/// <summary> /// Sends request for timer value for all timer transitions that are outgoing from the CurrentActivity if timer value is equal 0 or -1 /// </summary> /// <param name="processInstance">Process instance</param> public void RequestTimerValue(ProcessInstance processInstance, ActivityDefinition activity = null) { if (NeedTimerValue == null) { return; } var notDefinedTimerTransitions = processInstance.ProcessScheme.GetTimerTransitionForActivity(activity ?? processInstance.CurrentActivity, ForkTransitionSearchType.Both) .Where( t => (t.Trigger.Timer.Value.Equals(ImmediateTimerValue) || t.Trigger.Timer.Value.Equals(InfinityTimerValue)) && !processInstance.IsParameterExisting(GetTimerValueParameterName(t.Trigger.Timer))).ToList(); if (!notDefinedTimerTransitions.Any()) { return; } var eventArgs = new NeedTimerValueEventArgs(processInstance, notDefinedTimerTransitions); NeedTimerValue(this, eventArgs); foreach (var request in eventArgs.TimerValueRequests) { if (request.NewValue.HasValue) { processInstance.SetParameter(GetTimerValueParameterName(request.Definition), request.NewValue.Value, ParameterPurpose.Persistence); } } }
// // Conditions // private bool ShouldExecuteActivity(ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter) { if (string.IsNullOrWhiteSpace(actionParameter)) { return(true); } if (!processInstance.IsParameterExisting("ShouldExecute")) { return(true); } var parameter = processInstance.GetParameter <string>("ShouldExecute"); if (string.IsNullOrWhiteSpace(parameter)) { return(true); } var shouldExecuteMap = JsonConvert.DeserializeObject <Dictionary <string, object> >(parameter); if (shouldExecuteMap != null && shouldExecuteMap.ContainsKey(actionParameter) && shouldExecuteMap[actionParameter] is bool shouldExecute) { return(shouldExecute); } return(true); }
/// <summary> /// Resets value of named timer /// </summary> /// <param name="processInstance">Process instance</param> /// <param name="timerName">Timer name in Scheme</param> public void ResetTimerValue(ProcessInstance processInstance, string timerName) { var parameterName = GetTimerValueParameterName(timerName); if (!processInstance.IsParameterExisting(parameterName)) { return; } processInstance.SetParameter <DateTime?>(parameterName, null, ParameterPurpose.Persistence); }
private void RegisterTimers(ProcessInstance processInstance, List <string> usedTransitions) { var timersToRegister = processInstance.ProcessScheme.GetTimerTransitionForActivity(processInstance.CurrentActivity, ForkTransitionSearchType.Both) .Where(t => t.Trigger.Timer != null && !usedTransitions.Contains(t.Name)) .Where( t => (!t.Trigger.Timer.Value.Equals(InfinityTimerValue) && !t.Trigger.Timer.Value.Equals(ImmediateTimerValue)) || processInstance.IsParameterExisting(GetTimerValueParameterName(t.Trigger.Timer))) .Select(t => t.Trigger.Timer) .ToList(); if (!timersToRegister.Any()) { return; } RefreshOrRegisterTimer(processInstance, timersToRegister); }
/// <summary> /// Returns transitions triggered by a timer which value is equal to 0 /// </summary> /// <param name="processInstance">Process instance</param> /// <returns></returns> public IEnumerable <TransitionDefinition> GetTransitionsForImmediateExecution(ProcessInstance processInstance, ActivityDefinition activity = null) { return (processInstance.ProcessScheme.GetTimerTransitionForActivity(activity ?? processInstance.CurrentActivity, ForkTransitionSearchType.Both) .Where(t => t.Trigger.Timer.Value.Equals(ImmediateTimerValue) && !processInstance.IsParameterExisting(GetTimerValueParameterName(t.Trigger.Timer)))); }