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"));
 }
Exemplo n.º 2
0
        /// <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);
            }
        }