/// <summary> /// Saves the app update manifest. /// </summary> /// <exception cref="NullReferenceException">Thrown when the <see cref="ManifestUri" is null./></exception> /// <exception cref="InvalidOperationException">Thrown when the <see cref="ManifestUri" is not a file URI/></exception> public void Save() { if (ManifestUri == null) { throw new NullReferenceException($"The '{nameof(ManifestUri)}' cannot be null."); } if (!ManifestUri.IsFile) { throw new InvalidOperationException("The update manifest cannot be saved because it's not a file URI."); } _logger.LogInformation($"Saving manifest to '{ManifestUri.ToString().ToLower()}'."); lock (_lockObject) File.WriteAllText(ManifestUri.LocalPath, JsonConvert.SerializeObject(Applications, Formatting.Indented)); }
/// <summary> /// Loads the app update manifest. /// </summary> /// <exception cref="NullReferenceException">Thrown when the <see cref="ManifestUri" is null./></exception> /// <exception cref="FileNotFoundException">Thrown when the <see cref="ManifestUri" is a file URI and the file is not found./></exception> /// <exception cref="HttpRequestException">Thrown when the <see cref="ManifestUri" is a http or https URI and the resource is not found./></exception> public async Task Load() { if (ManifestUri == null) { throw new NullReferenceException($"The '{nameof(ManifestUri)}' cannot be null."); } var version = (((AssemblyInformationalVersionAttribute)GetType().Assembly.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute))).InformationalVersion); _logger.LogInformation($"Update Manager v{version} loading manifest from '{ManifestUri.ToString().ToLower()}'."); if (ManifestUri.IsFile) { if (File.Exists(ManifestUri.LocalPath)) { Applications = JsonConvert.DeserializeObject <List <Application> >(File.ReadAllText(ManifestUri.LocalPath)); } } else { using (var client = new HttpClient()) Applications = JsonConvert.DeserializeObject <List <Application> >(await client.GetStringAsync(ManifestUri)); } // Hook up our hierarchy. foreach (var app in Applications) { app.UpdateManager = this; foreach (var package in app.Packages) { package.Application = app; } } // for each app. IsLoaded = true; }
public override string ToString() => $"Manifest: {ManifestUri.ToString().ToLower()} Applications: {Applications.Count}";