Ejemplo n.º 1
0
        private static void FetchUpdates(QueryFilter queryToRun, CompressedMetadataStore destinationResult)
        {
            var server = new UpstreamServerClient(destinationResult.UpstreamSource);

            server.MetadataQueryProgress += Server_MetadataQueryProgress;

            Console.WriteLine("Fetching categories ...");

            server.GetCategories(destinationResult).GetAwaiter().GetResult();

            if (queryToRun != null)
            {
                Console.WriteLine("Running query with filters:");

                MetadataQuery.PrintFilter(queryToRun, destinationResult);

                server.GetUpdates(queryToRun, destinationResult).GetAwaiter().GetResult();
            }

            Console.WriteLine();
            destinationResult.CommitProgress += Program.MetadataSourceOperationProgressHandler;
            destinationResult.Commit();

            Console.WriteLine();
            ConsoleOutput.WriteGreen($"Query result saved to file {destinationResult.FilePath}");
        }
 static void Main(string[] args)
 {
     CommandLine.Parser.Default.ParseArguments <
         MetadataSourceStatusOptions,
         FetchUpdatesOptions,
         QueryMetadataOptions,
         MetadataSourceExportOptions,
         ContentSyncOptions,
         RunUpstreamServerOptions,
         MergeQueryResultOptions,
         FetchCategoriesOptions,
         FetchConfigurationOptions,
         MatchDriverOptions>(args)
     .WithParsed <FetchUpdatesOptions>(opts => MetadataSync.FetchUpdates(opts))
     .WithParsed <FetchConfigurationOptions>(opts => MetadataSync.FetchConfiguration(opts))
     .WithParsed <FetchCategoriesOptions>(opts => MetadataSync.FetchCategories(opts))
     .WithParsed <QueryMetadataOptions>(opts => MetadataQuery.Query(opts))
     .WithParsed <MatchDriverOptions>(opts => MetadataQuery.MatchDrivers(opts))
     .WithParsed <MetadataSourceExportOptions>(opts => UpdateMetadataExport.ExportUpdates(opts))
     .WithParsed <ContentSyncOptions>(opts => ContentSync.Run(opts))
     .WithParsed <MetadataSourceStatusOptions>(opts => MetadataQuery.Status(opts))
     .WithParsed <RunUpstreamServerOptions>(opts => UpstreamServer.Run(opts))
     .WithParsed <MergeQueryResultOptions>(opts => MetadataSync.MergeQueryResult(opts))
     .WithNotParsed(failed => Console.WriteLine("Error"));
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///  Runs a query command against a metadata source
        /// </summary>
        /// <param name="options">Query options (filters)</param>
        public static void Query(QueryMetadataOptions options)
        {
            var source = Program.LoadMetadataSourceFromOptions(options as IMetadataSourceOptions);

            if (source == null)
            {
                return;
            }

            var repoQuery = new MetadataQuery(source, options);

            repoQuery.Query();
        }