public void Startup() { if (this.ready) { return; } this.ready = true; var eventArgs = new CompliantEventArgs(); this.TestCompliant?.Invoke(this, eventArgs); /*有注册兼容性检查的才检查*/ if (eventArgs.collections.Any()) { foreach (var tmpl in this.addlist) { var steps = tmpl.Steps.ToArray(); if (steps.Length <= 3) { continue; } /*从第三个步骤开始,因为第二个步骤的消息参数是从begin那里得来的*/ for (var i = 2; i < steps.Length - 1; i++) { foreach (var step in steps[i].Steps) { var type = TemplateWorkStep.Find(step); if (!eventArgs.collections.ContainsKey(type)) { throw new TemplateNotCompliantException("步骤{0}所需要上一步骤的消息结果没有注册,无法确定是否与当前步骤兼容", type.FullName); } var elements = steps[i - 1]; foreach (var ele in elements.Steps) { if (!eventArgs.collections.ContainsKey(TemplateWorkStep.Find(ele))) { throw new TemplateNotCompliantException("步骤{0}所需要上一步骤的消息结果没有注册,无法确定是否与当前步骤兼容", type.FullName); } var preAction = eventArgs.collections[TemplateWorkStep.Find(ele)]; var curAction = eventArgs.collections[type]; if (curAction.Value.Invoke(type, preAction.Key)) { break; } throw new TemplateNotCompliantException("步骤{0}所需要上一步骤的消息结果与当前步骤不兼容", type.FullName); } } } } } this.templateRepository.SaveAndChange(this.workflowengine.JsonSerializer, this.addlist.ToArray(), this.changeList.ToArray()); return; }
/// <summary> /// 从json内容中转换为模板对象 /// </summary> /// <param name="jsonSerializer"></param> /// <param name="json">The json.</param> /// <returns></returns> public static Template FromJson(IJsonSerializer jsonSerializer, string json) { if (string.IsNullOrEmpty(json)) { return(null); } var temp = jsonSerializer.Deserialize <TemplateJson>(json); if (temp == null) { return(null); } var template = new Template(temp.Name); foreach (var ele in temp.Collection) { template.Next(ele.Steps.Select(ta => TemplateWorkStep.Find(ta)).ToArray(), ele.Mode); } return(template.End()); }