private async Task LoadExtendedInformation(CupKey key, string registry) { try { var data = JsonConvert.DeserializeObject <CupInformation>(await Cache.GetStringAsync($"{registry}/{key.Type.ToString().ToLowerInvariant()}/{key.Id}")); data.SourceRegistry = registry.ApartFromLast("/"); data.IsExtendedLoaded = true; RegisterLatestVersion(key, data); } catch (Exception e) { Logging.Warning(e); } }
private void RegisterLatestVersion([NotNull] CupKey key, [NotNull] CupInformation information) { Logging.Debug("New update: " + key + information); if (_storage.Get <bool>($"ignore:{key}") || _storage.Get <bool>($"ignore:{key}:{information.Version}") || _versions.TryGetValue(key, out var existing) && existing.Version.IsVersionNewerThan(information.Version)) { return; } _versions[key] = information; NewLatestVersion?.Invoke(this, new CupEventArgs(key, information)); }
private async Task LoadList(string registry) { var data = await Cache.GetStringAsync($@"{registry}/list"); JObject list; try { list = JObject.Parse(data); } catch (Exception e) { Logging.Warning($"Failed to parse: {data}"); return; } foreach (var p in list) { if (!Enum.TryParse <CupContentType>(p.Key, true, out var type)) { Logging.Warning("Not supported type: " + type); continue; } if (!(p.Value is JObject obj)) { Logging.Warning("Not supported format: " + type); continue; } foreach (var item in obj) { try { var key = new CupKey(type, item.Key); if (item.Value.Type == JTokenType.String) { RegisterLatestVersion(key, new CupInformation((string)item.Value, false, registry)); } else if (item.Value is JObject details) { RegisterLatestVersion(key, new CupInformation((string)details["version"], (bool)details["limited"], registry)); } else { Logging.Warning("Not supported format: " + type + "/" + item.Key); } } catch (Exception e) { Logging.Warning("Not supported format: " + type + "/" + item.Key); Logging.Warning(e); } } } }
public CupInformation GetInformation(CupContentType type, [NotNull] string id) { var key = new CupKey(type, id); if (!_versions.TryGetValue(key, out var data)) { return(null); } if (!data.IsExtendedLoaded) { data.IsExtendedLoaded = true; LoadExtendedInformation(key, data.SourceRegistry).Forget(); } return(data); }
protected bool Equals(CupKey other) { return(Type == other.Type && string.Equals(Id, other.Id)); }