예제 #1
0
        private IEnumerable <UrlMapping> GetUrlMappings(Uri gitUri)
        {
            bool isValidContentUri(Uri uri)
            => uri.Query == "" && uri.UserInfo == "";

            if (Hosts != null)
            {
                foreach (var item in Hosts)
                {
                    string hostUrl = item.ItemSpec;

                    if (!UriUtilities.TryParseAuthority(hostUrl, out var hostUri))
                    {
                        Log.LogError(CommonResources.ValuePassedToTaskParameterNotValidDomainName, nameof(Hosts), item.ItemSpec);
                        continue;
                    }

                    Uri    contentUri;
                    string contentUrl           = item.GetMetadata(ContentUrlMetadataName);
                    bool   hasDefaultContentUri = string.IsNullOrEmpty(contentUrl);
                    if (hasDefaultContentUri)
                    {
                        contentUri = GetDefaultContentUriFromHostUri(hostUri.Authority, gitUri);
                    }
                    else if (!Uri.TryCreate(contentUrl, UriKind.Absolute, out contentUri) || !isValidContentUri(contentUri))
                    {
                        Log.LogError(CommonResources.ValuePassedToTaskParameterNotValidHostUri, nameof(Hosts), contentUrl);
                        continue;
                    }

                    yield return(new UrlMapping(hostUri.Host, item, hostUri.Port, contentUri, hasDefaultContentUri));
                }
            }

            // Add implicit host last, so that matching prefers explicitly listed hosts over the implicit one.
            if (SupportsImplicitHost && IsSingleProvider)
            {
                if (Uri.TryCreate(RepositoryUrl, UriKind.Absolute, out var uri))
                {
                    yield return(new UrlMapping(uri.Host, hostItem: null, uri.GetExplicitPort(), GetDefaultContentUriFromRepositoryUri(uri), hasDefaultContentUri: true));
                }
                else
                {
                    Log.LogError(CommonResources.ValuePassedToTaskParameterNotValidUri, nameof(RepositoryUrl), RepositoryUrl);
                }
            }
        }
        private IEnumerable <Uri> GetHostUris()
        {
            if (Hosts != null)
            {
                foreach (var item in Hosts)
                {
                    if (UriUtilities.TryParseAuthority(item.ItemSpec, out var hostUri))
                    {
                        yield return(hostUri);
                    }
                }
            }

            // Add implicit host last, so that matching prefers explicitly listed hosts over the implicit one.
            if (IsSingleProvider && Uri.TryCreate(RepositoryUrl, UriKind.Absolute, out var repositoryUri))
            {
                yield return(repositoryUri);
            }
        }