/// <summary>Save data fetched for a mod.</summary> /// <param name="mod">The mod data.</param> public CachedMod SaveMod(CachedMod mod) { string id = this.NormalizeId(mod.ID); this.Mods.ReplaceOne( entry => entry.ID == id && entry.Site == mod.Site, mod, new ReplaceOptions { IsUpsert = true } ); return(mod); }
/********* ** 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); }
/// <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)); }
/// <summary>Save data fetched for a mod.</summary> /// <param name="mod">The mod data.</param> public CachedMod SaveMod(CachedMod mod) { string key = this.GetKey(mod.Site, mod.ID); return(this.Mods[key] = mod); }
/// <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)); }