static public Packet UpLoadFile(HttpContext context, int nCommand, ref string strError) { try { //System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch(); //w.Start(); string strProgressName = CommandTool.ReqString(context, "ProgressName"); UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectId"); UInt32 nPartID = CommandTool.ReqUint(context, "PartId"); UInt32 nWorkProgressID = CommandTool.ReqUint(context, "ProgressId"); UInt32 nPointCount = CommandTool.ReqUint(context, "PointCount"); UInt32 nInfoCount = CommandTool.ReqUint(context, "InfoCount"); string[] paramNames = new string[] { "PointID", "PointName", "Value" }; DataTable dtPoint = CommandTool.ReqDataTable(context, nPointCount, "point", "Value", paramNames); paramNames = new string[] { "PointID", "Nominal", "UpTol", "LowTol" }; DataTable dtInfo = CommandTool.ReqDataTable(context, nInfoCount, "info", "", paramNames); DM_ModelProject modelProject = getProjectInfo(nProjectID); DM_ModelPart modelPart = getPartInfo(nProjectID, nPartID); DM_WorkPlace modelWorkPlace = getWorkInfo(nProjectID, nPartID, nWorkProgressID); DM_ModelWorkshop modelWorkShop = getWorkShop(modelWorkPlace.WorkshopID); Packet recvPacket = writeMeasureFile(modelProject, modelPart, modelWorkPlace, modelWorkShop, dtPoint, dtInfo, strProgressName, ref strError); //w.Stop(); return(recvPacket); } catch (Exception ex) { strError = "CmdManager:UpLoadFile 错误" + ex.Message; return(null); } }
//查询文报告PDF文件 static public Packet GetReportPDF(HttpContext context, int nCommand, ref string strError) { try { string strFileUrl = CommandTool.ReqString(context, "PDFName"); PacketTable table = new PacketTable(); table.AddField("PDFName", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, strFileUrl); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery-GetClass 错误:" + ex.Message; return(null); } }
//查询图片所属分类 static public Packet GetClass(HttpContext context, int nCommand, ref string strError) { try { UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); UInt32 nPartID = CommandTool.ReqUint(context, "PartID"); UInt32 nImageID = CommandTool.ReqUint(context, "ImageID"); byte bIsFD = 0; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("ImageID", PacketTable.FieldType.TypeUint); table.AddField("IsFD", PacketTable.FieldType.TypeByte); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nPartID); table.SetValue(0, 2, nImageID); table.SetValue(0, 3, (byte)bIsFD); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable, 2); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery-GetClass 错误:" + ex.Message; return(null); } }
private void Awake() { if (instance) { DestroyImmediate(gameObject); } else { instance = this; } ConfirmConsoleUI(); }
public string GetProjectInfo(HttpContext context, ref string strError) { int nProjectIndex = CommandTool.ReqInt(context, "ProjectIndex", 0); try { Export handler = new Export(); DM_Factory factory = GetFactory(); if (factory == null) { return(handler.Error("无法获取工厂信息")); } List <ProjectInfo> arrProject = LoadProjectInfo(factory); if (arrProject == null || arrProject.Count == 0) { return(handler.Error("无法获取该工厂车型信息")); } if (nProjectIndex < 0) { nProjectIndex = -1; } if (nProjectIndex > arrProject.Count - 1) { nProjectIndex = arrProject.Count - 1; } int nPrevIndex = nProjectIndex > 0 ? nProjectIndex - 1 : -1; int nNextIndex = nProjectIndex < arrProject.Count - 1 ? nProjectIndex + 1 : -1; ProjectStatInfo statInfo = Stat(factory, arrProject[nProjectIndex]); statInfo.ProjectIndex = nProjectIndex; statInfo.PrevProjectIndex = nPrevIndex; statInfo.NextProjectIndex = nNextIndex; string strInfo = handler.Success(statInfo); return(strInfo); } catch (System.Exception ex) { Export handler = new Export(); return(handler.Error("错误:" + ex.Message)); } }
//统计报警 static public List <Packet> StatFileAlarm(HttpContext context, int nCommand, ref string strError) { try { List <Packet> arrPacket = new List <Packet>(); UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); int nLastNum = 30; string strPartID = CommandTool.ReqString(context, "PartID");; UInt32 nNominalID = 0; UInt32 nProgressID = 0; string strRuleIDs = ""; string[] nPartID = strPartID.Split(','); foreach (var PartID in nPartID) { PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("LastNum", PacketTable.FieldType.TypeInt); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("NominalID", PacketTable.FieldType.TypeUint); table.AddField("ProgressID", PacketTable.FieldType.TypeUint); table.AddField("RuleIDs", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nLastNum); table.SetValue(0, 2, UInt32.Parse(PartID)); table.SetValue(0, 3, nNominalID); table.SetValue(0, 4, nProgressID); table.SetValue(0, 5, strRuleIDs); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); arrPacket.Add(recvPacket); } return(arrPacket); } catch (Exception ex) { strError = "CmdQuery_GetPartArray:错误" + ex.Message; return(null); } }
static public Packet GetQueryUser(HttpContext context, int nCommand, ref string strError) { string strUserName = CommandTool.ReqString(context, "UserName"); string strPassword = CommandTool.ReqString(context, "Password"); ServerConnection conn = new ServerConnection(1);//连接主服务器 PacketTable table = new PacketTable(); table.AddField("UserNO", PacketTable.FieldType.TypeString); table.AddField("Password", PacketTable.FieldType.TypeString); table.MakeTable(1); table.SetValue(0, 0, strUserName); table.SetValue(0, 1, strPassword); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); }
//查询所属分类的下点的名义值、上下公差 static public Packet GetNominal(HttpContext context, int nCommand, ref string strError, string strClassID) { try { if (strClassID == "") { return(null); } UInt32 nClassID = Convert.ToUInt32(strClassID); UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); UInt32 nPartID = CommandTool.ReqUint(context, "PartID"); UInt32 nPointID = 0; byte bIsFD = 0; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("ClassID", PacketTable.FieldType.TypeUint); table.AddField("PointID", PacketTable.FieldType.TypeUint); table.AddField("IsFD", PacketTable.FieldType.TypeByte); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nPartID); table.SetValue(0, 2, nClassID); table.SetValue(0, 3, nPointID); table.SetValue(0, 4, (byte)bIsFD); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery-GetNominal:错误 " + ex.Message; return(null); } }
//统计分类合格率 static protected Packet StatGroupPassRate(byte nOption, HttpContext context, int nCommand, ref string strError) { try { UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); UInt32 nPartID = CommandTool.ReqUint(context, "PartID"); UInt32 nProgressID = CommandTool.ReqUint(context, "ProgressID"); UInt32 nClassID = 0; byte bIsFD = 0; int nLastNum = 10; PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.AddField("PartID", PacketTable.FieldType.TypeUint); table.AddField("ProgressID", PacketTable.FieldType.TypeUint); table.AddField("ClassID", PacketTable.FieldType.TypeUint); table.AddField("IsFD", PacketTable.FieldType.TypeByte); table.AddField("LastNum", PacketTable.FieldType.TypeInt); table.MakeTable(1); table.SetValue(0, 0, nProjectID); table.SetValue(0, 1, nPartID); table.SetValue(0, 2, nProgressID); table.SetValue(0, 3, nClassID); table.SetValue(0, 4, (byte)bIsFD); table.SetValue(0, 5, nLastNum); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable, nOption); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery_GetPartArray:错误" + ex.Message; return(null); } }
//查询零件 static public Packet GetPartArray(HttpContext context, int nCommand, ref string strError) { try { UInt32 nProjectID = CommandTool.ReqUint(context, "ProjectID"); PacketTable table = new PacketTable(); table.AddField("ProjectID", PacketTable.FieldType.TypeUint); table.MakeTable(1); table.SetValue(0, 0, nProjectID); PacketTable[] arrTable = new PacketTable[1]; arrTable[0] = table; //连接服务器 ServerConnection conn = new ServerConnection(); Packet recvPacket = conn.ExecuteCommand(nCommand, arrTable); return(recvPacket); } catch (Exception ex) { strError = "CmdQuery_GetPartArray:错误" + ex.Message; return(null); } }
public string SetSettingInfo(HttpContext context, ref string strError) { try { Export handler = new Export(); int nLastNum = CommandTool.ReqInt(context, "LastNum"); string strDateFrom = CommandTool.ReqString(context, "DateFrom"); string strDateTo = CommandTool.ReqString(context, "DateTo"); if (nLastNum == 0 && strDateFrom != "" && strDateTo != "") { string strSelectFactory = CommandTool.ReqString(context, "SelectFactory"); if (strSelectFactory == "") { return(handler.Error("选择的工厂为空")); } SystemSettingInfo settingInfo = new SystemSettingInfo() { LastNum = 0, DateFrom = strDateFrom, DateTo = strDateTo, SelectFactory = strSelectFactory }; SetInfo(settingInfo, ref strError); if (strError != "") { return(handler.Error(strError)); } else { return(handler.Success("设置成功")); } } else if (nLastNum != 0 && strDateFrom == "" && strDateTo == "") { string strSelectFactory = CommandTool.ReqString(context, "SelectFactory"); if (strSelectFactory == "") { return(handler.Error("选择的工厂为空")); } SystemSettingInfo settingInfo = new SystemSettingInfo() { LastNum = nLastNum, DateFrom = DateTime.Now.ToString("yyyy-MM-dd"), DateTo = DateTime.Now.ToString("yyyy-MM-dd"), SelectFactory = strSelectFactory }; SetInfo(settingInfo, ref strError); if (strError != "") { return(handler.Error(strError)); } else { return(handler.Success("设置成功")); } } else { return(handler.Error("设置失败")); } } catch (Exception ex) { Export handler = new Export(); return(handler.Error(ex.Message)); } }
private static int LogStep(ref Step[,] canvasMatrix, Step step, int curRow, int threadCol, int indentLevel, out string log, out string functions) { int nextRow = curRow; log = ""; functions = ""; string indentString = new string(' ', indentLevel * 4); if (step.Description.Length > 0) { log = "\r\n\r\n" + indentString + "/*" + step.Description + "*/";// + ((log.Length > 0) ? ("\r\n" + log) : ("")); } else { log = "";//"\r\n";// +log; } switch (step.ToolName) { case "NullTool": { log = ""; return(nextRow); } case "NoOpTool": { if (step.Enabled == false) { log += "\r\n" + indentString + "// " + "/*" + step.StepName.Replace("_x0020_", "_") + "*/"; } else { log += "\r\n" + indentString + "/*NOP: " + step.StepName.Replace("_x0020_", "_") + "*/"; } return(nextRow); } case "CaseTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string caselog; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); Step[,] caseMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, threadCol, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); CaseTool.CaseToTxt(ref caseMatrix, 0, indentLevel + ((eh.Length > 0) ? 1 : 0), height, width, out caselog, out functions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + caselog.Replace("\r\n", "\r\n// "); } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + caselog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + caselog; } } return(nextRow); } case "VariableTool": { string varlog, varfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); VariableTool.SetVariableToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out varlog, out varfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + varlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + varlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + varlog; } } if (varfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + varfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + varfunction; } } return(nextRow); } case "PaWTestTool": case "MethodTool": case "TestTool": case "Mouse": case "Keyboard": case "Inspect": { string testlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); TestTool.TestToTxt(step.StepXmlNode, indentLevel + ((eh.Length > 0) ? 1 : 0), out testlog, out dummy); if (step.ToolName == "TestTool" || step.ToolName == "PaWTestTool") { XmlNode path = step.StepXmlNode.SelectSingleNode(".//*[@Key='ResourceFullName']"); if (path != null) { string p; if (path.Attributes["Value"] != null) { p = path.Attributes["Value"].Value; } else { p = path.SelectSingleNode(".//*[@Key='Value']/@Value").Value; } log += "\r\n" + indentString + "/*" + "Path: " + p.Replace(".tsdrv", "") + " */"; } } if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + testlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + testlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + testlog; } } return(nextRow); } case "AttributeTool": { string alog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); AttributeTool.AttributeToTxt(step.StepXmlNode, indentLevel + ((eh.Length > 0) ? 1 : 0), out alog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + alog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + alog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + alog; } } return(nextRow); } case "CaptureImageTool": { string cilog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); CaptureImageTool.CaptureImageToTxt(step.StepXmlNode, indentLevel + ((eh.Length > 0) ? 1 : 0), out cilog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + cilog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + cilog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + cilog; } } return(nextRow); } case "CriteriaTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); CriteriaTool.CriteriaToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "ScripterTool": case "PaWScripterTool": { string slog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); ScripterTool.ScripterToTxt(step.StepXmlNode, indentLevel + ((eh.Length > 0) ? 1 : 0), out slog, out dummy); XmlNode path = step.StepXmlNode.SelectSingleNode(".//*[@Key='ResourceFullName']"); if (path != null) { string p; if (path.Attributes["Value"] != null) { p = path.Attributes["Value"].Value; } else { p = path.SelectSingleNode(".//*[@Key='Value']/@Value").Value; } log += "\r\n" + indentString + "/* " + "Path: " + p.Replace(".tsscript", "") + " */"; } if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + slog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + slog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + slog; } } return(nextRow); } case "CommandTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); CommandTool.CommandToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "TerminalCommandTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); TerminalCommandTool.CommandToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "WriteTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); WriteTool.WriteToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "ReadTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); ReadTool.ReadToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "MessageTool": { string clog, cfunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); MessageTool.MessageToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out clog, out cfunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + clog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + clog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + clog; } } if (cfunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + cfunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + cfunction; } } return(nextRow); } case "TransformationTool": { string tlog, tfunctions; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); TransformTool.TransformToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out tlog, out tfunctions); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + tlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + tlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + tlog; } } if (tfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + tfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + tfunctions; } } return(nextRow); } case "SetSessionTool": { string sessionlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); SetSessionTool.SessionToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out sessionlog, out dummy); log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + sessionlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + sessionlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + sessionlog; } } return(nextRow); } case "DelayTool": { string dlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); DelayTool.DelayToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } return(nextRow); } case "SetEventTool": { string dlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); SetEventTool.SetEventToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } return(nextRow); } case "WaitForEventTool": { string dlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); WaitForEventTool.WaitForEventToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dummy); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } return(nextRow); } case "PassFailTool": { string dlog, dfunc; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); PassFailTool.PassFailToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dfunc); string tooltype = step.StepXmlNode.SelectSingleNode(".//*[@Key='NotificationType']/@Value").Value; string toolname = "PassFailTool"; switch (tooltype) { case "0": toolname = "Pass"; break; case "1": toolname = "Fail"; break; case "2": toolname = "Text To Report"; break; default: break; } log += "\r\n" + indentString + "/*" + toolname + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } if (dfunc.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + dfunc.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + dfunc; } } return(nextRow); } case "ErrorTool": { string dlog, dummy; ErrorTool.ErrorToTxt(step, indentLevel, out dlog, out dummy); log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "// throw" + step.StepName.Replace("_x0020_", "_") + dlog; } else { log += "\r\n" + indentString + "throw " + step.StepName.Replace("_x0020_", "_") + dlog; } return(nextRow); } case "EndSessionTool": { string dlog, dummy; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); EndSessionTool.EndSessionToTxt(step, indentLevel + ((eh.Length > 0) ? 1 : 0), out dlog, out dummy); log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + dlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } } return(nextRow); } case "EndTool": { string dlog, dummy; EndTool.EndToTxt(step, indentLevel, out dlog, out dummy); log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + dlog; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + dlog; } return(nextRow); } case "CodeTool": { string dummy, codefunction; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); CodeTool.CodeToTxt(step, indentLevel + ((eh.Length > 0)?1:0), out dummy, out codefunction); if (step.Enabled == false) { log += "\r\n" + indentString + "//" + step.StepName.Replace("_x0020_", "_") + "()"; } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + step.StepName.Replace("_x0020_", "_") + "()"; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + step.StepName.Replace("_x0020_", "_") + "()"; } } if (codefunction.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + codefunction.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + codefunction; } } return(nextRow); } case "LoopTool": case "ParaLoopTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string looplog, loopfunctions; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); Step[,] loopMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, threadCol, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); LoopTool.LoopToTxt(ref loopMatrix, 0, indentLevel + ((eh.Length > 0) ? 1 : 0), height, width, out looplog, out loopfunctions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + looplog.Replace("\r\n", "\r\n// "); } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + looplog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + looplog; } } if (loopfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + loopfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + loopfunctions; } } return(nextRow); } case "WhileTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string wlog, wfunctions; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); Step[,] whileMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, threadCol, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); WhileTool.WhileToTxt(ref whileMatrix, 0, indentLevel + ((eh.Length > 0) ? 1 : 0), height, width, out wlog, out wfunctions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + wlog.Replace("\r\n", "\r\n// "); } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + wlog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + wlog; } } if (wfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + wfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + wfunctions; } } return(nextRow); } case "LockTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string llog, lfunctions; string eh = ErrorHandlingToTxt.Parse(step.StepXmlNode, indentLevel); Step[,] lockMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, threadCol, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); LockTool.LockToTxt(ref lockMatrix, 0, indentLevel + ((eh.Length > 0) ? 1 : 0), height, width, out llog, out lfunctions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + llog.Replace("\r\n", "\r\n// "); } else { if (eh.Length > 0) { log += "\r\n" + indentString + "try" + "\r\n" + indentString + "{"; log += "\r\n" + indentString + " " + llog; log += "\r\n" + indentString + "}" + "\r\n" + eh; } else { log += "\r\n" + indentString + llog; } } if (lfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + lfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + lfunctions; } } return(nextRow); } case "ParallelTool": { int width = step.StepWidth; int height = step.StepHeight; log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; string plog, pfunctions; Step[,] pMatrix = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, curRow, 0, Math.Min(curRow + height - 1, canvasMatrix.GetLength(0) - 1), canvasMatrix.GetLength(1) - 1); ParallelTool.ParallelToTxt(ref pMatrix, threadCol, indentLevel, height, width, out plog, out pfunctions); nextRow = curRow + height; if (step.Enabled == false) { log += "\r\n" + indentString + "// " + plog.Replace("\r\n", "\r\n// "); } else { log += "\r\n" + indentString + plog; } if (pfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + pfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + pfunctions; } } return(nextRow); } case "GroupTool": case "PaWDllTool": case "DllTool": case "CommandShellTool": case "SequenceTool": case "TerminalTool": case "WebServiceTool": case "NetworkClientTool": { string glog, gfunctions; if (step.ToolName == "DllTool" || step.ToolName == "PaWDllTool" || step.ToolName == "WebServiceTool") { XmlNode path = step.StepXmlNode.SelectSingleNode(".//*[@Key='ResourceFullName']"); if (path != null) { string p; if (path.Attributes["Value"] != null) { p = path.Attributes["Value"].Value; } else { p = path.SelectSingleNode(".//*[@Key='Value']/@Value").Value; } log += "\r\n" + indentString + "/*" + "Path: " + p.Replace(".tsdll", "") + " */"; } log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; } else if (step.ToolName == "SequenceTool") { XmlNode path = step.StepXmlNode.SelectSingleNode(".//*[@Key='LibraryFullName']"); if (path != null) { string p; if (path.Attributes["Value"] != null) { p = path.Attributes["Value"].Value; } else { p = path.SelectSingleNode(".//*[@Key='Value']/@Value").Value; } log += "\r\n" + indentString + "/*" + "Path: " + p.Replace(".tslib", "") + " */"; } log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; } else { log += "\r\n" + indentString + "/*" + step.ToolName + ": " + step.StepName + "*/"; } XmlNode groupSteps = step.StepXmlNode.SelectSingleNode(".//List[@Key='Steps']"); XmlNode eh = step.StepXmlNode.SelectSingleNode(".//ErrorHandlingBehavior"); CanvasAnalyzer.StepsListToTxt(groupSteps.ChildNodes, true, indentLevel, eh, out glog, out gfunctions); if (step.Enabled == false) { log += "\r\n" + indentString + "// " + glog.Replace("\r\n", "\r\n// "); } else { log += "\r\n" + indentString + glog; } if (gfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + gfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + gfunctions; } } return(nextRow); } case "AnalyzableCompositeTool": { string aclog, acfunctions; XmlNodeList acTools = step.StepXmlNode.SelectNodes(".//Array[@Key='ChildTools']/*"); foreach (XmlNode tool in acTools) { Step curstep = new Step(tool); curstep.Enabled = step.Enabled; LogStep(ref canvasMatrix, curstep, curRow, threadCol, indentLevel, out aclog, out acfunctions); if (step.Enabled == false) { log += "\r\n" + indentString + "// " + aclog.Replace("\r\n", "\r\n// "); } else { log += "\r\n" + indentString + aclog; } if (acfunctions.Length > 0) { if (step.Enabled == false) { functions += "\r\n" + "// " + acfunctions.Replace("\r\n", "\r\n// "); } else { functions += "\r\n" + acfunctions; } } } return(nextRow + acTools.Count - 1); } } if (step.Enabled == false) { log += "\r\n" + indentString + "//"; } else { log += "\r\n" + indentString; } log += step.StepName.Replace("_x0020_", "_") + " // (" + step.ToolName + ")"; return(nextRow); }
private static void CreateDemo(string path, string content, int bufferSize) { var floder = path.Substring(0, path.LastIndexOf("\\")); if (!Directory.Exists(path)) { var directoryInfo = Directory.CreateDirectory(path); Console.WriteLine(directoryInfo); } //1.创建 //Creates or overwrites the specified file. //public static FileStream Create(string path); //public static FileStream Create(string path, int bufferSize); //bufferSize //The number of bytes buffered for reads and writes to the file. //为读和写缓存的字节数 //public static FileStream Create(string path, int bufferSize, FileOptions options); //不进行任何操作时效果相同 //emm... 通过创建缓存区 可以增加读写的效率 CommandTool.CountTime((() => { using (FileStream fileStream = File.Create(path)) { var bytes = Encoding.UTF8.GetBytes(content); fileStream.Write(bytes, 0, bytes.Length); } return("public static FileStream Create(string path);"); })); CommandTool.CountTime((() => { using (FileStream fileStream = File.Create(path + "-1", bufferSize)) { var bytes = Encoding.UTF8.GetBytes(content); fileStream.Write(bytes, 0, bytes.Length); } return("public static FileStream Create(string path, int bufferSize);"); })); // Asynchronous = 1073741824, // 0x40000000 异步锁 // DeleteOnClose = 67108864, // 0x04000000 在关闭时删除 // Encrypted = 16384, // 0x00004000 存在拒绝访问 // None = 0, // RandomAccess = 268435456, // 0x10000000 // SequentialScan = 134217728, // 0x08000000 // WriteThrough = -2147483648, // -0x80000000 不计入缓存,直接操作 CommandTool.CountTime((() => { using (FileStream fileStream = File.Create(path + "-2", bufferSize, FileOptions.WriteThrough)) { var bytes = Encoding.UTF8.GetBytes(content); fileStream.Write(bytes, 0, bytes.Length); } return("public static FileStream Create(string path, int bufferSize, FileOptions options);"); })); // public static StreamWriter CreateText(string path); //Creates or opens a file for writing UTF-8 encoded text. If the file already exists, its contents are overwritten. CommandTool.CountTime((() => { using (StreamWriter fw = File.CreateText(path + "---")) { fw.Write(content); } return("public static StreamWriter CreateText(string path);"); })); }