public static TriDataPack GetPack(String packname) { if (!datas.ContainsKey(packname)) { TriDataPack data = DataService.GetAllTriData(packname); datas.Add(packname, data); } return(datas[packname]); }
public static void resetData(string tableName, TriDataPack pack) { String line; StreamWriter sw = new StreamWriter(datapath + "/" + tableName + ".cfg", false, Encoding.UTF8); sw.WriteLine("[header]"); for (int i = 0; i < pack.headers.Count; ++i) { line = pack.headers[i] + "\t" + pack.dataTypes[i] + "\t" + pack.dataSizes[i] + "\t" + pack.comment[i]; sw.WriteLine(line); } sw.WriteLine(); sw.WriteLine("[data]"); //按照key顺序输出 List <int> key1List = new List <int>(); Dictionary <int, List <TriData> > key1Map = new Dictionary <int, List <TriData> >(); foreach (TriData tri in pack.data.Keys) { if (!key1Map.ContainsKey(tri.a)) { key1Map.Add(tri.a, new List <TriData>()); key1List.Add(tri.a); } key1Map[tri.a].Add(tri); } key1List.Sort(); for (int i = 0; i < key1List.Count; ++i) { List <int> key2List = new List <int>(); Dictionary <int, List <TriData> > key2Map = new Dictionary <int, List <TriData> >(); foreach (TriData tri in key1Map[key1List[i]]) { if (!key2Map.ContainsKey(tri.b)) { key2Map.Add(tri.b, new List <TriData>()); key2List.Add(tri.b); } key2Map[tri.b].Add(tri); } key2List.Sort(); for (int j = 0; j < key2List.Count; ++j) { List <int> key3List = new List <int>(); Dictionary <int, TriData> key3Map = new Dictionary <int, TriData>(); foreach (TriData tri in key2Map[key2List[j]]) { key3Map.Add(tri.c, tri); key3List.Add(tri.c); } key3List.Sort(); for (int k = 0; k < key3List.Count; ++k) { sw.WriteLine(String.Join("\t", pack.data[key3Map[key3List[k]]].ToArray())); } } } sw.Close(); pack.lines.Clear(); StreamReader sr = new StreamReader(datapath + "/" + tableName + ".cfg", Encoding.UTF8); while ((line = sr.ReadLine()) != null) { pack.lines.Add(line); } sr.Close(); }
public static TriDataPack GetAllTriData(string tableName) { TriDataPack pack = new TriDataPack(tableName); pack.lines.Clear(); StreamReader sr = new StreamReader(datapath + "/" + tableName + ".cfg", Encoding.UTF8); string line = ""; bool inHeader = false; bool inData = false; while ((line = sr.ReadLine()) != null) { pack.lines.Add(line); if (line == "[header]") { inHeader = true; inData = false; } else if (line == "[data]") { inHeader = false; inData = true; } else if (inHeader) { string[] items = line.Split('\t'); if (items.Length >= 3) { pack.headers.Add(items[0]); pack.dataTypes.Add(items[1]); pack.dataSizes.Add(int.Parse(items[2])); } if (items.Length >= 4) { pack.comment.Add(items[3]); } else { pack.comment.Add(""); } } else if (inData) { string[] items = line.Split('\t'); List <string> strList = items.ToList(); int keyid = int.Parse(items[0]); TriData dat = new TriData(int.Parse(items[0]), int.Parse(items[1]), int.Parse(items[2])); pack.data.Add(dat, new List <string>(items)); if (pack.keys.ContainsKey(keyid)) { pack.keys[keyid]++; } else { pack.keys.Add(keyid, 1); } } } sr.Close(); return(pack); }