public void MapGame(AggregatedGame game, VpdbRelease release, string fileId) { // update in case we didn't catch the last version. _vpdbManager.GetRelease(release.Id).Subscribe(updatedRelease => { _logger.Info("Mapping {0} to {1} ({2})", game, release, fileId); GetOrCreateMapping(game).Map(release, fileId); }, exception => _vpdbClient.HandleApiError(exception, "retrieving release details during linking")); }
/// <summary> /// Base constructor /// </summary> /// <param name="resolver">Dependency resolver</param> private AggregatedGame(IDependencyResolver resolver) { _file = resolver.GetService <IFile>(); _logger = resolver.GetService <ILogger>(); _vpdbManager = resolver.GetService <IVpdbManager>(); _jobManager = resolver.GetService <IJobManager>(); // status props this.WhenAnyValue(x => x.Mapping).Select(x => x != null).ToProperty(this, g => g.HasMapping, out _hasMapping); this.WhenAnyValue(x => x.FilePath).Select(x => x != null).ToProperty(this, g => g.HasLocalFile, out _hasLocalFile); this.WhenAnyValue(x => x.XmlGame).Select(x => x != null).ToProperty(this, g => g.HasXmlGame, out _hasXmlGame); // filename (from pinballx database if set, otherwise from local file) this.WhenAnyValue(x => x.XmlGame).Subscribe(xmlGame => { if (xmlGame == null) { this.WhenAnyValue(g => g.FilePath) .Select(Path.GetFileName) .ToProperty(this, game => game.FileName, out _fileName); } else { this.WhenAnyValue(x => x.FilePath, x => x.XmlGame.FileName) .Select(x => x.Item1 != null ? Path.GetFileName(x.Item1) : x.Item2) .ToProperty(this, game => game.FileName, out _fileName); } }); // visibility (invisible if disabled in pinballx or hidden in mapping) this.WhenAnyValue(x => x.XmlGame, x => x.Mapping).Subscribe(x => { if (x.Item1 != null && x.Item2 != null) { this.WhenAnyValue(g => g.XmlGame.Enabled, g => g.Mapping.IsHidden) .Select(y => (y.Item1 == null || "true".Equals(y.Item1, StringComparison.InvariantCultureIgnoreCase)) && !y.Item2) .ToProperty(this, game => game.IsVisible, out _isVisible); } else if (x.Item1 == null && x.Item2 != null) { this.WhenAnyValue(g => g.Mapping.IsHidden) .Select(isHidden => !isHidden) .ToProperty(this, game => game.IsVisible, out _isVisible); } else if (x.Item1 != null && x.Item2 == null) { this.WhenAnyValue(g => g.XmlGame.Enabled) .Select(enabled => enabled == null || "true".Equals(enabled, StringComparison.InvariantCultureIgnoreCase)) .ToProperty(this, game => game.IsVisible, out _isVisible); } else { Observable.Return(true).ToProperty(this, game => game.IsVisible, out _isVisible); } }); // populate mappings this.WhenAnyValue(x => x.Mapping).Subscribe(mapping => { if (mapping == null) { MappedTableFile = null; MappedVersion = null; MappedRelease = null; Observable.Return((Job)null).ToProperty(this, game => game.MappedJob, out _mappedJob); } else { // vpdb mappings mapping .WhenAnyValue(m => m.FileId, m => m.ReleaseId) .Where(x => x.Item1 != null && x.Item2 != null) .SelectMany(x => _vpdbManager.GetRelease(mapping.ReleaseId)) .Subscribe(x => SetRelease(x, mapping.FileId)); // job mapping.WhenAnyValue(m => m.JobId) .Where(jobId => jobId != null && jobId != 0) .Select(jobId => _jobManager.CurrentJobs.FirstOrDefault(job => job.Id == jobId)) .ToProperty(this, game => game.MappedJob, out _mappedJob); } }); // download status this.WhenAnyValue(x => x.MappedJob).Subscribe(job => { if (job != null) { job.WhenAnyValue(j => j.Status) .Select(status => status == Job.JobStatus.Transferring) .ToProperty(this, game => game.IsDownloading, out _isDownloading); job.WhenAnyValue(j => j.Status) .Select(status => status == Job.JobStatus.Queued) .ToProperty(this, game => game.IsQueued, out _isQueued); } else { Observable.Return(false).ToProperty(this, game => game.IsDownloading, out _isDownloading); Observable.Return(false).ToProperty(this, game => game.IsQueued, out _isQueued); } }); }