Beispiel #1
0
        public void Initialize()
        {
            // settings must be initialized before doing this.
            if (string.IsNullOrEmpty(_settingsManager.Settings.ApiKey))
            {
                throw new InvalidOperationException("Must initialize settings before game manager.");
            }

            _databaseManager.Initialize();
            _pinballXManager.Initialize();
            _vpdbClient.Initialize();
            _versionManager.Initialize();
            _jobManager.Initialize();
            _initialized.OnNext(Unit.Default);

            var delay = TimeSpan.FromMilliseconds(500);               // let props update first

            // setup handlers for table file changes TODO implement properly (specially rename)
            _pinballXManager.TableFileCreated.ObserveOn(_threadManager.WorkerScheduler).Subscribe(OnTableFileChanged);
            _pinballXManager.TableFileChanged.ObserveOn(_threadManager.WorkerScheduler).Subscribe(OnTableFileChanged);
            _pinballXManager.TableFileDeleted.ObserveOn(_threadManager.WorkerScheduler).Subscribe(OnTableFileDeleted);
            _pinballXManager.TableFileRenamed.ObserveOn(_threadManager.WorkerScheduler).Subscribe(x => OnTableFileRenamed(x.Item1, x.Item2));
            _pinballXManager.TableFolderAdded.ObserveOn(_threadManager.WorkerScheduler).Delay(delay).Subscribe(path => MergeLocalFiles(path, _pinballXManager.GetTableFiles(path)));
            _pinballXManager.TableFolderRemoved.ObserveOn(_threadManager.WorkerScheduler).Delay(delay).Subscribe(path => MergeLocalFiles(path, new List <string>()));

            // setup handler for xml database changes
            _pinballXManager.GamesUpdated.Subscribe(d => MergeXmlGames(d.Item1, d.Item2, d.Item3));

            // setup handler for Matching changes
            _pinballXManager.MappingsUpdated.Subscribe(d => MergeMappings(d.Item1, d.Item2));

            // validate settings and retrieve profile
            Task.Run(async() => await _settingsManager.Validate(_settingsManager.Settings, _messageManager));
        }