private void AddOrUpdateConfiguredPMode(string fullPath) { lock (__cacheLock) { if (_fileEventCache.Contains(fullPath)) { Logger.Trace($"{PModeName} {fullPath} has already been handled."); return; } _fileEventCache.Add(fullPath, fullPath, _policy); } T pmode = TryDeserialize(fullPath); if (pmode == null) { Logger.Warn($"File at: \'{fullPath}\' cannot be converted to a {PModeName} because the XML in the file isn\'t valid."); // Since the PMode that we expect in this file is invalid, it // must be removed from our cache. RemoveLocalPModeFromCache(fullPath); return; } ValidationResult pmodeValidation = _pmodeValidator.Validate(pmode); if (!pmodeValidation.IsValid) { Logger.Warn($"Invalid {PModeName} at: \'{fullPath}\'"); pmodeValidation.LogErrors(LogManager.GetCurrentClassLogger()); // Since the PMode that we expect isn't valid according to the validator, it // must be removed from our cache. RemoveLocalPModeFromCache(fullPath); return; } var configuredPMode = new ConfiguredPMode(fullPath, pmode); if (_pmodes.ContainsKey(pmode.Id)) { Logger.Warn($"Existing PMode {pmode.Id} will be overwritten with PMode from {fullPath}"); } else { Logger.Trace($"Add new {PModeName} with Id: " + pmode.Id); } _pmodes.AddOrUpdate(pmode.Id, configuredPMode, (key, value) => configuredPMode); _filePModeIdMap.AddOrUpdate(fullPath, pmode.Id, (key, value) => pmode.Id); }
private static ConfiguredPMode GetPModeEntry <T>(string id, PModeWatcher <T> watcher) where T : class, IPMode { if (String.IsNullOrEmpty(id)) { throw new KeyNotFoundException($"Given {typeof(T).Name} key is null"); } ConfiguredPMode entry = watcher.GetPModeEntry(id); if (entry == null) { throw new ConfigurationErrorsException($"No {typeof(T).Name} found for {id}"); } return(entry); }