public JsonResult Save(string SimulationListID, string SimulationListCode, string WorkflowCode, string SimulationIDS) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(false, ""); InstanceSimulationList SimulationList = null; OThinker.H3.WorkflowTemplate.WorkflowClause Clause = null; Clause = this.Engine.WorkflowManager.GetClause(WorkflowCode); if (string.IsNullOrEmpty(SimulationListID)) { SimulationList = new InstanceSimulationList() { WorkflowCode = WorkflowCode }; } else { SimulationList = this.Engine.SimulationManager.GetSimulationList(SimulationListID); } if (SimulationList == null) { //编辑的模拟不存在 result.Message = "Simulation.SimulationDetail_Mssg4"; return Json(result); } //编码必须以字母开始 //System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[A-Za-z][A-Za-z0-9_]*$"); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z\\u4e00-\\u9fa5][0-9a-zA-Z\\u4e00-\\u9fa5_]*$"); if (!regex.Match(SimulationListCode).Success) { result.Message = "Simulation.ObjectSchemaProperty_Mssg4"; return Json(result); } SimulationList.Simulations = (SimulationIDS + string.Empty).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); SimulationList.SimulationListCode = SimulationListCode; SimulationList.WorkflowCode = WorkflowCode; if (string.IsNullOrEmpty(SimulationList.SimulationListCode)) { //编辑的模拟不存在 // WriteResponse(false, this.PortalResource.GetString("SimulationDetail_Mssg3")); result.Message = "Simulation.SimulationDetail_Mssg3"; return Json(result); } if (SimulationList.Simulations == null || SimulationList.Simulations.Length < 1) { //编辑的模拟不存在 result.Message = "Simulation.SimulationDetail_Mssg5"; return Json(result); } if (!string.IsNullOrEmpty(SimulationListID)) { result.Success = this.Engine.SimulationManager.UpdateSimulationList(SimulationList); } else { result.Success = this.Engine.SimulationManager.AddSimulationList(SimulationList); } if (result.Success) { result.Message = "msgGlobalString.SaveSucced"; } else { result.Message = "msgGlobalString.SaveFailed"; } return Json(result); })); }
object LoadInstances(string SimulationListID) { ActionResult results = new ActionResult(false, ""); if (string.IsNullOrEmpty(SimulationListID)) { return(null); } InstanceSimulationList SimulationLists = this.Engine.SimulationManager.GetSimulationList(SimulationListID); if (SimulationLists == null || SimulationLists.Simulations == null) { return(null); } Dictionary <string, string[]> ExistItems = new Dictionary <string, string[]>(); Dictionary <string, bool> ActivityIgnore = new Dictionary <string, bool>(); List <object> InstanceObjs = new List <object>(); InstanceSimulation[] simulations = this.Engine.SimulationManager.GetSimulations(SimulationLists.Simulations); Dictionary <string, string> DicUnits = new Dictionary <string, string>(); Dictionary <string, string> lstInstanceIds = new Dictionary <string, string>(); Dictionary <string, string> lstState = new Dictionary <string, string>(); List <string> lstUserIDs = new List <string>(); Dictionary <string, int> result = new Dictionary <string, int>(); if (simulations != null || simulations.Length > 0) { foreach (InstanceSimulation Simulation in simulations) { if (Simulation.NextBatchNo < 2) { results.Message = "Simulation.SimulationReport_Mssg"; return(results); } if (Simulation.DataItems != null && Simulation.DataItems.Length > 0) { foreach (InstanceSimulationDataItem item in Simulation.DataItems) { if (!ExistItems.ContainsKey(Simulation.ObjectID + item.ItemName)) { ExistItems.Add(Simulation.ObjectID + item.ItemName, item.ItemValues); } if (!ActivityIgnore.ContainsKey(Simulation.ObjectID + item.ItemName)) { ActivityIgnore.Add(Simulation.ObjectID + item.ItemName, item.Ignore); } } } int SimulationTokenID = 0; if (SimulationTokenID <= InstanceSimulationLog.InitialBatchNo || SimulationTokenID >= Simulation.NextBatchNo) { SimulationTokenID = Simulation.NextBatchNo - 1; } DataTable InstanceTable = this.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable( " SELECT " + "B." + InstanceContext.C_ObjectID + ",B." + InstanceContext.PropertyName_Originator + ",B." + InstanceContext.PropertyName_InstanceName + ",B." + InstanceContext.PropertyName_State + " FROM " + InstanceSimulationLog.TableName + " A JOIN " + InstanceContext.TableName + " B " + " ON A." + InstanceSimulationLog.PropertyName_InstanceId + "=B." + InstanceContext.C_ObjectID + " WHERE A." + InstanceSimulationLog.PropertyName_SimulationID + "='" + Simulation.ObjectID + "'" + " AND A." + InstanceSimulationLog.PropertyName_BatchNo + "=" + SimulationTokenID + " "); if (InstanceTable != null && InstanceTable.Rows.Count > 0) { //一次获取所有用户 foreach (DataRow row in InstanceTable.Rows) { lstUserIDs.Add(row[InstanceContext.PropertyName_Originator] + string.Empty); if (!lstInstanceIds.ContainsKey(Simulation.ObjectID)) { lstInstanceIds.Add(Simulation.ObjectID, row[InstanceContext.C_ObjectID] + string.Empty); } if (!lstState.ContainsKey(Simulation.ObjectID)) { lstState.Add(Simulation.ObjectID, row[InstanceContext.PropertyName_State] + string.Empty); } } OThinker.Organization.Unit[] Units = this.Engine.Organization.GetUnits(lstUserIDs.ToArray()).ToArray(); if (Units != null) { foreach (OThinker.Organization.Unit u in Units) { if (!DicUnits.ContainsKey(u.ObjectID)) { DicUnits.Add(u.ObjectID, u.Name); } } } } } foreach (InstanceSimulation Simulation in simulations) { List <string> message = new List <string>(); int workItemCount = 0; int failedCount = 0; int IgnoreCount = 0; bool exception = false; if (lstInstanceIds != null && lstInstanceIds.Count > 0) { string InstanceId = lstInstanceIds[Simulation.ObjectID]; InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(InstanceId); if (!context.Exceptional) { string[] workitemIds = this.Engine.Query.QueryWorkItems(InstanceId, -1, OThinker.H3.WorkItem.WorkItemType.Unspecified, OThinker.H3.WorkItem.WorkItemState.Finished, OThinker.Data.BoolMatchValue.Unspecified); if (workitemIds != null || workitemIds.Length > 0) { foreach (string workitemId in workitemIds) { OThinker.H3.WorkItem.WorkItem workItem = this.Engine.WorkItemManager.GetWorkItem(workitemId); if (ActivityIgnore.ContainsKey(Simulation.ObjectID + workItem.ActivityCode)) { if (!ActivityIgnore[Simulation.ObjectID + workItem.ActivityCode]) { if (ExistItems.ContainsKey(Simulation.ObjectID + workItem.ActivityCode)) { if (ExistItems[Simulation.ObjectID + workItem.ActivityCode] == null || ExistItems[Simulation.ObjectID + workItem.ActivityCode].Length == 0) { IgnoreCount++; } else if (!ExistItems[Simulation.ObjectID + workItem.ActivityCode].Contains(workItem.Participant)) { failedCount++; } } } else { IgnoreCount++; } } } workItemCount = workitemIds.Length - IgnoreCount; } } else { exception = true; if (!result.ContainsKey(Simulation.ObjectID)) { result.Add(Simulation.ObjectID, 1); } } if (failedCount > 0 && !result.ContainsKey(Simulation.ObjectID)) { result.Add(Simulation.ObjectID, 1); } double Percent = 0; if (workItemCount > 0) { Percent = (workItemCount - failedCount) * 100 / workItemCount; } InstanceObjs.Add(new { ObjectID = InstanceId, Originator = DicUnits.ContainsKey(Simulation.Originators[0]) ? DicUnits[Simulation.Originators[0]] : "", InstanceName = Simulation.InstanceName, State = (exception ? "Simulation.InstanceGrid_Exceptional" : "InstanceState.InstanceState_" + Enum.Parse(typeof(InstanceState), lstState[Simulation.ObjectID] + string.Empty).ToString()), Url = this.GetInstanceUrl(InstanceId, "", DateTime.Now.ToString("yyyyMMddHHmmss")), workItemCount = workItemCount + IgnoreCount, SuccessCount = workItemCount - failedCount, failedCount = failedCount, IgnoreCount = IgnoreCount, Percent = Percent + "%", SimulationID = Simulation.ObjectID }); } } } List <object> lstSimulationObjs = new List <object>(); int failed = 0; foreach (string simulationId in SimulationLists.Simulations) { if (result.ContainsKey(simulationId)) { failed += result[simulationId]; } } int total = SimulationLists.Simulations.Length; int SuccessNum = SimulationLists.Simulations.Length - failed; double percent = SuccessNum * 100 / total; var SimulationListCode = SimulationLists.SimulationListCode; var RunTime = DateTime.MinValue.ToLongDateString(); if (SimulationLists.LastRunTime > DateTime.Parse("1753-1-1") && SimulationLists.LastRunTime < DateTime.MaxValue) { RunTime = SimulationLists.LastRunTime.ToLongDateString(); } var SimulationNum = total + string.Empty; var FailedNum = failed + string.Empty; var PercentString = percent + "%"; var gridData = CreateLigerUIGridData(InstanceObjs.ToArray()); results.Success = true; results.Extend = new{ GridData = gridData, SimulationListCode = SimulationListCode, RunTime = RunTime, SimulationNum = SimulationNum, FailedNum = FailedNum, SuccessNum = SuccessNum.ToString(), Percent = PercentString }; return(results); }
public JsonResult Load(string SimulationListID, string WorkflowCode) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(false, ""); InstanceSimulationList SimulationList = null; OThinker.H3.WorkflowTemplate.WorkflowClause Clause = null; Clause = this.Engine.WorkflowManager.GetClause(WorkflowCode); SimulationList = this.Engine.SimulationManager.GetSimulationList(SimulationListID); var WorkflowName = ""; var SimulationListCode = ""; string simulation = string.Empty; //当前测试集的测试用例ID var Simulations = new List <object>(); //当前流程测试用例集合 //ID非空为编辑模式 if (!string.IsNullOrEmpty(SimulationListID)) { if (SimulationList != null) { if (Clause != null) { WorkflowName = Clause.WorkflowName + "[" + WorkflowCode + "]"; } SimulationListCode = SimulationList.SimulationListCode; if (SimulationList.Simulations != null && SimulationList.Simulations.Length > 0) { foreach (string id in SimulationList.Simulations) { simulation += id + ";"; } simulation = simulation.TrimEnd(';'); } // ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "simulation", "var simulation=\"" + simulation + "\";", true); } else { result.Message = "Simulation.SimulationDetail_Mssg1"; //打开失败 return Json(result, JsonRequestBehavior.AllowGet); } } //ID为空,为新增模式 else { WorkflowName = this.Engine.WorkflowManager.GetClauseDisplayName(WorkflowCode); } InstanceSimulation[] SimulationsObject = this.Engine.SimulationManager.GetSimulationByWorkflow(WorkflowCode); if (SimulationsObject != null && SimulationsObject.Length > 0) { List <object> lstSimulations = new List <object>(); foreach (InstanceSimulation sim in SimulationsObject) { lstSimulations.Add(new { ObjectID = sim.ObjectID, InstanceName = sim.InstanceName }); } Simulations = lstSimulations; } var returnObject = new { WorkflowName = WorkflowName, SimulationListCode = SimulationListCode, SimulationIDS = simulation, Simulations = CreateLigerUIGridData(Simulations.ToArray()) }; result.Success = true; result.Message = ""; result.Extend = returnObject; return Json(result, JsonRequestBehavior.AllowGet); })); }