public bool TryGetConfigurationData(string name, IEnumerable<string> environmentSequence, out IConfigurationDataHandle configurationData) { lock(lockObject) { JsonFileConfigurationDataHandle result = null; if ( configurationDataHandles.TryGetValue(name,out result)) { configurationData = result; return true; } var fullFilename = Path.Combine(rootDirectory.FullName, name + "." + extension); if ( System.IO.File.Exists(fullFilename)) { try { var newHandle = new JsonFileConfigurationDataHandle(new FileInfo(fullFilename),name, environmentSequence, maxWaitTime, pollInterval); configurationDataHandles.Add(name,newHandle); configurationData = newHandle; return true; } catch(OperationCanceledException) {} catch(IOException) {} } } configurationData = null; return false; }
public ConfigurationModelHandle(IConfigurationDataHandle dataHandle,Type modelType) { this.dataHandle = dataHandle; this.modelType = modelType; this.model = Map(dataHandle != null ? dataHandle.Data : null); if ( this.model == null ) { throw new InvalidOperationException(string.Format("Unable to read configuration {0} into configuration model {1}",dataHandle.Name,modelType)); } if (this.dataHandle != null) { this.dataHandle.Changed += DataHandleOnChanged; } }
private void DataHandleOnChanged(IConfigurationDataHandle configurationDataHandle) { var newModel = Map(configurationDataHandle.Data); if ( newModel != null ) { Interlocked.Exchange(ref model, newModel); var changedHandler = Changed; if ( changedHandler != null ) { changedHandler(this); } } }