// merges 2 sections together. Used by a wrapper to merge same sections of different files public void Merge(SectionParam sectionParam) { foreach (KeyValuePair <string, List <DataStructure> > keyValuePair in sectionParam.DataStructureDict) { foreach (DataStructure dataStructure in keyValuePair.Value) { // just insert if not already exists if (!DataStructureDict.TryGetValue(keyValuePair.Key, out List <DataStructure> finalDSList)) // initialize if not already exists { finalDSList = new List <DataStructure>(); DataStructureDict.Add(keyValuePair.Key, finalDSList); } DataStructure alreadyExistingDs = null; int i = 0; for (; i < finalDSList.Count; i++) { DataStructure tmpDs = finalDSList[i]; if (tmpDs.GetDatastructureName() == dataStructure.GetDatastructureName() && tmpDs.Realm == dataStructure.Realm) { alreadyExistingDs = tmpDs; break; } } if (alreadyExistingDs != null) { DataStructure mergedDs = alreadyExistingDs.Merge(dataStructure); if (mergedDs == null) { NeoDoc.WriteErrors("Merging issue", new List <string>() { "Tried to add an already existing '" + alreadyExistingDs.GetName() + "' datastructure ('" + alreadyExistingDs.GetDatastructureName() + "') while merging section '" + sectionParam.SectionName + "'!", "Existing datastructure source: '" + alreadyExistingDs.FoundPath + "' (ll. " + alreadyExistingDs.FoundLine + ")" }, dataStructure.FoundPath, dataStructure.FoundLine, (int)NeoDoc.ERROR_CODES.MERGING_ISSUE); } else if (mergedDs != alreadyExistingDs) // replace if new ds { finalDSList[i] = mergedDs; } continue; } finalDSList.Add(dataStructure); } } }
public void ProcessGlobals(SortedDictionary <string, SortedDictionary <string, List <DataStructure> > > globalsDict) { SortedDictionary <string, List <DataStructure> > finalDict = new SortedDictionary <string, List <DataStructure> >(); foreach (KeyValuePair <string, List <DataStructure> > keyValuePair in DataStructureDict) { List <DataStructure> finalDSList = new List <DataStructure>(); foreach (DataStructure dataStructure in keyValuePair.Value) { DataStructure alreadyExistingDs = null; if (!dataStructure.IsGlobal()) { foreach (DataStructure entry in finalDSList) { if (entry.GetDatastructureName() == dataStructure.GetDatastructureName() && entry.Realm == dataStructure.Realm) { alreadyExistingDs = entry; break; } } if (alreadyExistingDs != null) { NeoDoc.WriteErrors("Merging issue", new List <string>() { "Tried to add an already existing '" + alreadyExistingDs.GetName() + "' datastructure ('" + alreadyExistingDs.GetDatastructureName() + "') in the same section ('" + SectionName + "')!", "Existing datastructure source: '" + alreadyExistingDs.FoundPath + "' (ll. " + alreadyExistingDs.FoundLine + ")" }, dataStructure.FoundPath, dataStructure.FoundLine, (int)NeoDoc.ERROR_CODES.MERGING_ISSUE); continue; } finalDSList.Add(dataStructure); continue; } if (!globalsDict.TryGetValue(dataStructure.GetName(), out SortedDictionary <string, List <DataStructure> > dsList)) { dsList = new SortedDictionary <string, List <DataStructure> >(); globalsDict.Add(dataStructure.GetName(), dsList); } // just insert if not already exists if (!dsList.TryGetValue(dataStructure.GlobalWrapper, out List <DataStructure> dsWrapperList)) { dsWrapperList = new List <DataStructure>(); dsList.Add(dataStructure.GlobalWrapper, dsWrapperList); } int i = 0; for (; i < dsWrapperList.Count; i++) { DataStructure entry = dsWrapperList[i]; if (entry.GetDatastructureName() == dataStructure.GetDatastructureName() && entry.Realm == dataStructure.Realm) { alreadyExistingDs = entry; break; } } if (alreadyExistingDs != null) { DataStructure mergedDs = alreadyExistingDs.Merge(dataStructure); if (mergedDs == null) { NeoDoc.WriteErrors("Merging issue", new List <string>() { "Tried to add an already existing global '" + alreadyExistingDs.GetName() + "' datastructure ('" + alreadyExistingDs.GetDatastructureName() + "')!", "Existing datastructure source: '" + alreadyExistingDs.FoundPath + "' (ll. " + alreadyExistingDs.FoundLine + ")" }, dataStructure.FoundPath, dataStructure.FoundLine, (int)NeoDoc.ERROR_CODES.MERGING_ISSUE); } else if (mergedDs != alreadyExistingDs) // replace if new ds { dsWrapperList[i] = mergedDs; } continue; } dsWrapperList.Add(dataStructure); } if (finalDSList.Count > 0) { finalDict.Add(keyValuePair.Key, finalDSList); } } DataStructureDict = finalDict; }