/// <summary> /// Initialize a new instance of UpdateServerStartup. /// </summary> /// <param name="config"> /// <para>ASP.NET configuration.</para> /// <list type="bullet"> /// <item><description>Required: string entry "metadata-source" with the path to file containing updates metadata.</description></item> /// <item><description>Required: string entry "server-config" containing the server configuration in JSON format. A reference server configuration file is provided.</description></item> /// <item><description>Optional: string entry "content-source" containing the path where update content is stored.</description></item> /// <item><description>Optional: string entry "content-http-root" with the root URL where update content is serverd from (e.g. http://my-update-server.com). Usually this set to the address/name of the server. Required if "content-source" is specified.</description></item> /// </list> /// </param> public UpdateServerStartup(IConfiguration config) { // Get the repository path from the configuration var metadataSourceFile = config.GetValue <string>("metadata-source"); MetadataSource = CompressedMetadataStore.Open(metadataSourceFile); if (MetadataSource == null) { throw new System.Exception($"Cannot open updates metadata source from path {metadataSourceFile}"); } UpdateServiceConfiguration = Newtonsoft.Json.JsonConvert.DeserializeObject <Config>(config.GetValue <string>("server-config")); // A file that contains mapping of update identity to a 32 bit, locally assigned revision ID. var contentPath = config.GetValue <string>("content-source"); if (!string.IsNullOrEmpty(contentPath)) { ContentSource = new FileSystemContentStore(contentPath); if (ContentSource == null) { throw new System.Exception($"Cannot open updates content source from path {contentPath}"); } } ContentRoot = config.GetValue <string>("content-http-root"); }
/// <summary> /// Initialize a new instance of UpstreamServerStartup. /// </summary> /// <param name="config"> /// <para>ASP.NET configuration.</para> /// /// <para>Must contain a string entry "metadata-path" with the path to the metadata source to use</para> /// /// <para>Must contain a string entry "updates-filter" with a JSON serialized updates metadata filter</para> /// /// <para>Must contain a string entry "service-config-path" with the path to the service configuration JSON</para> /// /// <para>Can contain a string entry "content-path" with the path to the content store to use if serving update content</para> /// </param> public UpstreamServerStartup(IConfiguration config) { // Get the metadata source path from the configuration var sourcePath = config.GetValue <string>("metadata-path"); var contentPath = config.GetValue <string>("content-path"); // Get the filteres to apply to updates; restricts which updates are shared with downstream servers Filter = MetadataFilter.FromJson(config.GetValue <string>("updates-filter")); // Open the updates metadata source. It must exist LocalMetadataSource = CompressedMetadataStore.Open(sourcePath); if (LocalMetadataSource == null) { throw new System.Exception($"Cannot open the specified metadata source at {sourcePath}"); } var serviceConfigPath = config.GetValue <string>("service-config-path"); ServiceConfiguration = JsonConvert.DeserializeObject <ServerSyncConfigData>( File.OpenText(serviceConfigPath).ReadToEnd()); if (!string.IsNullOrEmpty(contentPath)) { LocalContentSource = new FileSystemContentStore(contentPath); ServiceConfiguration.CatalogOnlySync = false; } else { ServiceConfiguration.CatalogOnlySync = true; } }
internal ContentController(IMetadataSource metadataSource, IUpdateContentSource contentSource, MetadataFilter filter) { MetadataSource = metadataSource; ContentSource = contentSource; var updatesWithFiles = MetadataSource.GetUpdates(filter).Where(u => u.HasFiles); UpdateFiles = updatesWithFiles.SelectMany(u => u.Files).Distinct().ToDictionary( f => $"{f.GetContentDirectoryName().ToLower()}/{f.Digests[0].HexString.ToLower() + System.IO.Path.GetExtension(f.FileName).ToLower()}"); }
/// <summary> /// Create a content controller from the specified metadata and update content sources. /// </summary> /// <param name="metadataSource">The source of update metadata. Used to build the list of known files to serve.</param> /// <param name="contentSource">The source of content. Used to read update content and send it to clients.</param> public ClientSyncContentController(IMetadataSource metadataSource, IUpdateContentSource contentSource) { ContentSource = contentSource; var updatesWithFiles = metadataSource.GetUpdates().Where(u => u.HasFiles).ToList(); UpdateFiles = updatesWithFiles.SelectMany(u => u.Files).GroupBy(f => f.Digests[0].DigestBase64).Select(g => g.First()).ToDictionary( f => { // TODO: fix; hack; this is an internal implementation detail; must be exposed from server-server-sync library byte[] hashBytes = Convert.FromBase64String(f.Digests[0].DigestBase64); var cachedContentDirectoryName = string.Format("{0:X}", hashBytes.Last()); return($"{cachedContentDirectoryName.ToLower()}/{f.Digests[0].HexString.ToLower()}"); }); }