private static ClusterConfigClientSettings Initialize() { try { var folder = FolderLocator.Locate(AppDomain.CurrentDomain.BaseDirectory, ClusterConfigClientDefaults.LocalFolder); if (!folder.Exists) { return(Default); } var file = new FileInfo(Path.Combine(folder.FullName, ClusterConfigClientDefaults.ConfigurationFile)); if (!file.Exists) { return(Default); } var fileParser = new FileParser(new FileParserSettings()); var fileSettings = fileParser.Parse(file); if (fileSettings == null) { return(Default); } var settings = new ClusterConfigClientSettings(); ConfigurationFileHelper.Apply(fileSettings, settings); return(settings); } catch { return(Default); } }
/// <summary> /// Creates a new instance of <see cref="ClusterConfigClient"/> with given <paramref name="settings"/> merged with default settings from <see cref="DefaultSettingsProvider"/> (non-default user settings take priority). /// </summary> public ClusterConfigClient([NotNull] ClusterConfigClientSettings settings) { this.settings = settings = ConfigurationMerger.Merge(DefaultSettingsProvider.Settings, settings ?? throw new ArgumentNullException(nameof(settings))); log = settings.Log.ForContext <ClusterConfigClient>(); stateSource = new TaskCompletionSource <ClusterConfigClientState>(TaskCreationOptions.RunContinuationsAsynchronously); stateObservable = new CachingObservable <ClusterConfigClientState>(); clientState = new AtomicInt(State_NotStarted); cancellationSource = new CancellationTokenSource(); observablePropagationLock = new object(); }