public string CheckUnique(TabFile.Column column) { if (column.head.type != TypeDef.IntType) { return("检查命令不支持数据类型为" + column.head.type); } List <int> existList = new List <int>(); OnForeachDelegate checkAction = (dataIndex, data) => { int intData = (int)data; int index = existList.IndexOf(intData); if (index == -1) { existList.Add(intData); } else { return(column.head.name + "=" + intData); } return(null); }; return(ForeachColumnData(column, checkAction)); }
public string CheckIDExistAndCanBeZero(TabFile.Column column, string tabFileName, string columnName) { if (column.head.type != TypeDef.IntType && column.head.type != TypeDef.ListIntType) { return("检查命令不支持数据类型为" + column.head.type); } OnForeachDelegate checkAction = (dataIndex, data) => { string strData = data.ToString(); List <TabFile.Column> checkColumns = TabFileDataChecker.Instance.GetTabFileColumn(tabFileName, columnName); if (checkColumns == null || checkColumns.Count == 0) { return(tabFileName + "表不存在列" + columnName + ",无法进行检查"); } for (int j = 0; j < checkColumns.Count; j++) { TabFile.Column checkColumn = checkColumns[j]; int index = checkColumn.data.IndexOf(strData); if (index == -1 && (int)data != 0) { return(column.head.name + "=" + strData + "不存在" + tabFileName + "表" + columnName + "列"); } } return(null); }; return(ForeachColumnData(column, checkAction)); }
private string ForeachColumnData(TabFile.Column column, OnForeachDelegate callback) { string ret = null; switch (column.head.type) { case TypeDef.IntType: for (int i = 0; i < column.data.Count; i++) { int tempIntData = 0; int.TryParse(column.data[i], out tempIntData); ret = callback.Invoke(i, tempIntData); if (!string.IsNullOrEmpty(ret)) { return(ret); } } break; case TypeDef.StringType: for (int i = 0; i < column.data.Count; i++) { ret = callback.Invoke(i, column.data[i]); if (!string.IsNullOrEmpty(ret)) { return(ret); } } break; case TypeDef.ListIntType: for (int i = 0; i < column.data.Count; i++) { string columnData = column.data[i]; columnData = columnData.TrimStart('"'); columnData = columnData.TrimEnd('"'); string[] columnDataList = columnData.Split(','); for (int j = 0; j < columnDataList.Length; j++) { int tempIntData = 0; int.TryParse(columnDataList[j], out tempIntData); ret = callback.Invoke(i, tempIntData); if (!string.IsNullOrEmpty(ret)) { return(ret); } } } break; } return(null); }
public List <TabFile.Column> GetTabFileColumn(string name, string key) { TabFile tabFile = GetTabFile(name); if (tabFile == null) { return(null); } string columnParent = null; string columnName = null; int index = key.IndexOf('.'); if (index == -1) { columnParent = null; columnName = key; } else { columnParent = key.Substring(0, index); columnName = key.Substring(index + 1); } List <TabFile.Column> ret = new List <TabFile.Column>(); for (int i = 0; i < tabFile.columns.Count; i++) { TabFile.Column column = tabFile.columns[i]; // if (column.head.parent == columnParent && column.head.name == columnName) if (column.head.name == columnName) { ret.Add(column); } } if (ret == null || ret.Count == 0) { System.Console.WriteLine(key + "标识不存在,请检查checklist_" + name); } return(ret); }
public string CheckIDExistAndCanBeZeroWithRelative(TabFile.Column column, string relative, string columnName) { if (column.head.type != TypeDef.IntType) { return("检查命令不支持数据类型为" + column.head.type); } string[] relativeList = relative.Split('='); OnForeachDelegate checkAction = (dataIndex, data) => { if ((int)data == 0) { return(null); } string relativeTabFileName = FindRelativeColumn(dataIndex, relativeList); if (relativeTabFileName == null) { return("根据数据:" + data + ";无法找到关联列:" + relative); } List <TabFile.Column> checkColumns = TabFileDataChecker.Instance.GetTabFileColumn(relativeTabFileName, columnName); if (checkColumns.Count != 1) { return("根据数据:" + data + ";无法找到关联列:" + relative); } TabFile.Column relativeColumn = checkColumns[0]; for (int j = 0; j < relativeColumn.data.Count; j++) { int tempIntData = 0; int.TryParse(relativeColumn.data[j], out tempIntData); if (tempIntData == (int)data) { return(null); } } return("无法在关联列:" + relative + "找到数据:" + data); }; return(ForeachColumnData(column, checkAction)); }
public void StartCheck(string filePath) { FileInfo fileInfo = new FileInfo(filePath); int index = fileInfo.Name.IndexOf('_') + 1; if (index == -1) { System.Console.WriteLine("检查配置命名错误,应为checklist_目标表名:" + fileInfo.Name); return; } string curTargetFileName = fileInfo.Name.Substring(index).Replace(".txt", "").ToLower(); System.Console.WriteLine("检查完成--->" + curTargetFileName); FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader sr = new StreamReader(fs); string content = sr.ReadToEnd(); sr.Close(); fs.Close(); string[] lines = content.Split('\n'); for (int i = 0; i < lines.Length; i++) { string line = lines[i]; line = line.Trim('\r'); string[] commandDesc = line.Split('\t'); if (commandDesc.Length < 3) { continue; } string methodName = commandDesc[2]; Type t = checkList.GetType(); MethodInfo methodInfo = t.GetMethod(methodName); if (methodInfo == null) { System.Console.WriteLine("检查配置命令不存在:" + methodName); return; } string key = commandDesc[1]; List <TabFile.Column> columns = GetTabFileColumn(curTargetFileName, key); if (columns == null || columns.Count == 0) { return; } string ret = null; for (int j = 0; j < columns.Count; j++) { TabFile.Column column = columns[j]; List <object> paramList = new List <object>(); paramList.Add(column); for (int k = 3; k < commandDesc.Length; k++) { string param = commandDesc[k]; if (string.IsNullOrEmpty(param)) { break; } paramList.Add(param); } ret = methodInfo.Invoke(checkList, paramList.ToArray()) as string; if (string.IsNullOrEmpty(ret)) { continue; } System.Console.WriteLine(line + "检查不通过!"); System.Console.WriteLine(ret); break; } } }
public bool UnpackFromTabFile(string fileName, TabFile tabfile) { curTabFile = tabfile; this.fileName = fileName.Substring(0, 1).ToUpper() + fileName.Substring(1); CSStruct curStruct = null; CSListStruct curListSturct = null; for (int i = 0; i < tabfile.columns.Count; i++) { TabFile.Column column = tabfile.columns[i]; if (!column.head.clientExport) { continue; } switch (column.head.type) { case TypeDef.IntType: case TypeDef.BoolType: case TypeDef.FloatType: case TypeDef.StringType: case TypeDef.ListIntType: case TypeDef.ListFloatType: case TypeDef.ListStringType: case TypeDef.LuaTableType: CSVaribles varible = new CSVaribles(); varible.type = column.head.type; varible.name = column.head.name; if (curStruct != null) { if (curStruct.NotContains(varible)) { curStruct.varibles.Add(varible); } } else { varibles.Add(varible); } break; case TypeDef.StructType: if (!string.IsNullOrEmpty(column.head.name)) { if (curStruct != null) { System.Console.WriteLine("struct异常,列:" + (i + 1)); return(false); } if (curListSturct == null) { curStruct = new CSStruct(); curStruct.name = column.head.name; structs.Add(curStruct); } else { if (curListSturct.csStruct == null) { curStruct = new CSStruct(); curStruct.name = curListSturct.name; curListSturct.csStruct = curStruct; } curStruct = curListSturct.csStruct; curListSturct.count++; } } else { if (curStruct == null) { System.Console.WriteLine("struct异常,列:" + (i + 1)); return(false); } if (curListSturct == null) { varible = new CSVaribles(); varible.type = column.head.type; varible.csStruct = curStruct; varibles.Add(varible); } curStruct = null; } break; case TypeDef.ListType: if (!string.IsNullOrEmpty(column.head.name)) { if (curListSturct != null) { System.Console.WriteLine("list异常,列:" + (i + 1)); return(false); } curListSturct = new CSListStruct(); curListSturct.name = column.head.name; structLists.Add(curListSturct); } else { if (curListSturct == null) { System.Console.WriteLine("struct异常,列:" + (i + 1)); return(false); } varible = new CSVaribles(); varible.type = column.head.type; varible.csListStruct = curListSturct; varibles.Add(varible); curListSturct = null; } break; default: System.Console.WriteLine(i + ":不支持的数据类型:" + column.head.type + "," + column.head.name); break; } } return(true); }
public string CheckRange(TabFile.Column column, string min, string max) { if (column.head.type != TypeDef.IntType && column.head.type != TypeDef.FloatType && column.head.type != TypeDef.DoubleType) { return("检查命令不支持数据类型为" + column.head.type); } object objMinRet = null; object objMaxRet = null; switch (column.head.type) { case TypeDef.IntType: int intMin = 0; int.TryParse(min, out intMin); objMinRet = intMin; int intMax = 0; int.TryParse(max, out intMax); objMaxRet = intMax; break; case TypeDef.FloatType: float floatMin = 0; float.TryParse(min, out floatMin); objMinRet = floatMin; float floatMax = 0; float.TryParse(max, out floatMax); objMaxRet = floatMax; break; case TypeDef.DoubleType: double doubleMin = 0; double.TryParse(min, out doubleMin); objMinRet = doubleMin; double doubleMax = 0; double.TryParse(max, out doubleMax); objMaxRet = doubleMax; break; } OnForeachDelegate checkAction = (dataIndex, data) => { switch (column.head.type) { case TypeDef.IntType: if ((int)data >= (int)objMinRet && (int)data <= (int)objMaxRet) { return(null); } break; case TypeDef.FloatType: if ((int)data >= (int)objMinRet && (int)data <= (int)objMaxRet) { return(null); } break; case TypeDef.DoubleType: if ((int)data >= (int)objMinRet && (int)data <= (int)objMaxRet) { return(null); } break; } return(column.head.name + "=" + data); }; return(ForeachColumnData(column, checkAction)); }
public bool UnpackFromTabFile(TabFile tabfile, bool forceAll = false) { List <LuaStruct> structs = new List <LuaStruct>(); for (int i = 0; i < tabfile.columns[0].data.Count; i++) { StringBuilder line = new StringBuilder(); lines.Add(line); LuaStruct structTmp = new LuaStruct(); structs.Add(structTmp); } bool isInList = false; for (int i = 0; i < tabfile.columns.Count; i++) { TabFile.Column column = tabfile.columns[i]; for (int j = 0; j < column.data.Count; j++) { StringBuilder line = lines[j]; LuaStruct structTmp = structs[j]; string data = column.data[j]; if (i == 0) { line.Append("[" + data + "] = {"); } if (column.head.serverExport || forceAll) { switch (column.head.type) { case TypeDef.IntType: int intData = 0; int.TryParse(data, out intData); if (!isInList) { line.Append(column.head.name + "=" + intData + ","); } else { if (intData != 0) { structTmp.hasData = true; } structTmp.str.Append(column.head.name + "=" + intData + ","); } break; case TypeDef.BoolType: string str = data.ToLower(); bool boolData = false; if (!string.IsNullOrEmpty(str) && str != "0" && str != "false") { boolData = true; } string boolStr = boolData.ToString().ToLower(); if (!isInList) { line.Append(column.head.name + "=" + boolStr + ","); } else { if (boolData) { structTmp.hasData = true; } structTmp.str.Append(column.head.name + "=" + boolStr + ","); } break; case TypeDef.FloatType: float floatData = 0; float.TryParse(data, out floatData); string floatStr = string.Format("{0}", floatData); if (!isInList) { line.Append(column.head.name + "=" + floatStr + ","); } else { if (floatData != 0) { structTmp.hasData = true; } structTmp.str.Append(column.head.name + "=" + floatStr + ","); } break; case TypeDef.StringType: if (!string.IsNullOrEmpty(data)) { string strData = data.TrimStart('"'); strData = strData.TrimEnd('"'); strData = strData.Replace("\\", "\\\\"); strData = strData.Replace("\"", "\\\""); if (!isInList) { line.Append(column.head.name + "=\"" + strData + "\","); } else { structTmp.hasData = true; structTmp.str.Append(column.head.name + "=\"" + strData + "\","); } } break; case TypeDef.ListIntType: case TypeDef.ListFloatType: string strData2 = data.TrimStart('"'); strData2 = strData2.TrimEnd('"'); if (!isInList) { line.Append(column.head.name + "={" + strData2 + "},"); } else { if (!string.IsNullOrEmpty(data)) { structTmp.hasData = true; structTmp.str.Append(column.head.name + "={" + strData2 + "},"); } } break; case TypeDef.ListStringType: if (!string.IsNullOrEmpty(data)) { string strData = data.TrimStart('"'); strData = strData.TrimEnd('"'); string[] param = strData.Split(','); string strDataResult = ""; for (int k = 0; k < param.Length; k++) { strDataResult += "\"" + param[k] + "\""; if (k != param.Length - 1) { strDataResult += ","; } } if (!isInList) { line.Append(column.head.name + "={" + strDataResult + "},"); } else { structTmp.hasData = true; structTmp.str.Append(column.head.name + "={" + strDataResult + "},"); } } break; case TypeDef.StructType: if (!string.IsNullOrEmpty(column.head.name)) { structTmp.str = new StringBuilder(); structTmp.hasData = false; if (isInList) { structTmp.str.Append("{"); } else { line.Append(column.head.name + "={"); } } else { if (isInList) { structTmp.str.Replace(",", "", structTmp.str.Length - 1, 1); structTmp.str.Append("},"); if (structTmp.hasData) { line.Append(structTmp.str.ToString()); } } else { line.Replace(",", "", line.Length - 1, 1); line.Append("},"); } } break; case TypeDef.ListType: if (!string.IsNullOrEmpty(column.head.name)) { line.Append(column.head.name + "={"); isInList = true; } else { line.Replace(",", "", line.Length - 1, 1); line.Append("},"); isInList = false; } break; case TypeDef.LuaTableType: if (!string.IsNullOrEmpty(data)) { string strData = data.TrimStart('"'); strData = strData.TrimEnd('"'); if (!isInList) { line.Append(column.head.name + "=" + strData + ","); } else { structTmp.hasData = true; structTmp.str.Append(column.head.name + "=" + strData + ","); } } break; } } if (i == tabfile.columns.Count - 1) { line.Replace(",", "", line.Length - 1, 1); line.Append("},"); } } } return(true); }