Example #1
0
        private static string GetExpectedLicenseUrl(LicenseMetadata licenseMetadata)
        {
            if (licenseMetadata == null || LicenseType.File == licenseMetadata.Type)
            {
                return(GalleryConstants.LicenseDeprecationUrl);
            }

            if (LicenseType.Expression == licenseMetadata.Type)
            {
                return(LicenseExpressionRedirectUrlHelper.GetLicenseExpressionRedirectUrl(licenseMetadata.License));
            }

            throw new InvalidOperationException($"Unsupported license metadata type: {licenseMetadata.Type}");
        }
        public CompositeLicenseExpressionSegmentViewModel(CompositeLicenseExpressionSegment segment)
        {
            if (segment == null)
            {
                throw new ArgumentNullException(nameof(segment));
            }

            Value = segment.Value;
            IsLicenseOrException = segment.Type == CompositeLicenseExpressionSegmentType.LicenseIdentifier || segment.Type == CompositeLicenseExpressionSegmentType.ExceptionIdentifier;
            if (IsLicenseOrException)
            {
                LicenseUrl = LicenseExpressionRedirectUrlHelper.GetLicenseExpressionRedirectUrl(segment.Value);
            }
            else
            {
                LicenseUrl = null;
            }
        }
Example #3
0
        public DisplayPackageViewModel(Package package, User currentUser, string pushedBy)
            : base(package, currentUser)
        {
            Copyright = package.Copyright;

            DownloadCount = package.DownloadCount;
            LastEdited    = package.LastEdited;

            TotalDaysSinceCreated = 0;
            DownloadsPerDay       = 0;

            PushedBy = pushedBy;

            InitializeRepositoryMetadata(package.RepositoryUrl, package.RepositoryType);

            if (PackageHelper.TryPrepareUrlForRendering(package.ProjectUrl, out string projectUrl))
            {
                ProjectUrl = projectUrl;
            }

            var licenseExpression = package.LicenseExpression;

            if (!string.IsNullOrWhiteSpace(licenseExpression))
            {
                LicenseUrl = LicenseExpressionRedirectUrlHelper.GetLicenseExpressionRedirectUrl(licenseExpression);
            }
            else if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl))
            {
                LicenseUrl = licenseUrl;

                var licenseNames = package.LicenseNames;
                if (!string.IsNullOrEmpty(licenseNames))
                {
                    LicenseNames = licenseNames.Split(',').Select(l => l.Trim());
                }
            }
        }