Exemple #1
0
        public async Task <RepositoryLicense> LoadOrCreateLicenseAsync(string licenseCode, CancellationToken token)
        {
            licenseCode.AssertNotNull(nameof(licenseCode));

            var index = await Storage.ReadLicenseIndexJsonAsync(licenseCode, token);

            if (index != null)
            {
                return(new RepositoryLicense(index.Code, index.RequiresApproval, index.RequiresThirdPartyNotices, index.Dependencies));
            }

            var info = await Container.Resolve <ILicenseResolver>().DownloadByCodeAsync(licenseCode, token);

            if (info == null)
            {
                info = new LicenseInfo
                {
                    Code        = licenseCode,
                    FileName    = "license.txt",
                    FileContent = Array.Empty <byte>()
                };
            }

            index = new LicenseIndexJson
            {
                Code                      = info.Code,
                FullName                  = info.FullName,
                HRef                      = info.FileHRef,
                FileName                  = info.FileName,
                RequiresApproval          = true,
                RequiresThirdPartyNotices = false
            };
            await Storage.CreateLicenseIndexJsonAsync(index, token);

            await Storage.CreateLicenseFileAsync(info.Code, info.FileName, info.FileContent, token);

            return(new RepositoryLicense(index.Code, index.RequiresApproval, index.RequiresThirdPartyNotices, index.Dependencies));
        }
Exemple #2
0
 public void AddByCode(string code, LicenseInfo info) => _byCode.TryAdd(code, info);
Exemple #3
0
 public bool TryGetByCode(string code, out LicenseInfo info) => _byCode.TryGetValue(code, out info);
Exemple #4
0
 public void AddByUrl(string url, LicenseInfo info) => _byUrl.TryAdd(url, info);
Exemple #5
0
 public bool TryGetByUrl(string url, out LicenseInfo info) => _byUrl.TryGetValue(url, out info);