/// <summary> Add a new mapping set </summary> /// <param name="NewSet"> New brief item mapping set </param> public void Add_MappingSet( BriefItemMapping_Set NewSet ) { MappingSets.Add(NewSet); // Ensure the dictionary is current if ((mappingSetsDictionary == null) || (mappingSetsDictionary.Count != MappingSets.Count)) { if (mappingSetsDictionary == null) mappingSetsDictionary = new Dictionary<string, BriefItemMapping_Set>(StringComparer.OrdinalIgnoreCase); else mappingSetsDictionary.Clear(); foreach (BriefItemMapping_Set thisSet in MappingSets) { mappingSetsDictionary[thisSet.SetName] = thisSet; } } }
/// <summary> Add a new mapping set </summary> /// <param name="NewSet"> New brief item mapping set </param> public void Add_MappingSet(BriefItemMapping_Set NewSet) { MappingSets.Add(NewSet); // Ensure the dictionary is current if ((mappingSetsDictionary == null) || (mappingSetsDictionary.Count != MappingSets.Count)) { if (mappingSetsDictionary == null) { mappingSetsDictionary = new Dictionary <string, BriefItemMapping_Set>(StringComparer.OrdinalIgnoreCase); } else { mappingSetsDictionary.Clear(); } foreach (BriefItemMapping_Set thisSet in MappingSets) { mappingSetsDictionary[thisSet.SetName] = thisSet; } } }
/// <summary> Read the configuration file for the brief item mapping sets </summary> /// <returns> TRUE if successful, otherwise FALSE </returns> private static bool read_briefitem_mapping_details(XmlReader ReaderXml, InstanceWide_Configuration Config ) { // Ensure the brief item mapping exists if (Config.BriefItemMapping == null) Config.BriefItemMapping = new BriefItemMapping_Configuration(); // During this process, small objects ( IBriefItemMappers ) which contain no data // but implement the mapping method will be created. This dictionary helps to ensure // each one is created only once. Dictionary<string, IBriefItemMapper> mappingObjDictionary = new Dictionary<string, IBriefItemMapper>(); try { while (ReaderXml.Read()) { if (ReaderXml.NodeType == XmlNodeType.Element) { switch (ReaderXml.Name.ToLower()) { case "mappingset": // Get the ID for this mapping set string id = String.Empty; if (ReaderXml.MoveToAttribute("ID")) id = ReaderXml.Value.Trim(); // Was this indicated as the default set? if (ReaderXml.MoveToAttribute("Default")) { if (String.Compare(ReaderXml.Value, "true", StringComparison.OrdinalIgnoreCase) == 0) { if (id.Length > 0) Config.BriefItemMapping.DefaultSetName = id; else { Config.BriefItemMapping.DefaultSetName = "DEFAULT"; id = "DEFAULT"; } } } BriefItemMapping_Set thisSet = Config.BriefItemMapping.GetMappingSet(id); if (thisSet == null) { thisSet = new BriefItemMapping_Set {SetName = id}; Config.BriefItemMapping.Add_MappingSet(thisSet); } // Read the set here ReaderXml.MoveToElement(); read_mappingset_details(ReaderXml.ReadSubtree(), thisSet, mappingObjDictionary); break; } } } } catch (Exception ee) { Config.Source.Add_Log("EXCEPTION CAUGHT in Configuration_Files_Reader.read_briefitem_mapping_details"); Config.Source.Add_Log(ee.Message); Config.Source.Add_Log(ee.StackTrace); Config.Source.ErrorEncountered = true; return false; } return true; }
private static void read_mappingset_details(XmlReader ReaderXml, BriefItemMapping_Set ReturnValue, Dictionary<string, IBriefItemMapper> MappingObjDictionary) { // Just step through the subtree of this while (ReaderXml.Read()) { if (ReaderXml.NodeType == XmlNodeType.Element) { switch (ReaderXml.Name.ToLower()) { case "mapper": // Read all the data for this mapper class string mapperAssembly = String.Empty; string mapperClass = String.Empty; if (ReaderXml.MoveToAttribute("Assembly")) mapperAssembly = ReaderXml.Value.Trim(); if (ReaderXml.MoveToAttribute("Class")) mapperClass = ReaderXml.Value.Trim(); // Was this enabled? bool enabled = true; if (ReaderXml.MoveToAttribute("Default")) { if (String.Compare(ReaderXml.Value, "false", StringComparison.OrdinalIgnoreCase) == 0) { enabled = false; } } // Add this (if enabled) to the list of mappers if (enabled) { string error; // IBriefItemMapper mapper = get_or_create_mapper(mapperAssembly, mapperClass, MappingObjDictionary, out error); BriefItemMapping_Mapper mapperConfig = new BriefItemMapping_Mapper { Assembly = mapperAssembly, Class = mapperClass, Enabled = true, MappingObject = null }; ReturnValue.Mappings.Add(mapperConfig); } break; } } } }