示例#1
0
文件: Job.cs 项目: xantari/agent
 /// <summary>
 /// Constructor called when creating a new job through the application for
 /// downloading a table file.
 /// </summary>
 /// <param name="release">Release to be downloaded</param>
 /// <param name="tableFile">File of the release to be downloaded</param>
 /// <param name="filetype">Where does this end up?</param>
 /// <param name="platform">Platform the file belongs to</param>
 public Job(VpdbRelease release, VpdbTableFile tableFile, FileType filetype, VpdbTableFile.VpdbPlatform platform) : this(release, tableFile.Reference)
 {
     FileType = filetype;
     Thumb    = tableFile.Thumb;
     Platform = platform;
     _logger.Info("Creating new release download job for {0} {1}.", filetype, File.Uri.AbsoluteUri);
 }
示例#2
0
 public PinballXSystem FindSystem(VpdbTableFile tableFile)
 {
     if (tableFile?.Compatibility == null || tableFile.Compatibility.Count == 0)
     {
         return(null);
     }
     return(FindSystem(tableFile.Compatibility[0].Platform));
 }
示例#3
0
        public int Weight(VpdbTableFile tableFile, VpdbTableFile currentFile)
        {
            var weight = Weight(tableFile.Flavor, PrimarySetting, currentFile?.Flavor, null) * 100;

            if (weight == 0)
            {
                weight = Weight(tableFile.Flavor, FallbackSetting, currentFile?.Flavor, PrimarySetting);
            }
            return(weight);
        }
示例#4
0
        public GameResultItemViewModel(AggregatedGame game, VpdbRelease release, VpdbVersion version, VpdbTableFile tableFile, ICommand closeCommand)
        {
            Game      = game;
            Version   = version;
            Release   = release;
            TableFile = tableFile;

            SelectResult = ReactiveCommand.Create(() => {
                GameManager.MapGame(game, release, tableFile.Reference.Id);
                //MessageManager.LogReleaseLinked(game, release, tableFile.Reference.Id);

                closeCommand.Execute(null);
            });
        }
示例#5
0
 /// <summary>
 /// Sets VPDB release data when mapping data is available.
 /// </summary>
 /// <param name="release"></param>
 /// <param name="fileId"></param>
 private void SetRelease(VpdbRelease release, string fileId)
 {
     MappedRelease   = release;
     MappedVersion   = release.GetVersion(fileId);
     MappedTableFile = release.GetFile(fileId);
 }
示例#6
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);
                }
            });
        }
示例#7
0
 public bool Matches(VpdbTableFile tableFile, VpdbTableFile currentFile)
 {
     return(Weight(tableFile, currentFile) > 0);
 }
示例#8
0
 /// <summary>
 /// Calculates the total weight of a file based on flavor settings.
 /// </summary>
 /// <param name="tableFile">File to check</param>
 /// <param name="currentFile">The current/previous file of the release or null if new release</param>
 /// <returns>Total weight of the file based on the user's flavor settings</returns>
 private int FlavorWeight(VpdbTableFile tableFile, VpdbTableFile currentFile)
 {
     return(_flavorMatchers.Sum(matcher => matcher.Weight(tableFile, currentFile)));
 }
示例#9
0
 /// <summary>
 /// Checks if the flavor of the file is acceptable by the user's flavor settings.
 /// </summary>
 /// <param name="tableFile">File to check</param>
 /// <param name="currentFile">The current/previous file of the release or null if new release</param>
 /// <returns>Returns true if the primary or secondary flavor setting of ALL flavors matches, false otherwise.</returns>
 private bool FlavorMatches(VpdbTableFile tableFile, VpdbTableFile currentFile)
 {
     return(_flavorMatchers.TrueForAll(matcher => matcher.Matches(tableFile, currentFile)));
 }