public override void ExecuteCommand()

in Source/NuGetGallery.Operations/Tasks/RestorePackagesTask.cs [61:115]


        public override void ExecuteCommand()
        {
            if (!Force)
            {
                Log.Error("This task is deprecated because it only re-uploads the file, it doesn't restore the DB changes...");
                return;
            }

            Log.Info("Getting list of packages to restore; this will take some time.");
            var packages = GetPackages();
            var packageBlobFileNames = GetPackageBlobFileNames();
            var packageFileNamesToRestore = packages.Keys.Except(packageBlobFileNames).ToList();

            var totalCount = packageFileNamesToRestore.Count;
            var processedCount = 0;
            Log.Info(
                "Restoring {0} packages in storage account '{1}'.",
                totalCount,
                StorageAccountName);

            Parallel.ForEach(packageFileNamesToRestore, new ParallelOptions { MaxDegreeOfParallelism = 10 }, packageFileNameToRestore =>
            {
                var package = packages[packageFileNameToRestore];
                try
                {
                    var downloadPath = DownloadPackageBackup(
                        package.Id,
                        package.Version,
                        package.Hash);
                    UploadPackage(
                        package.Id,
                        package.Version,
                        downloadPath);
                    File.Delete(downloadPath);
                    Interlocked.Increment(ref processedCount);
                    Log.Info(
                        "Restored package '{0}.{1}' ({2} of {3}).",
                        package.Id,
                        package.Version,
                        processedCount,
                        totalCount);
                }
                catch (Exception ex)
                {
                    Interlocked.Increment(ref processedCount);
                    Log.Info(
                        "Error restoring package '{0}.{1}' ({2} of {3}): {4}.",
                        package.Id,
                        package.Version,
                        processedCount,
                        totalCount,
                        ex.Message);
                }
            });
        }