private static void ChangeNodes(string fullPath, Dictionary <string, List <string> > rapport, Dictionary <string, string> ips) { List <string> file = new List <string>(); foreach (string line in File.ReadAllLines(fullPath)) { file.Add(line); } for (int i = 0; i < file.Count(); i++) { string trimmedLine = file[i].Trim(); foreach (string startsWith in StartsWithList) { if (trimmedLine.StartsWith(startsWith) && trimmedLine.EndsWith(EndsWith)) { int firstIndex = file[i].IndexOf(startsWith); int lastIndex = file[i].LastIndexOf(EndsWith); string oldValue = file[i].Substring(firstIndex + startsWith.Length, lastIndex - firstIndex - startsWith.Length); string newValue = null; if (AnonymousNodes.ContainsKey(oldValue)) { newValue = AnonymousNodes[oldValue]; } if (AnonymousExtra.ContainsKey(oldValue)) { newValue = AnonymousExtra[oldValue]; } if (newValue != null) { int index = i; file[i] = file[i].Substring(0, firstIndex + startsWith.Length) + newValue + file[i].Substring(lastIndex, EndsWith.Length); } } } } File.Delete(fullPath); StreamWriter sw = File.CreateText(fullPath); foreach (string line in file) { sw.WriteLine(line); } }
public static Dictionary <string, List <string> > GenerateAnonymousNames(Dictionary <string, List <string> > rapport) { string currentExtension = ""; List <string> keys = rapport.Keys.ToList <string>(); for (int i = 0; i < keys.Count(); i++) { for (int j = 0; j < rapport[keys[i]].Count; j++) { string oldNode = rapport[keys[i]][j]; bool found2 = false; currentExtension = "_BA"; foreach (string ext in Extensions) { if (rapport[keys[i]][j].EndsWith(ext)) { found2 = true; currentExtension = ext; break; } } if (found2 && !DisableExtension) { rapport[keys[i]][j] = rapport[keys[i]][j].Substring(0, rapport[keys[i]][j].Length - currentExtension.Length); } List <int> indices = SearchChar(rapport[keys[i]][j], '_'); int currentIndex = 0; int k = 0; rapport[keys[i]][j] = ""; for (; k < Counters.Count && k < indices.Count; k++) { rapport[keys[i]][j] += "" + Counters[k] + "_"; currentIndex = indices[k]; Counters[k] += 1; } rapport[keys[i]][j] += Counters[k]; if (!DisableExtension) { rapport[keys[i]][j] += currentExtension; } Counters[k] += 1; if (!AnonymousNodes.ContainsKey(oldNode)) { AnonymousNodes.Add(oldNode, rapport[keys[i]][j]); } } } return(rapport); }