Exemple #1
0
        private static async Task ExecuteAsync(FeedMirrorRequest request, CancellationToken token)
        {
            request.PackagesDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            Directory.CreateDirectory(request.PackagesDirectory);

            try
            {
                var logger = new ConsoleLogger();

                var command = new FeedMirrorCommand();
                await command.ExecuteAsync(request, logger, token);
            }
            finally
            {
                Directory.Delete(request.PackagesDirectory, recursive: true);
            }
        }
Exemple #2
0
        private static async Task ExecuteAsync(FeedMirrorRequest request, CancellationToken token)
        {
            request.PackagesDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            Directory.CreateDirectory(request.PackagesDirectory);

            try
            {
                var logger = new ConsoleLogger();

                var command = new FeedMirrorCommand();
                await command.ExecuteAsync(request, logger, token);
            }
            finally
            {
                Directory.Delete(request.PackagesDirectory, recursive: true);
            }
        }
Exemple #3
0
        public static int Main(string[] args)
        {
            var application = new CommandLineApplication();
            application.Name = AppDomain.CurrentDomain.FriendlyName;

            var sourceOption = application.Option(
                "--source",
                "The NuGet source to read packages from.",
                CommandOptionType.SingleValue);

            var destinationOption = application.Option(
                "--destination",
                "The NuGet source to publish packages to. This should be the actual source URL, not the publish URL.",
                CommandOptionType.SingleValue);

            var destinationApiKeyOption = application.Option(
                "--destinationApiKey",
                "The API key to use when pushing to the destination.",
                CommandOptionType.SingleValue);

            var excludeNuGetSymbolsOption = application.Option(
                "--excludeNuGetSymbols",
                "Specify this option to ignore symbols package on the source and to not push them to the destination.",
                CommandOptionType.NoValue);

            var overwriteExistingOption = application.Option(
                "--overwriteExisting",
                "Specify thie option to overwrite existing packages on the destination by pushing all packages from the source.",
                CommandOptionType.NoValue);

            var maxDegreeOfParallelismOption = application.Option(
                "--maxDegreeOfParallelism",
                "The maximum degree of parallelism to use when pushing packages to the destination.",
                CommandOptionType.SingleValue);

            application.OnExecute(() =>
            {
                var validInput = true;

                if (!sourceOption.HasValue())
                {
                    Console.WriteLine($"The --{sourceOption.LongName} option is required.");
                    validInput = false;
                }
                
                if (!destinationOption.HasValue())
                {
                    Console.WriteLine($"The --{destinationOption.LongName} option is required.");
                    validInput = false;
                }

                if (!destinationApiKeyOption.HasValue())
                {
                    Console.WriteLine($"The --{destinationApiKeyOption.LongName} option is required.");
                    validInput = false;
                }

                int maxDegreeOfParallelism = 16;
                if (maxDegreeOfParallelismOption.HasValue() &&
                    (!int.TryParse(maxDegreeOfParallelismOption.Value(), out maxDegreeOfParallelism) || maxDegreeOfParallelism < 1))
                {
                    Console.WriteLine($"The --{maxDegreeOfParallelismOption.LongName} option must have a positive integer value.");
                    validInput = false;
                }

                if (!validInput)
                {
                    application.ShowHelp();
                    return 1;
                }

                var request = new FeedMirrorRequest
                {
                    Source = sourceOption.Value(),
                    Destination = destinationOption.Value(),
                    DestinationApiKey = destinationApiKeyOption.Value(),
                    IncludeNuGet = true,
                    IncludeVsix = true,
                    IncludeNuGetSymbols = !excludeNuGetSymbolsOption.HasValue(),
                    OverwriteExisting = overwriteExistingOption.HasValue(),
                    MaxDegreeOfParallelism = maxDegreeOfParallelism
                };
                
                ExecuteAsync(request, CancellationToken.None).Wait();

                return 0;
            });

            return application.Execute(args);
        }
Exemple #4
0
        public static int Main(string[] args)
        {
            var application = new CommandLineApplication();

            application.Name = AppDomain.CurrentDomain.FriendlyName;

            var sourceOption = application.Option(
                "--source",
                "The NuGet source to read packages from.",
                CommandOptionType.SingleValue);

            var destinationOption = application.Option(
                "--destination",
                "The NuGet source to publish packages to. This should be the actual source URL, not the publish URL.",
                CommandOptionType.SingleValue);

            var destinationApiKeyOption = application.Option(
                "--destinationApiKey",
                "The API key to use when pushing to the destination.",
                CommandOptionType.SingleValue);

            var excludeNuGetSymbolsOption = application.Option(
                "--excludeNuGetSymbols",
                "Specify this option to ignore symbols package on the source and to not push them to the destination.",
                CommandOptionType.NoValue);

            var overwriteExistingOption = application.Option(
                "--overwriteExisting",
                "Specify thie option to overwrite existing packages on the destination by pushing all packages from the source.",
                CommandOptionType.NoValue);

            var maxDegreeOfParallelismOption = application.Option(
                "--maxDegreeOfParallelism",
                "The maximum degree of parallelism to use when pushing packages to the destination.",
                CommandOptionType.SingleValue);

            application.OnExecute(() =>
            {
                var validInput = true;

                if (!sourceOption.HasValue())
                {
                    Console.WriteLine($"The --{sourceOption.LongName} option is required.");
                    validInput = false;
                }

                if (!destinationOption.HasValue())
                {
                    Console.WriteLine($"The --{destinationOption.LongName} option is required.");
                    validInput = false;
                }

                if (!destinationApiKeyOption.HasValue())
                {
                    Console.WriteLine($"The --{destinationApiKeyOption.LongName} option is required.");
                    validInput = false;
                }

                int maxDegreeOfParallelism = 16;
                if (maxDegreeOfParallelismOption.HasValue() &&
                    (!int.TryParse(maxDegreeOfParallelismOption.Value(), out maxDegreeOfParallelism) || maxDegreeOfParallelism < 1))
                {
                    Console.WriteLine($"The --{maxDegreeOfParallelismOption.LongName} option must have a positive integer value.");
                    validInput = false;
                }

                if (!validInput)
                {
                    application.ShowHelp();
                    return(1);
                }

                var request = new FeedMirrorRequest
                {
                    Source                 = sourceOption.Value(),
                    Destination            = destinationOption.Value(),
                    DestinationApiKey      = destinationApiKeyOption.Value(),
                    IncludeNuGet           = true,
                    IncludeVsix            = true,
                    IncludeNuGetSymbols    = !excludeNuGetSymbolsOption.HasValue(),
                    OverwriteExisting      = overwriteExistingOption.HasValue(),
                    MaxDegreeOfParallelism = maxDegreeOfParallelism
                };

                ExecuteAsync(request, CancellationToken.None).Wait();

                return(0);
            });

            return(application.Execute(args));
        }
Exemple #5
0
        public async Task ExecuteAsync(FeedMirrorRequest request, ILogger logger, CancellationToken token)
        {
            var settings = new InMemorySettings();
            SettingsUtility.SetConfigValue(
                settings,
                "globalPackagesFolder",
                request.PackagesDirectory);

            // Set up the source logic.
            var sourceUrlBuilder = new MyGetUrlBuilder(request.Source);
            var sourceRepository = Repository.Factory.GetCoreV3(request.Source);
            var sourceDownloaderResource = await sourceRepository.GetResourceAsync<DownloadResource>(token);
            var sourceHttpSourceResource = await sourceRepository.GetResourceAsync<HttpSourceResource>(token);
            var sourceHttpSource = sourceHttpSourceResource.HttpSource;
            var sourceSymbolsPackageDownloader = new MyGetNuGetSymbolsPackageDownloader(sourceUrlBuilder, sourceHttpSource, logger);
            var sourcePackageSearchResource = await sourceRepository.GetResourceAsync<PackageSearchResource>(token);
            var sourceVsixPackageDownloader = new MyGetVsixPackageDownloader(sourceUrlBuilder, sourceHttpSource, logger);

            // Set up enumeration logic for the source.
            var nuGetPackageEnumerator = new NuGetPackageEnumerator(sourcePackageSearchResource, logger);
            var vsixPackageEnumerator = new VsixPackageEnumerator(sourceUrlBuilder.GetVsixUrl(), sourceHttpSource, logger);

            // Set up the destination logic.
            var destinationUrlBuilder = new MyGetUrlBuilder(request.Destination);
            var destinationRepository = Repository.Factory.GetCoreV3(request.Destination);
            var destinationHttpSourceResource = await destinationRepository.GetResourceAsync<HttpSourceResource>(token);
            var destinationHttpSource = destinationHttpSourceResource.HttpSource;
            var destinationMetadataResource = await destinationRepository.GetResourceAsync<MetadataResource>(token);
            var destinationSymbolsPackageDownloader = new MyGetNuGetSymbolsPackageDownloader(destinationUrlBuilder, destinationHttpSource, logger);
            var destinationExistenceChecker = new NuGetPackageExistenceChecker(destinationMetadataResource, destinationSymbolsPackageDownloader, logger);
            var destinationVsixPackageDownloader = new MyGetVsixPackageDownloader(destinationUrlBuilder, destinationHttpSource, logger);

            // Set up push logic for the destination.
            var nuGetPackagePusher = new NuGetPackagePusher(destinationUrlBuilder.GetNuGetPushUrl(), request.DestinationApiKey, destinationHttpSource, logger);
            var vsixPackagePusher = new MyGetVsixPackagePusher(destinationUrlBuilder.GetVsixPushUrl(), request.DestinationApiKey, destinationHttpSource, logger);

            // Set up the mirror logic.
            var nuGetPackageMirror = new NuGetPackageMirrorCommand(
                request.OverwriteExisting,
                request.IncludeNuGetSymbols,
                sourceDownloaderResource,
                sourceSymbolsPackageDownloader,
                destinationExistenceChecker,
                nuGetPackagePusher,
                settings,
                logger);

            var nuGetMirror = new NuGetMirrorCommand(
                request.MaxDegreeOfParallelism,
                nuGetPackageEnumerator,
                nuGetPackageMirror,
                logger);

            var vsixPackageMirror = new VsixPackageMirrorCommand(
                request.OverwriteExisting,
                sourceVsixPackageDownloader,
                destinationVsixPackageDownloader,
                vsixPackagePusher);

            var vsixMirror = new VsixMirrorCommand(
                request.MaxDegreeOfParallelism,
                vsixPackageEnumerator,
                vsixPackageMirror,
                logger);

            // Execute.
            if (request.IncludeNuGet)
            {
                await nuGetMirror.Execute(token);
            }

            if (request.IncludeVsix)
            {
                await vsixMirror.Execute(token);
            }
        }
        public async Task ExecuteAsync(FeedMirrorRequest request, ILogger logger, CancellationToken token)
        {
            var settings = new InMemorySettings();

            SettingsUtility.SetConfigValue(
                settings,
                "globalPackagesFolder",
                request.PackagesDirectory);

            // Set up the source logic.
            var sourceUrlBuilder         = new MyGetUrlBuilder(request.Source);
            var sourceRepository         = Repository.Factory.GetCoreV3(request.Source);
            var sourceDownloaderResource = await sourceRepository.GetResourceAsync <DownloadResource>(token);

            var sourceHttpSourceResource = await sourceRepository.GetResourceAsync <HttpSourceResource>(token);

            var sourceHttpSource = sourceHttpSourceResource.HttpSource;
            var sourceSymbolsPackageDownloader = new MyGetNuGetSymbolsPackageDownloader(sourceUrlBuilder, sourceHttpSource, logger);
            var sourcePackageSearchResource    = await sourceRepository.GetResourceAsync <PackageSearchResource>(token);

            var sourceVsixPackageDownloader = new MyGetVsixPackageDownloader(sourceUrlBuilder, sourceHttpSource, logger);

            // Set up enumeration logic for the source.
            var nuGetPackageEnumerator = new NuGetPackageEnumerator(sourcePackageSearchResource, logger);
            var vsixPackageEnumerator  = new VsixPackageEnumerator(sourceUrlBuilder.GetVsixUrl(), sourceHttpSource, logger);

            // Set up the destination logic.
            var destinationUrlBuilder         = new MyGetUrlBuilder(request.Destination);
            var destinationRepository         = Repository.Factory.GetCoreV3(request.Destination);
            var destinationHttpSourceResource = await destinationRepository.GetResourceAsync <HttpSourceResource>(token);

            var destinationHttpSource       = destinationHttpSourceResource.HttpSource;
            var destinationMetadataResource = await destinationRepository.GetResourceAsync <MetadataResource>(token);

            var destinationSymbolsPackageDownloader = new MyGetNuGetSymbolsPackageDownloader(destinationUrlBuilder, destinationHttpSource, logger);
            var destinationExistenceChecker         = new NuGetPackageExistenceChecker(destinationMetadataResource, destinationSymbolsPackageDownloader, logger);
            var destinationVsixPackageDownloader    = new MyGetVsixPackageDownloader(destinationUrlBuilder, destinationHttpSource, logger);

            // Set up push logic for the destination.
            var nuGetPackagePusher = new NuGetPackagePusher(destinationUrlBuilder.GetNuGetPushUrl(), request.DestinationApiKey, destinationHttpSource, logger);
            var vsixPackagePusher  = new MyGetVsixPackagePusher(destinationUrlBuilder.GetVsixPushUrl(), request.DestinationApiKey, destinationHttpSource, logger);

            // Set up the mirror logic.
            var nuGetPackageMirror = new NuGetPackageMirrorCommand(
                request.OverwriteExisting,
                request.IncludeNuGetSymbols,
                sourceDownloaderResource,
                sourceSymbolsPackageDownloader,
                destinationExistenceChecker,
                nuGetPackagePusher,
                settings,
                logger);

            var nuGetMirror = new NuGetMirrorCommand(
                request.MaxDegreeOfParallelism,
                nuGetPackageEnumerator,
                nuGetPackageMirror,
                logger);

            var vsixPackageMirror = new VsixPackageMirrorCommand(
                request.OverwriteExisting,
                sourceVsixPackageDownloader,
                destinationVsixPackageDownloader,
                vsixPackagePusher);

            var vsixMirror = new VsixMirrorCommand(
                request.MaxDegreeOfParallelism,
                vsixPackageEnumerator,
                vsixPackageMirror,
                logger);

            // Execute.
            if (request.IncludeNuGet)
            {
                await nuGetMirror.Execute(token);
            }

            if (request.IncludeVsix)
            {
                await vsixMirror.Execute(token);
            }
        }