示例#1
0
        /// <summary>
        /// Sets up a watcher for <see cref="Enabled"/> that either creates or
        /// destroys the XML database watchers.
        /// </summary>
        public void Initialize()
        {
            if (!_dir.Exists(DatabasePath))
            {
                _logger.Warn("Invalid database path \"{0}\" for {1}, ignoring.", DatabasePath, this);
                return;
            }

            // watch xml database files and mappings
            this.WhenAnyValue(s => s.Enabled).Subscribe(enabled => {
                // kick off and watch
                if (enabled)
                {
                    // xml database
                    GetDatabaseFiles().ForEach(UpdateGames);
                    EnableDatabaseWatchers();

                    // mappings
                    UpdateOrRemoveMappings(MappingPath);
                    _mappingFileWatcher = _watcher.FileWatcher(MappingPath).Sample(TimeSpan.FromMilliseconds(100)).Subscribe(UpdateOrRemoveMappings);
                }
                else
                {
                    // clear games and destroy watchers
                    GetDatabaseFiles().ForEach(RemoveGames);
                    DisableDatabaseWatchers();
                    _mappingFileWatcher?.Dispose();
                }
            });
        }
示例#2
0
        public IPinballXManager Initialize()
        {
            // todo if we want to support changing pbx folder in the app without restarting, make this dynamic.
            var iniPath = _settingsManager.Settings.PinballXFolder + @"\Config\PinballX.ini";

            // setup game relay
            Systems.ShouldReset.ObserveOn(_threadManager.WorkerScheduler).Subscribe(_ => ResetSystems());
            Systems.ItemsAdded.Subscribe(AddSystem);
            Systems.ItemsRemoved.Subscribe(RemoveSystem);

            // setup table file watcher
            Systems.ShouldReset.ObserveOn(_threadManager.WorkerScheduler).Subscribe(_ => _watcher.WatchTables(Systems));
            Systems.ItemsRemoved.ObserveOn(_threadManager.WorkerScheduler).Subscribe(_ => _watcher.WatchTables(Systems));

            // update systems when ini changes (also, kick it off now)
            _watcher.FileWatcher(iniPath)
            .StartWith(iniPath)                                                 // kick-off without waiting for first file change
            .SubscribeOn(_threadManager.WorkerScheduler)                        // do work on background thread
            .Subscribe(UpdateSystems);

            return(this);
        }