Ejemplo n.º 1
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="rawText">The raw update key text.</param>
 /// <param name="repository">The mod repository containing the mod.</param>
 /// <param name="id">The mod ID within the repository.</param>
 public UpdateKey(string rawText, ModRepositoryKey repository, string id)
 {
     this.RawText    = rawText;
     this.Repository = repository;
     this.ID         = id;
     this.LooksValid =
         repository != ModRepositoryKey.Unknown &&
         !string.IsNullOrWhiteSpace(id);
 }
Ejemplo n.º 2
0
        /*********
        ** Public methods
        *********/
        /// <summary>Get the cached mod data.</summary>
        /// <param name="site">The mod site to search.</param>
        /// <param name="id">The mod's unique ID within the <paramref name="site"/>.</param>
        /// <param name="mod">The fetched mod.</param>
        /// <param name="markRequested">Whether to update the mod's 'last requested' date.</param>
        public bool TryGetMod(ModRepositoryKey site, string id, out CachedMod mod, bool markRequested = true)
        {
            // get mod
            if (!this.Mods.TryGetValue(this.GetKey(site, id), out mod))
            {
                return(false);
            }

            // bump 'last requested'
            if (markRequested)
            {
                mod.LastRequested = DateTimeOffset.UtcNow;
                mod = this.SaveMod(mod);
            }

            return(true);
        }
        /*********
        ** Public methods
        *********/
        /// <summary>Get the cached mod data.</summary>
        /// <param name="site">The mod site to search.</param>
        /// <param name="id">The mod's unique ID within the <paramref name="site"/>.</param>
        /// <param name="mod">The fetched mod.</param>
        /// <param name="markRequested">Whether to update the mod's 'last requested' date.</param>
        public bool TryGetMod(ModRepositoryKey site, string id, out CachedMod mod, bool markRequested = true)
        {
            // get mod
            id  = this.NormalizeId(id);
            mod = this.Mods.Find(entry => entry.ID == id && entry.Site == site).FirstOrDefault();
            if (mod == null)
            {
                return(false);
            }

            // bump 'last requested'
            if (markRequested)
            {
                mod.LastRequested = DateTimeOffset.UtcNow;
                mod = this.SaveMod(mod);
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>Construct an instance.</summary>
        /// <param name="site">The mod site on which the mod is found.</param>
        /// <param name="id">The mod's unique ID within the <paramref name="site"/>.</param>
        /// <param name="mod">The mod data.</param>
        public CachedMod(ModRepositoryKey site, string id, ModInfoModel mod)
        {
            // tracking
            this.LastUpdated   = DateTimeOffset.UtcNow;
            this.LastRequested = DateTimeOffset.UtcNow;

            // metadata
            this.Site        = site;
            this.ID          = id;
            this.FetchStatus = mod.Status;
            this.FetchError  = mod.Error;

            // mod info
            this.Name           = mod.Name;
            this.MainVersion    = mod.Version;
            this.PreviewVersion = mod.PreviewVersion;
            this.Url            = mod.Url;
            this.LicenseUrl     = mod.LicenseUrl;
            this.LicenseName    = mod.LicenseName;
        }
        /// <summary>Save data fetched for a mod.</summary>
        /// <param name="site">The mod site on which the mod is found.</param>
        /// <param name="id">The mod's unique ID within the <paramref name="site"/>.</param>
        /// <param name="mod">The mod data.</param>
        /// <param name="cachedMod">The stored mod record.</param>
        public void SaveMod(ModRepositoryKey site, string id, ModInfoModel mod, out CachedMod cachedMod)
        {
            id = this.NormalizeId(id);

            cachedMod = this.SaveMod(new CachedMod(site, id, mod));
        }
Ejemplo n.º 6
0
 /*********
 ** Protected methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="vendorKey">The unique key for this vendor.</param>
 protected RepositoryBase(ModRepositoryKey vendorKey)
 {
     this.VendorKey = vendorKey;
 }
Ejemplo n.º 7
0
 /// <summary>Construct an instance.</summary>
 /// <param name="repository">The mod repository containing the mod.</param>
 /// <param name="id">The mod ID within the repository.</param>
 public UpdateKey(ModRepositoryKey repository, string id)
     : this($"{repository}:{id}", repository, id)
 {
 }
Ejemplo n.º 8
0
 /*********
 ** Private methods
 *********/
 /// <summary>Get a cache key.</summary>
 /// <param name="site">The mod site.</param>
 /// <param name="id">The mod ID.</param>
 public string GetKey(ModRepositoryKey site, string id)
 {
     return($"{site}:{id.Trim()}".ToLower());
 }
Ejemplo n.º 9
0
        /// <summary>Save data fetched for a mod.</summary>
        /// <param name="site">The mod site on which the mod is found.</param>
        /// <param name="id">The mod's unique ID within the <paramref name="site"/>.</param>
        /// <param name="mod">The mod data.</param>
        /// <param name="cachedMod">The stored mod record.</param>
        public void SaveMod(ModRepositoryKey site, string id, ModInfoModel mod, out CachedMod cachedMod)
        {
            string key = this.GetKey(site, id);

            cachedMod = this.SaveMod(new CachedMod(site, id, mod));
        }