コード例 #1
0
        private async Task <T> GetAndValidateLeafAsync <T>(CatalogLeafType type, string leafUrl) where T : CatalogLeaf
        {
            var leaf = await DeserializeUrlAsync <T>(leafUrl);

            if (leaf.Type != type)
            {
                throw new ArgumentException(
                          $"The leaf type found in the document does not match the expected '{type}' type.",
                          nameof(type));
            }

            return(leaf);
        }
コード例 #2
0
        private async Task <CatalogLeaf> GetLeafAsync(CatalogLeafType type, string leafUrl, CancellationToken token)
        {
            switch (type)
            {
            case CatalogLeafType.PackageDetails:
                return(await GetPackageDetailsLeafAsync(leafUrl, token));

            case CatalogLeafType.PackageDelete:
                return(await GetPackageDeleteLeafAsync(leafUrl, token));

            default:
                throw new NotSupportedException($"The catalog leaf type '{type}' is not supported.");
            }
        }
コード例 #3
0
ファイル: CatalogClient.cs プロジェクト: xiaopohou/BaGet
        private async Task <T> GetAndValidateLeafAsync <T>(
            CatalogLeafType type,
            string leafUrl,
            CancellationToken cancellationToken) where T : CatalogLeaf
        {
            var result = await _httpClient.DeserializeUrlAsync <T>(leafUrl, cancellationToken);

            var leaf = result.GetResultOrThrow();

            if (leaf.Type != type)
            {
                throw new ArgumentException(
                          $"The leaf type found in the document does not match the expected '{type}' type.",
                          nameof(type));
            }

            return(leaf);
        }
コード例 #4
0
        public async Task <CatalogLeaf> GetAndValidateLeafAsync <T>(CatalogLeafType type, string leafUrl, CancellationToken token) where T : CatalogLeaf
        {
            using (_logger.BeginScope(new Dictionary <string, string>
            {
                { "type", type.ToString() },
                { "leafUrl", leafUrl },
            }))
            {
                _logger.LogInformation("Getting package leaf: {type}, {leafUrl}", type, leafUrl);
                var leaf = await DeserializeUrlAsync <T>(leafUrl, token);

                if (leaf != null && leaf.Type != type)
                {
                    _logger.LogError("The leaf type found in the document does not match the expected '{type}' type.", type);
                }

                return(leaf);
            }
        }