/// <summary>
        /// Export filtered or all update metadata from a source
        /// </summary>
        /// <param name="options">Export options</param>
        public static void ExportUpdates(MetadataSourceExportOptions options)
        {
            var source = Program.LoadMetadataSourceFromOptions(options as IMetadataSourceOptions);

            if (source == null)
            {
                return;
            }

            var filter = FilterBuilder.MetadataFilterFromCommandLine(options as IMetadataFilterOptions);

            if (filter == null)
            {
                return;
            }

            ServerSyncConfigData serverConfig;

            try
            {
                serverConfig = JsonConvert.DeserializeObject <ServerSyncConfigData>(File.ReadAllText(options.ServerConfigFile));
            }
            catch (Exception)
            {
                ConsoleOutput.WriteRed($"Failed to read server configuration file from {options.ServerConfigFile}");
                return;
            }

            (source as CompressedMetadataStore).ExportProgress += LocalSource_ExportOperationProgress;
            source.Export(filter, options.ExportFile, RepoExportFormat.WSUS_2016, serverConfig);
        }
        public static void Run(RunUpstreamServerOptions options)
        {
            // Create the updates filter configuration
            var filter = FilterBuilder.MetadataFilterFromCommandLine(options as IMetadataFilterOptions);

            var host = new WebHostBuilder()
                       .UseUrls($"http://{options.Endpoint}:{options.Port}")
                       .UseStartup <Server.UpstreamServerStartup>()
                       .UseKestrel()
                       .ConfigureKestrel((context, opts) => { })
                       .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
                logging.AddDebug();
                logging.AddEventSourceLogger();
            })
                       .ConfigureAppConfiguration((hostingContext, config) =>
            {
                var configDictionary = new Dictionary <string, string>()
                {
                    { "metadata-path", options.MetadataSourcePath },
                    { "content-path", options.ContentSourcePath },
                    { "updates-filter", filter.ToJson() },
                    { "service-config-path", options.ServiceConfigurationPath }
                };

                config.AddInMemoryCollection(configDictionary);
            })
                       .Build();

            host.Run();
        }
Example #3
0
        public static void Run(ContentSyncOptions options)
        {
            var metadataSource = Program.LoadMetadataSourceFromOptions(options as IMetadataSourceOptions);

            if (metadataSource == null)
            {
                return;
            }

            var filter = FilterBuilder.MetadataFilterFromCommandLine(options as IMetadataFilterOptions);

            if (filter == null)
            {
                return;
            }

            // Apply filters specified on the command line
            var updatesToDownload = metadataSource.GetUpdates(filter);

            if (updatesToDownload.Count == 0)
            {
                Console.WriteLine("No updates matched the filter");
                return;
            }

            var filesToDownload = new List <UpdateFile>();

            foreach (var update in updatesToDownload)
            {
                filesToDownload.AddRange(MetadataQuery.GetAllUpdateFiles(metadataSource, update));
            }

            var contentDestination = new FileSystemContentStore(options.ContentDestination);

            contentDestination.Progress += LocalSource_OperationProgress;

            var uniqueFiles = filesToDownload.GroupBy(f => f.DownloadUrl).Select(g => g.First()).ToList();

            uniqueFiles.RemoveAll(f => contentDestination.Contains(f));

            if (uniqueFiles.Count == 0)
            {
                ConsoleOutput.WriteGreen("The content matching the filter is up-to-date");
                return;
            }

            var totalDownloadSize = uniqueFiles.Sum(f => (long)f.Size);

            Console.Write($"Downloading {totalDownloadSize} bytes in {uniqueFiles.Count} files. Continue? (y/n)");
            var response = Console.ReadKey();

            if (response.Key == ConsoleKey.Y)
            {
                Console.WriteLine();
                contentDestination.Add(uniqueFiles);
            }
        }
Example #4
0
        /// <summary>
        /// Print updates from the store
        /// </summary>
        /// <param name="options">Print options, including filters</param>
        public void PrintUpdates(QueryMetadataOptions options)
        {
            var filter = FilterBuilder.MetadataFilterFromCommandLine(options as IMetadataFilterOptions);

            if (filter == null)
            {
                return;
            }

            filter.FirstX = options.FirstX;

            // Apply filters specified on the command line
            List <Update> filteredUpdates;

            if (options.Classifications || options.Products || options.Detectoids)
            {
                filteredUpdates = MetadataSource.GetCategories(filter);
                if (!options.Classifications)
                {
                    filteredUpdates.RemoveAll(u => u is Classification);
                }

                if (!options.Products)
                {
                    filteredUpdates.RemoveAll(u => u is Product);
                }

                if (!options.Detectoids)
                {
                    filteredUpdates.RemoveAll(u => u is Detectoid);
                }
            }
            else if (options.Updates || options.Drivers)
            {
                filteredUpdates = MetadataSource.GetUpdates(filter);

                if (options.Drivers)
                {
                    filteredUpdates.RemoveAll(u => !(u is DriverUpdate));
                }
            }
            else
            {
                filteredUpdates = new List <Update>();
            }

            if (filteredUpdates.Count == 0)
            {
                Console.WriteLine("No data found");
            }
            else
            {
                Console.Write("\r\nQuery results:\r\n-----------------------------");

                if (!options.CountOnly)
                {
                    foreach (var update in filteredUpdates)
                    {
                        PrintUpdateMetadata(update, MetadataSource);
                    }
                }

                Console.WriteLine("-----------------------------\r\nMatched {0} entries", filteredUpdates.Count);
            }
        }