protected virtual void BuildWorkflow(IEnumerable <WorkflowNode> allNodes, DefinitionSourceV1 source, IEnumerable <AbpWorkflowStepBody> stepBodys, WorkflowNode node) { if (source.Steps.Any(u => u.Id == node.Key)) { return; } var stepSource = new StepSourceV1(); stepSource.Id = node.Key; stepSource.Name = node.Key; AbpWorkflowStepBody stepbody = stepBodys.FirstOrDefault(u => u.Name == node.StepBody.Name); if (stepbody == null) { stepbody = new AbpWorkflowStepBody() { StepBodyType = typeof(NullStepBody) }; } stepSource.StepType = $"{stepbody.StepBodyType.FullName}, {stepbody.StepBodyType.Assembly.FullName}"; foreach (var input in stepbody.Inputs) { var value = node.StepBody.Inputs[input.Key].Value; if (!(value is IDictionary <string, object> || value is IDictionary <object, object>)) { value = $"\"{value}\""; } stepSource.Inputs.TryAdd(input.Key, value); } source.Steps.Add(stepSource); BuildBranching(allNodes, source, stepSource, stepBodys, node.NextNodes); }
protected virtual void BuildBranching(IEnumerable <WorkflowNode> allNodes, DefinitionSourceV1 source, StepSourceV1 stepSource, IEnumerable <AbpWorkflowStepBody> stepBodys, IEnumerable <WorkflowConditionNode> nodes) { foreach (var nextNode in nodes) { var node = allNodes.First(u => u.Key == nextNode.NodeId); stepSource.SelectNextStep[nextNode.NodeId] = "1==1"; if (nextNode.Conditions.Count() > 0) { List <string> exps = new List <string>(); foreach (var cond in nextNode.Conditions) { if (cond.Value is string && (!decimal.TryParse(cond.Value.ToString(), out decimal tempValue))) { if (cond.Operator != "==" && cond.Operator != "!=") { throw new AbpException($" if {cond.Field} is type of 'String', the Operator must be \"==\" or \"!=\""); } exps.Add($"data[\"{cond.Field}\"].ToString() {cond.Operator} \"{cond.Value}\""); continue; } exps.Add($"decimal.Parse(data[\"{cond.Field}\"].ToString()) {cond.Operator} {cond.Value}"); } stepSource.SelectNextStep[nextNode.NodeId] = string.Join(" && ", exps); } BuildWorkflow(allNodes, source, stepBodys, node); } }
/// <summary> /// 注册工作流 /// </summary> /// <param name="input"></param> /// <returns></returns> internal WorkflowDefinition LoadDefinition(PersistedWorkflowDefinition input) { if (_registry.IsRegistered(input.Id.ToString(), input.Version)) { throw new AbpException($"the workflow {input.Id} has ben definded!"); } var source = new DefinitionSourceV1(); source.Id = input.Id.ToString(); source.Version = input.Version; source.Description = input.Title; source.DataType = $"{typeof(Dictionary<string, object>).FullName}, {typeof(Dictionary<string, object>).Assembly.FullName}"; BuildWorkflow(input.Nodes, source, _stepBodys, input.Nodes.First(u => u.Key.ToLower().StartsWith("start"))); var json = source.ToJsonString(); Logger.DebugFormat("Workflow Json:{0}", json); var def = _definitionLoader.LoadDefinition(json, Deserializers.Json); return(def); }
private WorkflowDefinition Convert(DefinitionSourceV1 source) { var dataType = typeof(object); if (!string.IsNullOrEmpty(source.DataType)) { dataType = FindType(source.DataType); } var result = new WorkflowDefinition { Id = source.Id, Version = source.Version, Steps = ConvertSteps(source.Steps, dataType), DefaultErrorBehavior = source.DefaultErrorBehavior, DefaultErrorRetryInterval = source.DefaultErrorRetryInterval, Description = source.Description, DataType = dataType }; return(result); }