Esempio n. 1
0
        /// <summary>
        /// 执行数据镜像
        /// </summary>
        /// <param name="task">任务</param>
        /// <param name="mirror">镜像源信息</param>
        /// <param name="asyn">异步通知</param>
        public void Execute(SPFTask task, Mirror mirror, IAsyncTaskProgress asyn)
        {
            //生成保存目录
            FileHelper.CreateExitsDirectorySafe(mirror.Target);

            //镜像
            MirrorService = SingleWrapperHelper <MirrorServiceFactory> .GetInstance().GetInstance(mirror);

            MirrorService.Execute(mirror, asyn);

            if (FileHelper.IsValid(mirror.Local))
            {//镜像成功
                mirror.VerifyCode = FileHelper.MD5FromFileUpper(mirror.Local);

                //生成MD5文件
                var md5File = mirror.Local.TrimEnd(SPFTask.EXT_MIRROR) + SPFTask.EXT_VERIFYCODE_FILE;
                FileHelper.CreateFile(md5File, mirror.VerifyCode, Encoding.UTF8);

                //生成设备信息文件
                var deviceFile = mirror.Local.TrimEnd(SPFTask.EXT_MIRROR) + SPFTask.EXT_DEVICE;
                Serializer.SerializeToBinary(task.Device, deviceFile);

                task.TaskMirrorFilePath = mirror.Local;
                task.VerifyCodes.Add(new FileVerifyCode()
                {
                    FilePath = mirror.Local, VerifyCode = mirror.VerifyCode
                });
            }
        }
 public DefaultPackageMetadataService(
     IMirrorService mirror,
     IPackageService packages,
     RegistrationBuilder builder)
 {
     _mirror   = mirror ?? throw new ArgumentNullException(nameof(mirror));
     _packages = packages ?? throw new ArgumentNullException(nameof(packages));
     _builder  = builder ?? throw new ArgumentNullException(nameof(builder));
 }
Esempio n. 3
0
 public DefaultPackageContentService(
     IMirrorService mirror,
     IPackageService packages,
     IPackageStorageService storage)
 {
     _mirror   = mirror ?? throw new ArgumentNullException(nameof(mirror));
     _packages = packages ?? throw new ArgumentNullException(nameof(packages));
     _storage  = storage ?? throw new ArgumentNullException(nameof(storage));
 }
 public PackageModel(
     IMirrorService mirror,
     IPackageContentService content,
     ISearchService search,
     IUrlGenerator url)
 {
     _mirror  = mirror ?? throw new ArgumentNullException(nameof(mirror));
     _content = content ?? throw new ArgumentNullException(nameof(content));
     _search  = search ?? throw new ArgumentNullException(nameof(search));
     _url     = url ?? throw new ArgumentNullException(nameof(url));
 }
Esempio n. 5
0
        public async Task ProcessAsync(
            IRepositorySource source,
            IMirrorService mirrorService,
            IRepositoryTarget[] targets,
            CancellationToken cancellationToken)
        {
            if (!targets.Any())
            {
                throw new NotSupportedException("At least one target is required!");
            }

            var repos = await source.GetRepositoriesAsync(cancellationToken);

            _log.LogInformation($"Source {source.SourceId} has {repos.Length} repositories (to be mirrored by {mirrorService.MirrorId})");

            var mirroredRepositories = (await mirrorService.GetExistingMirrorsAsync(cancellationToken))
                                       .Select(x => x.Repository)
                                       .ToArray();
            var toMirror = repos.Where(r => !mirroredRepositories.Contains(r.Name)).ToArray();

            if (toMirror.Length == 0)
            {
                _log.LogInformation("All repositories are already mirrored!");
                return;
            }
            _log.LogInformation($"{repos.Length - toMirror.Length} repositories are already mirrored, setting up mirrors for the remaining {toMirror.Length} repositories..");
            var cachedResponse = new Dictionary <IRepositoryTarget, IRepository[]>();

            foreach (var target in targets)
            {
                cachedResponse[target] = await target.GetRepositoriesAsync(cancellationToken);
            }
            foreach (var repo in toMirror)
            {
                _log.LogInformation($"Creating mirror for repository {repo.Name}");
                // create mirror last as it is the marker whether a repo mirror already exists
                // creating repositories is also idempotent
                foreach (var target in targets)
                {
                    var existing = cachedResponse[target];
                    if (existing.Any(e => e.Name == repo.Name))
                    {
                        continue;
                    }

                    await target.CreateRepositoryAsync(source, repo, cancellationToken);
                }
                await mirrorService.SetupMirrorAsync(repo, cancellationToken);

                _log.LogInformation($"Created mirror for repository {repo.Name}");
            }
        }
Esempio n. 6
0
 public TrayApp()
 {
     _notifyIcon               = new NotifyIcon();
     _isOptionsVisible         = false;
     _backgroundWorker         = new BackgroundWorker();
     _backgroundWorker.DoWork += _backgroundWorker_DoWork;
     _timer = new Timer {
         Enabled = false
     };
     _timer.Tick          += _timer_Tick;
     _configurationService = new ConfigurationService(Application.CommonAppDataPath, Application.ExecutablePath);
     _mirrorService        = new MirrorService();
 }
 public DefaultPackageMetadataService(
     IContext context,
     IMirrorService mirror,
     IPackageService packages,
     RegistrationBuilder builder,
     IUrlGenerator urlGenerator)
 {
     _context      = context ?? throw new ArgumentNullException(nameof(context));
     _mirror       = mirror ?? throw new ArgumentNullException(nameof(mirror));
     _packages     = packages ?? throw new ArgumentNullException(nameof(packages));
     _builder      = builder ?? throw new ArgumentNullException(nameof(builder));
     _urlGenerator = urlGenerator;
 }
Esempio n. 8
0
 public RegistrationLeafController(IMirrorService mirror, IPackageService packages)
 {
     _mirror   = mirror ?? throw new ArgumentNullException(nameof(mirror));
     _packages = packages ?? throw new ArgumentNullException(nameof(packages));
 }
Esempio n. 9
0
 public DatabasePackageMetadataService(IMirrorService mirror, IPackageService packages, IBaGetUrlGenerator url)
 {
     _mirror   = mirror ?? throw new ArgumentNullException(nameof(mirror));
     _packages = packages ?? throw new ArgumentNullException(nameof(packages));
     _url      = url ?? throw new ArgumentNullException(nameof(url));
 }
Esempio n. 10
0
 public MazeService(IMirrorService mirrorService)
 {
     _mirrorService = mirrorService;
 }
Esempio n. 11
0
        public CacheRegistrationIndexModule(IMirrorService mirror)
        {
            this._mirror = mirror ?? throw new ArgumentNullException(nameof(mirror));
            this.Get("cache/v3/registration/{id}/index.json", async(req, res, routeData) =>
            {
                string id = routeData.As <string>("id");
                // Documentation: https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource
                var upstreamPackages = (await _mirror.FindUpstreamMetadataAsync(id, CancellationToken.None)).ToList();
                var versions         = upstreamPackages.Select(p => p.Identity.Version).ToList();

                if (!upstreamPackages.Any())
                {
                    res.StatusCode = 404;
                    return;
                }

                // TODO: Paging of registration items.
                // "Un-paged" example: https://api.nuget.org/v3/registration3/newtonsoft.json/index.json
                // Paged example: https://api.nuget.org/v3/registration3/fake/index.json
                await res.AsJson(new
                {
                    Count          = upstreamPackages.Count,
                    TotalDownloads = upstreamPackages.Sum(p => p.DownloadCount),
                    Items          = new[]
                    {
                        new RegistrationIndexItem(
                            packageId: id,
                            items: upstreamPackages.Select(p => ToRegistrationIndexLeaf(req, p)).ToList(),
                            lower: versions.Min().ToNormalizedString(),
                            upper: versions.Max().ToNormalizedString()
                            ),
                    }
                });
            });

            this.Get("cache/v3/registration/{id}/{version}.json", async(req, res, routeData) =>
            {
                string id      = routeData.As <string>("id");
                string version = routeData.As <string>("version");

                if (!NuGetVersion.TryParse(version, out var nugetVersion))
                {
                    res.StatusCode = 400;
                    return;
                }

                // Allow read-through caching to happen if it is confiured.
                await _mirror.MirrorAsync(id, nugetVersion, CancellationToken.None);

                var package = await _mirror.FindAsync(new PackageIdentity(id, nugetVersion));

                if (package == null)
                {
                    res.StatusCode = 404;
                    return;
                }

                // Documentation: https://docs.microsoft.com/en-us/nuget/api/registration-base-url-resource
                var result = new RegistrationLeaf(
                    registrationUri: req.PackageRegistration(id, nugetVersion, "cache"),
                    listed: package.IsListed,
                    downloads: package.DownloadCount.GetValueOrDefault(),
                    packageContentUri: req.PackageDownload(id, nugetVersion, "cache"),
                    published: package.Published.GetValueOrDefault(),
                    registrationIndexUri: req.PackageRegistration(id, "cache"));

                await res.AsJson(result);
            });
        }
Esempio n. 12
0
 public SearchController(ISearchService searchService, IMirrorService mirrorService)
 {
     _searchService = searchService ?? throw new ArgumentNullException(nameof(searchService));
     _mirrorService = mirrorService;
 }
Esempio n. 13
0
        public CachePackageModule(IMirrorService mirror)
            : base("cache/v3/package")
        {
            _mirror = mirror ?? throw new ArgumentNullException(nameof(mirror));

            this.Get("/{id}/index.json", async(req, res, routeData) => {
                string id = routeData.As <string>("id");
                IReadOnlyList <string> upstreamVersions = await _mirror.FindUpstreamAsync(id, CancellationToken.None);
                if (upstreamVersions.Any())
                {
                    await res.AsJson(new
                    {
                        Versions = upstreamVersions.ToList()
                    });
                    return;
                }
                res.StatusCode = 404;
            });

            this.Get("/{id}/{version}/{idVersion}.nupkg", async(req, res, routeData) => {
                string id      = routeData.As <string>("id");
                string version = routeData.As <string>("version");

                if (!NuGetVersion.TryParse(version, out var nugetVersion))
                {
                    res.StatusCode = 400;
                    return;
                }

                // Allow read-through caching if it is configured.
                await _mirror.MirrorAsync(id, nugetVersion, CancellationToken.None);

                var identity      = new PackageIdentity(id, nugetVersion);
                var packageStream = await _mirror.GetPackageStreamAsync(identity);

                await res.FromStream(packageStream, "application/octet-stream");
            });

            this.Get("/{id}/{version}/{id2}.nuspec", async(req, res, routeData) => {
                string id      = routeData.As <string>("id");
                string version = routeData.As <string>("version");

                if (!NuGetVersion.TryParse(version, out var nugetVersion))
                {
                    res.StatusCode = 400;
                    return;
                }

                // Allow read-through caching if it is configured.
                await _mirror.MirrorAsync(id, nugetVersion, CancellationToken.None);

                if (!await _mirror.ExistsAsync(new PackageIdentity(id, nugetVersion)))
                {
                    res.StatusCode = 404;
                    return;
                }

                var identity = new PackageIdentity(id, nugetVersion);

                await res.FromStream(await _mirror.GetNuspecStreamAsync(identity), "text/xml");
            });

            this.Get("/{id}/{version}/readme", async(req, res, routeData) => {
                string id      = routeData.As <string>("id");
                string version = routeData.As <string>("version");

                if (!NuGetVersion.TryParse(version, out var nugetVersion))
                {
                    res.StatusCode = 400;
                    return;
                }

                // Allow read-through caching if it is configured.
                await _mirror.MirrorAsync(id, nugetVersion, CancellationToken.None);

                if (!await _mirror.ExistsAsync(new PackageIdentity(id, nugetVersion)))
                {
                    res.StatusCode = 404;
                    return;
                }

                var identity = new PackageIdentity(id, nugetVersion);

                await res.FromStream(await _mirror.GetReadmeStreamAsync(identity), "text/markdown");
            });
        }