/// <summary> /// Add entry into the configuration. /// </summary> /// <param name="key">key of the entry.</param> /// <param name="value">value to use.</param> /// <returns>boolean of success/failure.</returns> public bool Add(IConfigItem configItem) { if (_memoryCacheService.Contains(configItem.key)) { throw new DuplicateKeyException(string.Format("Configuration key already exists {0}", configItem.key)); } if (Monitor.TryEnter(_lockObject)) { try { Thread.Sleep(5000); _memoryCacheService.Add(configItem); _fileManager.AddEntry(configItem); } catch (Exception e) { if (_memoryCacheService.Contains(configItem.key)) { _memoryCacheService.Remove(configItem.key); } throw new ConfigAddException(string.Format("Configuration add failed for key {0}", configItem.key)); } finally { Monitor.Exit(_lockObject); } } else { throw new ResourceLockedException(string.Format("Resource locked while adding config item {0}", configItem.key)); } return(true); }