コード例 #1
0
        public DownloadManager(IPinballXManager pinballXManager, IJobManager jobManager, IVpdbManager vpdbManager,
                               ISettingsManager settingsManager, IMessageManager messageManager, IDatabaseManager databaseManager,
                               ILogger logger, CrashManager crashManager)
        {
            _pinballXManager = pinballXManager;
            _jobManager      = jobManager;
            _vpdbManager     = vpdbManager;
            _settingsManager = settingsManager;
            _messageManager  = messageManager;
            _databaseManager = databaseManager;
            _logger          = logger;
            _crashManager    = crashManager;

            // setup download callbacks
            jobManager.WhenDownloaded.Subscribe(OnDownloadCompleted);

            // setup flavor matchers as soon as settings are available.
            _settingsManager.Settings.WhenAny(
                s => s.DownloadOrientation,
                s => s.DownloadOrientationFallback,
                s => s.DownloadLighting,
                s => s.DownloadLightingFallback,
                (a, b, c, d) => Unit.Default).Subscribe(_ =>
            {
                _logger.Info("Setting up flavor matchers.");
                _flavorMatchers.Clear();
                _flavorMatchers.Add(new OrientationMatcher(_settingsManager.Settings));
                _flavorMatchers.Add(new LightingMatcher(_settingsManager.Settings));
            });
        }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: xantari/agent
        public GameManager(IPinballXManager pinballXManager, IVpdbClient vpdbClient, IVpdbManager vpdbManager, ISettingsManager
                           settingsManager, IDownloadManager downloadManager, IDatabaseManager databaseManager, IVersionManager versionManager,
                           IMessageManager messageManager, IRealtimeManager realtimeManager, IVisualPinballManager visualPinballManager,
                           IThreadManager threadManager, IJobManager jobManager, IFile file, ILogger logger)
        {
            _pinballXManager      = pinballXManager;
            _vpdbClient           = vpdbClient;
            _vpdbManager          = vpdbManager;
            _settingsManager      = settingsManager;
            _downloadManager      = downloadManager;
            _databaseManager      = databaseManager;
            _versionManager       = versionManager;
            _messageManager       = messageManager;
            _realtimeManager      = realtimeManager;
            _visualPinballManager = visualPinballManager;
            _threadManager        = threadManager;
            _file       = file;
            _logger     = logger;
            _jobManager = jobManager;


            // update releases from VPDB on the first run, but delay it a bit so it
            // doesn't do all that shit at the same time!
            _settingsManager.ApiAuthenticated
            .Where(user => user != null)
            .Take(1)
            .Delay(TimeSpan.FromSeconds(2))
            .Subscribe(_ => UpdateReleaseData());

            // subscribe to downloaded releases
            _downloadManager.WhenReleaseDownloaded.Subscribe(OnReleaseDownloaded);

            // link games if new games are added
            //Games.Changed.Subscribe(_ => CheckGameLinks());

            // when game is linked or unlinked, update profile with channel info

            /*IDisposable gameLinked = null;
             * Games.Changed.Subscribe(_ => {
             *      gameLinked?.Dispose();
             *      gameLinked = Games
             *              .Select(g => g.Changed.Where(x => x.PropertyName == "ReleaseId"))
             *              .Merge()
             *              .Subscribe(__ => UpdateChannelConfig());
             * });*/

            // setup pusher messages
            SetupRealtime();
        }
コード例 #3
0
        /// <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);
                }
            });
        }