示例#1
0
        // 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);
                }
            }
        }
示例#2
0
        public void Merge(WrapperParam wrapperParam)
        {
            foreach (string author in wrapperParam.Authors)
            {
                if (!Authors.Contains(author))
                {
                    Authors.Add(author);
                }
            }

            // now we need to search for any section and add it into the wrapper AS WELL AS merging same sections of same wrappers together
            foreach (SectionParam section in wrapperParam.SectionDict.Values)
            {
                if (section.DataStructureDict.Count < 1)                 // do not include empty sections
                {
                    continue;
                }

                // section already exists?
                SectionParam finalSection = null;

                foreach (SectionParam tmpSection in SectionDict.Values)
                {
                    if (tmpSection.SectionName == section.SectionName)
                    {
                        finalSection = tmpSection;

                        break;
                    }
                }

                if (finalSection == null)
                {
                    SectionDict.Add(section.SectionName, section);                     // add missing section directly into the wrappers section list
                }
                else
                {
                    finalSection.Merge(section);
                }
            }
        }