private static Dictionary <string, MappingItem> GetDictionary(string filePath, bool isOverride) { Dictionary <string, MappingItem> dict = new Dictionary <string, MappingItem>(); try { // If file exists, use streamreader to load mappings into dictionary using (StreamReader sr = new StreamReader(filePath)) { string line; while ((line = sr.ReadLine()) != null) { string[] parts = line.Split('|'); // Lowercase c-codes (for comparison to codes from URL parameters later) parts[0] = parts[0].ToLower(); // Sort c-codes alphabetically/numerically if there are multiple if (parts[0].Contains(",")) { string[] split = parts[0].Split(','); Array.Sort(split); string newKey = string.Join(",", split); parts[0] = newKey; } // Create MappingItem object for mapping MappingItem item = new MappingItem(); item.Codes = parts[0].Split(',').ToList(); item.Text = parts[1]; item.IsOverride = isOverride; // Add mapping to dictionary if it isn't already present if (!dict.ContainsKey(parts[0])) { dict.Add(parts[0], item); } } } } catch (Exception ex) { LogManager.GetLogger(typeof(DynamicTrialListingMappingService)).ErrorFormat("Error while getting the mapping file.", ex); } return(dict); }
private static Dictionary <string, MappingItem> LoadDictionaryMappingFromFiles(string evsFilePath, string overrideFilePath, bool withOverrides) { Dictionary <string, MappingItem> dict = new Dictionary <string, MappingItem>(); if (!withOverrides) { try { // If file exists, use streamreader to load EVS mappings into dictionary using (StreamReader sr = new StreamReader(evsFilePath)) { string line; while ((line = sr.ReadLine()) != null) { line = line.ToLower(); string[] parts = line.Split('|'); // Lowercase c-codes (for comparison to codes from URL parameters later) parts[0] = parts[0].ToLower(); // Sort c-codes alphabetically/numerically if there are multiple if (parts[0].Contains(",")) { string[] split = parts[0].Split(','); Array.Sort(split); string newKey = string.Join(",", split); parts[0] = newKey; } // Create MappingItem object for mapping MappingItem item = new MappingItem(); item.Codes = parts[0].Split(',').ToList(); item.Text = parts[1]; item.IsOverride = false; // Add mapping to dictionary if it isn't already present if (!dict.ContainsKey(parts[0])) { dict.Add(parts[0], item); } } } } catch { // Log an error if the file exists but cannot be read. // Do not make the page error out - we want the dictionaries to still work, // even if there is something wrong with the friendly name mapping file. LogManager.GetLogger(typeof(DynamicTrialListingFriendlyNameMappingService)).ErrorFormat("Mapping file '{0}' could not be read.", evsFilePath); } } else { // Log an error if the file does not exist. // Do not make the page error out - we want the dictionaries to still work, // even if there is something wrong with the friendly name mapping file. LogManager.GetLogger(typeof(DynamicTrialListingFriendlyNameMappingService)).ErrorFormat("Error while getting the mapping file located at '{0}'.", evsFilePath); } if (withOverrides) { try { // If file exists and we need overrides, use streamreader to load override mappings into dictionary using (StreamReader sr = new StreamReader(overrideFilePath)) { string line; while ((line = sr.ReadLine()) != null) { line = line.ToLower(); string[] parts = line.Split('|'); // Lowercase c-codes (for comparison to codes from URL parameters later) parts[0] = parts[0].ToLower(); // Sort c-codes alphabetically/numerically if there are multiple if (parts[0].Contains(",")) { string[] split = parts[0].Split(','); Array.Sort(split); string newKey = string.Join(",", split); parts[0] = newKey; } // Create MappingItem object for mapping MappingItem item = new MappingItem(); item.Codes = parts[0].Split(',').ToList(); item.Text = parts[1]; item.IsOverride = true; if (!dict.ContainsKey(parts[0])) { // Add override mapping to dictionary if it isn't already present dict.Add(parts[0], item); } } } } catch { // Log an error if the file exists but cannot be read. // Do not make the page error out - we want the dictionaries to still work, // even if there is something wrong with the friendly name mapping file. LogManager.GetLogger(typeof(DynamicTrialListingFriendlyNameMappingService)).ErrorFormat("Mapping file '{0}' could not be read.", overrideFilePath); } } else { // Log an error if the file does not exist. // Do not make the page error out - we want the dictionaries to still work, // even if there is something wrong with the friendly name mapping file. LogManager.GetLogger(typeof(DynamicTrialListingFriendlyNameMappingService)).ErrorFormat("Error while getting the mapping file located at '{0}'.", overrideFilePath); } return(dict); }