/// <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; } }
/// <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> /// Runs the sync command /// </summary> /// <param name="options">Fetch command options</param> public static void FetchUpdates(FetchUpdatesOptions options) { Endpoint upstreamEndpoint; CompressedMetadataStore baselineSource; Console.WriteLine("Opening query results file"); baselineSource = CompressedMetadataStore.Open(options.MetadataSourcePath); if (baselineSource == null) { ConsoleOutput.WriteRed("Cannot open the query result file!"); return; } ConsoleOutput.WriteGreen("Done!"); upstreamEndpoint = baselineSource.UpstreamSource; // The filter to apply when fetching updates QueryFilter queryToRun = null; queryToRun = baselineSource.Filters.FirstOrDefault(); if (queryToRun != null) { ConsoleOutput.WriteCyan("Using the filter from the baseline source. Command line filters are ignored!"); } if (queryToRun == null) { // A new query will be created based on command line options try { queryToRun = MetadataSync.CreateValidFilterFromOptions(options, baselineSource); } catch (Exception ex) { ConsoleOutput.WriteRed(ex.Message); return; } } using (var syncResult = new CompressedMetadataStore(baselineSource)) { if (!string.IsNullOrEmpty(options.AccountName) && !string.IsNullOrEmpty(options.AccountGuid)) { if (!Guid.TryParse(options.AccountGuid, out Guid accountGuid)) { ConsoleOutput.WriteRed("The account GUID must be a valid GUID string"); return; } syncResult.SetUpstreamCredentials(options.AccountName, accountGuid); } FetchUpdates(queryToRun, syncResult); } }
/// <summary> /// Opens an updates metadata source the path specified on the command line /// </summary> /// <param name="sourceOptions">The command line switch that contains the path</param> /// <returns>A open updates metadata source</returns> public static IMetadataSource LoadMetadataSourceFromOptions(IMetadataSourceOptions sourceOptions) { IMetadataSource source = null; Console.Write("Opening update metadata source file... "); try { source = CompressedMetadataStore.Open(sourceOptions.MetadataSourcePath); ConsoleOutput.WriteGreen("Done!"); } catch (Exception ex) { Console.WriteLine(); ConsoleOutput.WriteRed("Cannot open the query result file:"); ConsoleOutput.WriteRed(ex.Message); } return(source); }