private DbStruct[] DoAnalyse(Stream fs, bool flag) { DbStruct[] dbstruct = null; bool isFirstLine = true; int TotalColumns = 0, LinesProcessed = 0; using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { string line; while ((line = sr.ReadLine()) != null) { string[] splitted = line.Split(new char[] { ',' }); if (isFirstLine) { TotalColumns = splitted.Length; dbstruct = new DbStruct[TotalColumns]; for (int i = 0; i < TotalColumns; i++) { string str = splitted[i]; str = str.TrimStart('"').TrimEnd('"'); dbstruct[i] = new DbStruct(); dbstruct[i].Name = str; dbstruct[i].MaxLength = 0; dbstruct[i].IsString = false; dbstruct[i].IntSize = 0; dbstruct[i].IsNull = false; } isFirstLine = !isFirstLine; } else { for (int i = 0; i < TotalColumns; i++) { string str = splitted[i]; str = str.TrimStart('"').TrimEnd('"'); if (str == "" || str == string.Empty) { dbstruct[i].IsNull = true; } if (str.Length > dbstruct[i].MaxLength) { dbstruct[i].MaxLength = str.Length; } long value = 0; if (!long.TryParse(str, out value)) { dbstruct[i].IsString = true; } else if (flag && value != 0 && str[0] == '0') { dbstruct[i].IsString = true; } if (!dbstruct[i].IsString) { byte IntSize = 0; if (value >= 0 && value <= 255) { IntSize = 0; } if ((value > 255 && value <= 32767) || (value > -32768 && value < 0)) { IntSize = 1; } if ((value > 32767 && value <= 2147483647) || (value > -2147483648 && value <= -32768)) { IntSize = 2; } if ((value > 2147483647 && value <= 9223372036854775807) || (value > -9223372036854775808 && value <= -2147483648)) { IntSize = 3; } dbstruct[i].IntSize = Math.Max(dbstruct[i].IntSize, IntSize); } } } LinesProcessed++; } } return(dbstruct); }
public void RunNameTransformation(INameTransformation transform) { Reload(); DbStruct.RunNameTransformation(transform); SaveToFile(); }