Пример #1
0
        public SettingsRoot GetSettings()
        {
            try
            {
                _available.WaitOne();
            }
            catch (AbandonedMutexException e)
            {
                _log.Warn("Failed to acquire semaphore lock when loading settings.", e);
                return(null);
            }

            try
            {
                // If the settings have already been populated then return them
                if (_settingsRoot != null)
                {
                    _available.Release();
                    return(_settingsRoot);
                }

                _settingsRoot = _settingsRepository.Load();
                if (_settingsRoot == null)
                {
                    _settingsRoot = _settingsRepository.CreateNewSettings();
                    try
                    {
                        _settingsRepository.Save(_settingsRoot);
                    }
                    catch (Exception ex)
                    {
                        _log.Warn("Saving new settings failed.", ex);
                    }
                }

                _available.Release();
            }
            catch (Exception)
            {
                _available.Release();
                throw;
            }

            return(_settingsRoot);
        }