public LogMsgData[] IsValid(DataSheetInfo sInfo, int index) { List <LogMsgData> result = new List <LogMsgData>(); DataFieldInfo dfi = sInfo.GetFieldInfo(index); int len = 0; if (!int.TryParse(dfi.validationValue, out len)) { return(null); } int count = sInfo.GetContentCount(); for (int i = 0; i < count; i++) { object data = sInfo.GetContentValue(i, index); if (data != null && (dfi.type == DataFieldType.Int || dfi.type == DataFieldType.Float || dfi.type == DataFieldType.Double || dfi.type == DataFieldType.Long)) { } } if (result.Count > 0) { return(result.ToArray()); } else { return(null); } }
public LogMsgData[] IsValid(DataSheetInfo sInfo, int index) { List <LogMsgData> result = new List <LogMsgData>(); DataFieldInfo dfi = sInfo.GetFieldInfo(index); int count = sInfo.GetContentCount(); Dictionary <string, bool> cacheData = new Dictionary <string, bool>(); for (int i = 0; i < count; i++) { object data = sInfo.GetContentValue(i, index); if (data == null) { result.Add(new ErrorLogData1(LogConst.E_DataValidation_Null, "" + index)); } } if (result.Count > 0) { return(result.ToArray()); } else { return(null); } }
public LogMsgData[] IsValid(DataSheetInfo sInfo, int index) { List <LogMsgData> result = new List <LogMsgData>(); DataFieldInfo dfi = sInfo.GetFieldInfo(index); int len = 0; if (!int.TryParse(dfi.validationValue, out len)) { return(null); } int count = sInfo.GetContentCount(); for (int i = 0; i < count; i++) { object data = sInfo.GetContentValue(i, index); if (data != null && (dfi.type == DataFieldType.String || dfi.type == DataFieldType.Stringt || dfi.type == DataFieldType.Res)) { string value = (string)data; if (value.Length > len) { result.Add(new ErrorLogData3(LogConst.E_DataValidation_StrLen, "" + index, "" + len, value)); } } } if (result.Count > 0) { return(result.ToArray()); } else { return(null); } }
private bool AddField(DataFieldInfo fieldInfo) { string nameReg = @"^[A-Z][A-Za-z0-9]{1,15}$"; if (!Regex.IsMatch(fieldInfo.name, nameReg)) { logMsg.Add(new ErrorLogData2(LogConst.E_DataField_NameFormat, "" + fieldInfo.columnIndex, fieldInfo.name)); return(false); } if (fields.Count == 0 && (fieldInfo.name != "ID" || fieldInfo.type != DataFieldType.Int)) { logMsg.Add(new ErrorLogData(LogConst.E_DataField_ID)); return(false); } foreach (DataFieldInfo dfi in fields) { if (dfi.name == fieldInfo.name) { logMsg.Add(new ErrorLogData2(LogConst.E_DataField_NameRepeat, "" + dfi.columnIndex, "" + fieldInfo.columnIndex)); return(false); } } fields.Add(fieldInfo); return(true); }
public LogMsgData[] IsValid(DataSheetInfo sInfo, int index) { List <LogMsgData> result = new List <LogMsgData>(); DataFieldInfo dfi = sInfo.GetFieldInfo(index); int count = sInfo.GetContentCount(); Dictionary <string, bool> cacheData = new Dictionary <string, bool>(); for (int i = 0; i < count; i++) { object data = sInfo.GetContentValue(i, index); if (data != null) { string validaStr = null; if (dfi.type == DataFieldType.Dic) { Dictionary <string, string> dicData = (Dictionary <string, string>)data; List <string> tempStrs = new List <string>(); foreach (KeyValuePair <string, string> kvp in dicData) { string t = kvp.Key + ":" + (kvp.Value == null ? "null" : kvp.Value); tempStrs.Add(t); } tempStrs.Sort(); validaStr = string.Join(",", tempStrs.ToArray()); } else if (dfi.type == DataFieldType.Array) { List <string> arrData = (List <string>)data; arrData.Sort(); validaStr = string.Join(",", arrData.ToArray()); } else { validaStr = (string)data; } if (cacheData.ContainsKey(validaStr)) { result.Add(new ErrorLogData2(LogConst.E_DataValidation_Repeat, "" + index, validaStr)); } else { cacheData.Add(validaStr, true); } } } if (result.Count > 0) { return(result.ToArray()); } else { return(null); } }
public bool IsInDefault(DataFieldInfo dfInfo, object value) { object data = null; if (defaultDic.TryGetValue(dfInfo, out data)) { if (data.Equals(value)) { return(true); } } return(false); }
public static void GetFieldDicKeyInfo(string ft, out DataFieldInfo keyField, out DataFieldInfo valueField) { keyField = null; valueField = null; if (string.IsNullOrEmpty(ft)) { return; } int sIndex = ft.IndexOf('('); int lIndex = ft.LastIndexOf(')'); if (sIndex < 0 || lIndex < 0) { return; } string fTypeStr = ft.Substring(sIndex + 1, lIndex - sIndex - 1); if (fTypeStr.IndexOf('/') <= 0) { return; } string[] fTypeStrSplit = fTypeStr.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (fTypeStrSplit == null || fTypeStrSplit.Length != 2) { return; } DataFieldType keyFT = GetFieldType(fTypeStrSplit[0]); DataFieldType valueFT = GetFieldType(fTypeStrSplit[1]); if (keyFT == DataFieldType.None || valueFT == DataFieldType.None) { return; } keyField = new DataFieldInfo(); keyField.type = keyFT; if (keyFT == DataFieldType.Ref) { keyField.refName = GetFieldRefName(fTypeStrSplit[0]); } valueField = new DataFieldInfo(); valueField.type = valueFT; if (valueFT == DataFieldType.Ref) { valueField.refName = GetFieldRefName(fTypeStrSplit[1]); } }
public object GetContentValue(int row, int col, bool useDefault = false) { if (row >= 0 && row < contents.Count && col >= 0 && col < fields.Count) { object result = contents[row].GetCellData(col).value; if (result == null) { if (useDefault) { DataFieldInfo dfInfo = fields[col]; if (dfInfo.type != DataFieldType.Dic && dfInfo.type != DataFieldType.Array && !string.IsNullOrEmpty(dfInfo.defaultContent)) { result = dfInfo.defaultContent; } } } return(result); } return(null); }
public static void GetArrayFieldInfo(string ft, out DataFieldInfo valueField) { valueField = null; if (string.IsNullOrEmpty(ft)) { return; } int sIndex = ft.IndexOf('('); int lIndex = ft.LastIndexOf(')'); if (sIndex < 0 || lIndex < 0) { return; } string fTypeStr = ft.Substring(sIndex + 1, lIndex - sIndex - 1); DataFieldType fType = GetFieldType(fTypeStr); valueField = new DataFieldInfo(); valueField.type = fType; if (fType == DataFieldType.Ref) { valueField.refName = GetFieldRefName(ft); } }
private bool ParseToContent(WorkSheet wSheet) { int rowCount = wSheet.RowCount(); int colCount = wSheet.ColumnCount(); int startRow = MIN_ROW_COUNT; for (int j = startRow; j < rowCount; j++) { DataLineInfo content = new DataLineInfo(fields.Count); for (int i = 0; i < fields.Count; i++) { DataFieldInfo fInfo = fields[i]; string value = wSheet.GetValue(j, fInfo.columnIndex); if (fInfo.type == DataFieldType.Dic) { if (string.IsNullOrEmpty(value)) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLen, "" + j, "" + i)); continue; } else { if (int.TryParse(value, out int count)) { int maxLen = -1; if (i == fields.Count - 1) { maxLen = colCount - fInfo.columnIndex - 1; } else { maxLen = fields[i + 1].columnIndex - fInfo.columnIndex - 1; } if (count * 2 > maxLen) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLarge, "" + j, "" + i)); continue; } else { Dictionary <string, string> result = new Dictionary <string, string>(); for (int m = 1; m <= count; m++) { string k = wSheet.GetValue(j, fInfo.columnIndex + 2 * (m - 1) + 1); string v = wSheet.GetValue(j, fInfo.columnIndex + 2 * m); if (result.ContainsKey(k)) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLarge, "" + j, "" + i)); result.Clear(); break; } else { result.Add(k, v); } } content.AddCellData(i, j, fInfo.columnIndex, result); } } else { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLen, "" + j, "" + i)); continue; } } } else if (fInfo.type == DataFieldType.Array) { if (string.IsNullOrEmpty(value)) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLen, "" + j, "" + i)); continue; } else { if (int.TryParse(value, out int count)) { int maxLen = -1; if (i == fields.Count - 1) { maxLen = colCount - fInfo.columnIndex - 1; } else { maxLen = fields[i + 1].columnIndex - fInfo.columnIndex - 1; } if (count > maxLen) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_ArrayLarge, "" + j, "" + i)); continue; } else { List <string> result = new List <string>(); for (int m = 1; m <= count; m++) { result.Add(wSheet.GetValue(j, fInfo.columnIndex + m)); } content.AddCellData(i, j, fInfo.columnIndex, result); } } else { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLen, "" + j, "" + i)); continue; } } } else { string v = wSheet.GetValue(j, fInfo.columnIndex); content.AddCellData(i, j, fInfo.columnIndex, v); } } contents.Add(content); } contents.Sort(SortDataLineByID); return(true); }
private bool ParseToField(WorkSheet wsheet) { int rowCount = wsheet.RowCount(); int colCount = wsheet.ColumnCount(); DataFieldType preFieldType = DataFieldType.None; for (int i = 1; i < colCount; i++) { string fName = wsheet.GetValue(0, i); string fTypeStr = wsheet.GetValue(1, i); string fExportStr = wsheet.GetValue(2, i); string fDesc = wsheet.GetValue(3, i); string fDefault = wsheet.GetValue(4, i); string fValidation = wsheet.GetValue(5, i); string fValidValue = wsheet.GetValue(6, i); if (string.IsNullOrEmpty(fName)) { if (preFieldType == DataFieldType.Dic || preFieldType == DataFieldType.Array) { continue; } else { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_Empty, "" + i)); continue; } } DataFieldType fType = DataHelper.GetFieldType(fTypeStr); if (fType == DataFieldType.None) { logMsg.Add(new ErrorLogData2(LogConst.E_DataField_TypeNone, "" + i, string.IsNullOrEmpty(fTypeStr) ? "" : fTypeStr)); continue; } DataFieldExport fExport = DataHelper.GetFieldExport(fExportStr); if (fExport == DataFieldExport.None) { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_ExportNone, "" + i)); continue; } DataFieldInfo fInfo = new DataFieldInfo { columnIndex = i, name = fName, type = fType, export = fExport, desc = fDesc, validation = DataHelper.GetFieldValidationType(fValidation), validationValue = fValidValue, defaultContent = fDefault }; if (fType == DataFieldType.Dic) { DataHelper.GetFieldDicKeyInfo(fTypeStr, out fInfo.keyField, out fInfo.valueField); if (fInfo.keyField == null || fInfo.valueField == null) { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_DicType, "" + i)); continue; } if (fInfo.keyField.type == DataFieldType.Ref) { if (string.IsNullOrEmpty(fInfo.keyField.refName)) { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_DicKeyRef, "" + i)); continue; } } if (fInfo.valueField.type == DataFieldType.Ref) { if (string.IsNullOrEmpty(fInfo.valueField.refName)) { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_DicValueRef, "" + i)); continue; } } } else if (fType == DataFieldType.Array) { DataHelper.GetArrayFieldInfo(fTypeStr, out fInfo.valueField); if (fInfo.valueField == null) { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_ArrayType, "" + i)); continue; } else if (fInfo.valueField.type == DataFieldType.Ref) { if (string.IsNullOrEmpty(fInfo.valueField.refName)) { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_ArrayValueRef, "" + i)); continue; } } } else if (fType == DataFieldType.Ref) { fInfo.refName = DataHelper.GetFieldRefName(fTypeStr); if (string.IsNullOrEmpty(fInfo.refName)) { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_RefRef, "" + i)); continue; } } else if (fType == DataFieldType.Res) { fInfo.refName = DataHelper.GetFieldRefName(fTypeStr); if (string.IsNullOrEmpty(fInfo.refName)) { logMsg.Add(new ErrorLogData1(LogConst.E_DataField_ResType, "" + i)); continue; } } preFieldType = fType; if (!AddField(fInfo)) { fields.Clear(); return(false); } } return(true); }
private void CreateSummary() { summary.count = dataSheet.GetContentCount(); summary.subformCount = (int)Math.Ceiling(((float)summary.count) / exportConfig.subform); summary.textPath = dataSheet.Name + "Text"; summary.strPath = dataSheet.Name + "Str"; for (int i = 0; i < dataSheet.GetFieldCount(); i++) { DataFieldInfo dfInfo = dataSheet.GetFieldInfo(i); if (dfInfo.type == DataFieldType.Stringt) { summary.textFields.Add(dfInfo.name); } else if (dfInfo.type == DataFieldType.String || dfInfo.type == DataFieldType.Res) { summary.strFields.Add(dfInfo.name); } } int index = 1; while (true) { DataToOptimizeLuaSummary.SubformDataOfSummary subformData = new DataToOptimizeLuaSummary.SubformDataOfSummary(); subformData.path = string.Format("{0}/{0}_{1}", dataSheet.Name, index); subformData.minID = int.Parse((string)dataSheet.GetContentValue((index - 1) * exportConfig.subform, 0)); int maxIndex = index * exportConfig.subform - 1; if (maxIndex >= dataSheet.GetContentCount()) { maxIndex = dataSheet.GetContentCount() - 1; } subformData.maxID = int.Parse((string)dataSheet.GetContentValue(maxIndex, 0)); summary.subforms.Add(subformData); if (maxIndex == dataSheet.GetContentCount() - 1) { break; } index++; } for (int i = 1; i < dataSheet.GetFieldCount(); i++) { DataFieldInfo dfInfo = dataSheet.GetFieldInfo(i); if (dfInfo.type == DataFieldType.Array || dfInfo.type == DataFieldType.Dic) { continue; } Dictionary <string, int> totalCount = new Dictionary <string, int>(); for (int j = 0; j < dataSheet.GetContentCount(); j++) { string data = (string)dataSheet.GetContentValue(j, i, true); if (!string.IsNullOrEmpty(data)) { if (dfInfo.type == DataFieldType.Stringt) { data = "" + text.AddText(data); } else if (dfInfo.type == DataFieldType.String || dfInfo.type == DataFieldType.Res) { data = "" + str.AddText(data); } if (totalCount.ContainsKey(data)) { totalCount[data]++; } else { totalCount.Add(data, 1); } } } string maxValue = null; int maxCount = 0; foreach (KeyValuePair <string, int> kvp in totalCount) { if (kvp.Value > maxCount) { maxValue = kvp.Key; maxCount = kvp.Value; } } if (maxValue != null && maxCount > 1) { summary.defaultDic.Add(dfInfo, maxValue); } } }
public void Export() { string dirPath = exportConfig.targetDir; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } summary.Export(dataSheet.Name, dirPath); text.Export(dataSheet.Name + "Text_" + ConfigMgr.GetInstance().GetConfig().languageConfig.package, dirPath); str.Export(dataSheet.Name + "Str", dirPath); string subDirPath = dirPath + "/" + dataSheet.Name; if (!Directory.Exists(subDirPath)) { Directory.CreateDirectory(subDirPath); //Directory.Delete(subDirPath, true); } for (int i = 1; i <= summary.subformCount; i++) { int startIndex = (i - 1) * exportConfig.subform; int endIndex = i * exportConfig.subform - 1; if (endIndex >= dataSheet.GetContentCount()) { endIndex = dataSheet.GetContentCount() - 1; } StringBuilder sb = new StringBuilder(); sb.AppendFormat("local {0}_{1} = {{\n", dataSheet.Name, i); for (int k = startIndex; k <= endIndex; k++) { int dataID = int.Parse((string)dataSheet.GetContentValue(k, 0)); sb.AppendFormat(" [{0}] = {{\n", dataID); for (int j = 0; j < dataSheet.GetFieldCount(); j++) { DataFieldInfo dfInfo = dataSheet.GetFieldInfo(j); object data = dataSheet.GetContentValue(k, j, true); if (dfInfo.type == DataFieldType.Stringt) { data = "" + text.GetIndex((string)data); } else if (dfInfo.type == DataFieldType.String || dfInfo.type == DataFieldType.Res) { data = "" + str.GetIndex((string)data); } if (summary.IsInDefault(dfInfo, data)) { continue; } switch (dfInfo.type) { case DataFieldType.Dic: break; case DataFieldType.Array: break; case DataFieldType.Bool: case DataFieldType.Float: case DataFieldType.Int: case DataFieldType.Long: case DataFieldType.Double: case DataFieldType.Ref: { string strData = (string)data; sb.AppendFormat(" {0} = {1},\n", dfInfo.name, strData.ToLower()); } break; case DataFieldType.String: case DataFieldType.Stringt: case DataFieldType.Res: { string strData = (string)data; sb.AppendFormat(" {0}_index = {1},\n", dfInfo.name, strData.ToLower()); } break; } } sb.AppendLine(" },"); } sb.AppendLine("}"); sb.AppendFormat("SetLooseReadonly({0}_{1})\n", dataSheet.Name, i); sb.AppendFormat("return {0}_{1}\n", dataSheet.Name, i); string fileContent = sb.ToString(); File.WriteAllText(subDirPath + "/" + dataSheet.Name + "_" + i + ".lua", fileContent); } }