コード例 #1
0
        private void hostingWatcher_Changed(FileSystemEventArgs e)
        {
            var content = File.ReadAllText(e.FullPath);

            Hosting = JsonConvert.DeserializeObject <Hosting>(content);

            if (Hosting == null)
            {
                throw new ArgumentException("Settings file invalid: " + e.FullPath);
            }

            if (_settingsWatcher != null)
            {
                _settingsWatcher.Dispose();
            }

            var settingsPath = Combine(_settingsFilePath);

            _settingsWatcher = new Mark.FileWatcher.FileWatcher(settingsPath);
            _settingsWatcher.AddChangedListener(settingsWatcher, true);
        }
コード例 #2
0
        public SettingsContext(string settingsFileName = "app.json", string settingsPath = "settings")
        {
            if (string.IsNullOrWhiteSpace(settingsFileName))
            {
                throw new ArgumentNullException("filename");
            }

            if (string.IsNullOrWhiteSpace(settingsPath))
            {
                throw new ArgumentNullException("settingsPath");
            }

            _settingsFilePath = settingsFileName;

            if (Path.IsPathRooted(settingsPath))
            {
                _rootPath = settingsPath;
            }
            else
            {
                _rootPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, settingsPath);
            }

            var hostingPath = Path.Combine(_rootPath, "hosting.json");

            if (File.Exists(hostingPath))
            {
                _hostingWatcher = new FileWatcher.FileWatcher(hostingPath);
                _hostingWatcher.AddChangedListener(hostingWatcher_Changed, true);
            }
            else
            {
                Hosting = new Hosting();
                var settingsFilePath = Combine(_settingsFilePath);
                _settingsWatcher = new Mark.FileWatcher.FileWatcher(settingsFilePath);
                _settingsWatcher.AddChangedListener(settingsWatcher, true);
            }
        }