void ScanForCompInfo(string[] input) { for (int i = 1; i < input.Length; i++) { if (RegFunctions.IsCompBaseInfo(input[i])) { string s = input[i].Split('@')[0]; Dictionary <string, string> d = ScanFile(s); Dictionary <string, string> d2 = RegFunctions.GetDefLineDict(input[i]); defaultDict.Add(s, new Dictionary <string, string>()); if (d != null) { foreach (var kv in d2) { DictionaryFunctions.AddOrUpdatePair(kv, d); } defaultDict[s] = d; } else { defaultDict[s] = d2; } } } }
//Scan macro and store string[] ScanMacro(string[] input) { string temp = string.Join("\r\n", input); Dictionary <string, string> tcontent = new Dictionary <string, string>() { { KeyWordDef.AT, "MACRO" }, }; Dictionary <string, List <string> > macroDict = RegFunctions.GetMacroDictAndRemove(temp, out string output); foreach (var kv in macroDict) { CompInfoTemp ct = new CompInfoTemp() { gname = "MACRO", rname = kv.Key, content = tcontent }; ct.contents = (from mkv in macroDict from value in kv.Value let key = "#ITEM#" select new { key, value }) .Select(dict => new Dictionary <string, string> { { dict.key, dict.value } }) .ToList(); gTopoList.Add(ct); } return(output.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)); }
public virtual void FillContentFromDefLine(CompInfoTemp t, string defLine) { Dictionary <string, string> dt = RegFunctions.GetDefLineDict(defLine); foreach (var kv in dt) { DictionaryFunctions.AddOrUpdatePair(kv, t.content); } }
Dictionary <string, string> ScanFile(string type) { string filePath = defaultInfoPath + type + ".txt"; if (File.Exists(filePath)) { string fileStr = File.ReadAllText(filePath); return(RegFunctions.GetDefaultDict(fileStr)); } else { return(null); } }
public static List <int> GetAxisNoByCompName(string compList) { List <string> compNameList = RegFunctions.SplitToListByComma(compList); List <int> li = new List <int>(); foreach (string s in compNameList) { string n = s.Split('.')[0]; string i = s.Split('.').Length > 1 ? s.Split('.')[1] : "0"; try { li.Add(gTopoList.Find(c => c.rname == s.Split('.')[0]).axisStart + int.Parse(i)); } catch { continue; } } return(li); }
public static void AppendMultiRepeat(ref string source, string keyWord, List <Dictionary <string, string> > replaceDictList, int startIndex = 0, int count = int.MaxValue) { Dictionary <int, string> ms = RegFunctions.GetRepeat(source, keyWord, startIndex, count); int index = 0; int _count = 0; foreach (var rkv in ms) { index += rkv.Key; foreach (var dt in replaceDictList) { string matchStr = rkv.Value; foreach (var tkv in dt) { if (_count != 0 && tkv.Key.StartsWith("@@")) { int _index = matchStr.IndexOf(tkv.Key); if (_index != -1) { string line = GetWholeLine(matchStr, _index); matchStr.Replace(line + "\r\n", ""); } } matchStr = matchStr.Replace(tkv.Key, tkv.Value); } List <string> t = matchStr.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList(); t.RemoveAll(s => s.Contains("&")); t.RemoveAt(t.Count - 1); matchStr = string.Join("\r\n", t); source = source.Insert(index, matchStr); index += matchStr.Length; _count++; } index -= rkv.Key; } }
List <CompInfoTemp> ScanTopo(string[] input) { List <Dictionary <string, string> > strDict = RegFunctions.GetTopoDict(input[0]); if (strDict.Count <= 0) { throw new Exception("首行不是拓补定义"); } List <CompInfoTemp> topoList = new List <CompInfoTemp>(); Dictionary <string, int> compMaxNumDict = new Dictionary <string, int>(); Dictionary <string, List <int> > checkNumDict = new Dictionary <string, List <int> >(); foreach (var kv in strDict) { List <int> compNumList = new List <int>(); string compName = kv.First().Key; string sv = kv.First().Value; int i; DictionaryFunctions.GetValueOrAddNewKey(checkNumDict, compName, new List <int>()); if (sv.Contains('$')) { List <int> li; try { li = sv.Split('$')[1].Split(',').Select(s => int.Parse(s)).ToList(); } catch { throw new Exception($"无效值{compName}:{sv}"); } int num = int.TryParse(sv.Split('$')[0], out num) ? num : li.Count; for (i = 1; i <= num; i++) { if (i <= li.Count) { compNumList.Add(li[i - 1]); } else { compNumList.Add(li.Last() + i - li.Count); } } } else { int value = int.Parse(kv.First().Value); i = DictionaryFunctions.GetValueOrAddNewKey(compMaxNumDict, compName, 0) + 1; compMaxNumDict[compName] += value; for (; i <= compMaxNumDict[compName]; i++) { compNumList.Add(i); } } ; foreach (int j in compNumList) { i = j; if (checkNumDict[compName].Contains(i)) { throw new Exception($"重复编号{compName}:{i}"); } checkNumDict[compName].Add(i); CompInfoTemp temp = new CompInfoTemp() { rname = compName + i.ToString(), gname = compName, }; topoList.Add(temp); } } return(topoList); }
public override void FillContentFromDefLine(CompInfoTemp t, string s) { Dictionary <string, string> dt = RegFunctions.GetDefLineDict(s); t.contents.Add(dt); }