private void btnSubmit_Click(object sender, RoutedEventArgs e) { if (this.lstNodeInfos.SelectedItem != null) { var item = this.lstNodeInfos.SelectedItem as NSNodeInfo; if (item != null) { if (this.cmbSubmitType.SelectedIndex > -1 && ((this.cmbSubmitType.SelectedValue.ToString() == SubmitTypeEnum._BK.ToString()) ? this.cmbBacknodes.SelectedIndex > -1 : true)) { SubmitInfo_DTO submitInfo = new SubmitInfo_DTO(); submitInfo.NodeId = item.Id; submitInfo.Condition = this.txtSubmit.Text; submitInfo.ExpandDatas = new List <ExpandData>() { new ExpandData() }; submitInfo.SubmitResult = this.cmbSubmitType.SelectedValue.ToString() + ((this.cmbSubmitType.SelectedValue.ToString() == SubmitTypeEnum._BK.ToString()) ? ":" + (this.cmbBacknodes.SelectedValue as InstanceNode_DTO).Name : ""); this.txbMsg.Text = _client.SubmitWorkflow(submitInfo); AddNewChild(item.NodeName); } else { this.txbMsg.Text = "提交值出错"; } } } }
// public string SubmitWorkflow(SubmitInfo_DTO submitInfo) // { // if (submitInfo == null) // return "提交信息不能为空!"; // if (!string.IsNullOrEmpty(_iSubmitValidation.ValidateMsg(submitInfo.SubmitResult))) // return _iSubmitValidation.ValidateMsg(submitInfo.SubmitResult); // if (!Locker.Add(submitInfo.NodeId)) // return "请不要重复提交!"; // // 读取模板 // TemplateRepository tr = new TemplateRepository(Context); // InstanceInfoRepository iir = new InstanceInfoRepository(Context); // NodeInfoRepository nir = new NodeInfoRepository(Context); // HashSet<Guid> newActivities = new HashSet<Guid>(); // var node = nir.Get(submitInfo.NodeId); // if (node != null) // { // node.SubmitResult = submitInfo.SubmitResult; // var instance = iir.Get(node.InstanceId); // if (instance != null) // { // var templateInfo = tr.Get(instance.TemplateId); // // 解析 // XElement doc = XElement.Parse(templateInfo.TemplateText); // // 结束并发 // if (submitInfo.SubmitResult.StartsWith(SubmitTypeEnum._SP.ToString())) // { // // 停止并发 // TransRouting.StopParallel(doc, instance.TaskId, node, Context, node.NodeId); // } // // 驳回 // else if (submitInfo.SubmitResult.StartsWith(SubmitTypeEnum._BK.ToString())) // { // // 找到要驳回的点的名称 // string backNodeName = submitInfo.SubmitResult.Substring(4); // // 在模板上找到的对应的点 // XElement templateXml = XElement.Parse(templateInfo.TemplateText); // var nodeInfos = from c in templateXml.Elements("DesignerItems").Elements("DesignerItem") // where c.Element("Name").Value == backNodeName // select c; // if (nodeInfos.Count() == 0) // throw new Exception("驳回的点不存在!"); // // 结束该点下的所有点 //#warning 上一节点,下一个节点 // HashSet<Guid> stopAllNodes = new HashSet<Guid>(); // HashSet<Guid> hasAlreadyFinds = new HashSet<Guid>(); // TransRouting.FindAllNext(templateXml, nodeInfos.First(), node.TaskId, node.InstanceId, Context, stopAllNodes, hasAlreadyFinds); // stopAllNodes.Add(node.NodeId); // var stopNodeInfos = Context.NSNodeInfos.Where(p => p.InstanceId == node.InstanceId && p.RunState == RUNNING && stopAllNodes.Contains(p.NodeId)); // foreach (var nodeInfo in stopNodeInfos) // { // nodeInfo.RunState = RunStateEnum.end.ToString(); // } // TransRouting.Routing(doc, nodeInfos.First(), node, Context, newActivities); // } // else // { // /// 查找驳回点并生成新的节点 // var custsExc = from c in doc.Elements("Connections").First().Elements("Connection") // where c.Element("SourceID").Value == node.NodeId.ToString() // select c.Element("SinkID").Value; // // 结束当前的点 // node.RunState = RunStateEnum.end.ToString(); // nir.Modify(node); // foreach (var item in custsExc) // { // // 获取节点名称 // var nodeInfos = from c in doc.Elements("DesignerItems").Elements("DesignerItem") // where c.Element("ID").Value == item // select c; // foreach (var nodeInfo in nodeInfos) // { // TransRouting.Routing(doc, nodeInfo, node, Context, newActivities); // } // } // } // // 回到父流程节点 // var finisheds = TransRoutingHelper.InstanceFinished(newActivities, node.TaskId, node.InstanceId, Context); // // 新生成的节点 // foreach (var item in finisheds) // { // // 首先获取模板上面的ID // var parentNode = nir.Get(item); // if (parentNode != null) // { // var instnace = iir.Get(parentNode.InstanceId); // XElement parentDoc =XElement.Parse(tr.Get(instance.TemplateId).TemplateText); // // 获取节点名称 // var nodeInfos = from c in parentDoc.Elements("DesignerItems").Elements("DesignerItem") // where c.Element("ID").Value == parentNode.NodeId.ToString() // select c; // foreach (var nodeInfo in nodeInfos) // { // TransRouting.Routing(doc, nodeInfo, parentNode, Context, newActivities); // } // } // } // } // } // try // { // Context.SaveChanges(); // } // catch (DbEntityValidationException e) // { // StringBuilder sb = new StringBuilder(); // foreach (var eve in e.EntityValidationErrors) // { // sb.Append(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", // eve.Entry.Entity.GetType().Name, eve.Entry.State)); // foreach (var ve in eve.ValidationErrors) // { // sb.Append(string.Format("- Property: \"{0}\", Error: \"{1}\"", // ve.PropertyName, ve.ErrorMessage)); // } // } // return sb.Append("持久化失败!").ToString(); // } // catch (Exception ex) // { // return "提交失败"; // } // return "提交成功!"; // } public string SubmitWorkflow(SubmitInfo_DTO submitInfo) { StringBuilder result = new StringBuilder(); try { #region 验证 if (submitInfo == null) { return("提交信息不能为空!"); } if (!Locker.Add(submitInfo.NodeId)) { return("请不要重复提交!"); } #endregion (验证) #region 获取节点信息 TransInfoDto transInfoDto = new TransInfoDto(); transInfoDto.Persistence = DBFactory.GetPersistencePlugIn(); transInfoDto.Context = transInfoDto.Persistence.Context; transInfoDto.GroupCounter = submitInfo.ExpandDatas == null ? 0 : submitInfo.ExpandDatas.Count(); var activity = transInfoDto.Persistence.GetActivityByID(submitInfo.NodeId); if (activity == null) { return("要办理的节点已经不存在!"); } #endregion (获取节点信息) #region 获取模板信息 var instance = transInfoDto.Persistence.GetInsanceInfo(activity.InstanceId); var template = transInfoDto.Persistence.GetTemplateInfo(instance.TemplateId); #endregion (获取模板信息) #region 生成DTO信息 transInfoDto.TaskId = activity.TaskId; transInfoDto.InstanceId = activity.InstanceId; transInfoDto.InstanceNodeId = activity.NodeId; transInfoDto.TemplateXml = template.TemplateText; transInfoDto.ActivityType = ActivityTypeEnum.Process; transInfoDto.Condition = submitInfo.Condition; transInfoDto.SubmitType = EnumHelper.GetEnumByString <SubmitTypeEnum>(submitInfo.SubmitResult); #endregion (生成DTO信息) var currentActivity = XmlHelper.GetActivitiesByName(template.TemplateText, activity.NodeName).First(); transInfoDto.Activity = currentActivity; if (!string.IsNullOrEmpty(_iSubmitValidation.ValidateMsg(submitInfo.SubmitResult, transInfoDto))) { Locker.Remove(submitInfo.NodeId); return(_iSubmitValidation.ValidateMsg(submitInfo.SubmitResult, transInfoDto)); } #region 提交 new RoutingHost().EndRouing(transInfoDto); #endregion (提交) transInfoDto.Persistence.Context.SaveChanges(); } catch (WFRoutingException rex) { LogHelper.WriteLog(rex.Message + rex.ToString()); } catch (Exception ex) { LogHelper.WriteLog(ex.ToString()); } return(result.ToString()); }