protected PlatformVersionInfo GetAvailableVersionsFromStorage(
            string platformName,
            string versionMetadataElementName)
        {
            _logger.LogDebug("Getting list of available versions for platform {platformName}.", platformName);
            var httpClient = _httpClientFactory.CreateClient("general");

            var sdkStorageBaseUrl = GetPlatformBinariesStorageBaseUrl();
            var url               = string.Format(SdkStorageConstants.ContainerMetadataUrlFormat, sdkStorageBaseUrl, platformName);
            var blobList          = httpClient.GetStringAsync(url).Result;
            var xdoc              = XDocument.Parse(blobList);
            var supportedVersions = new List <string>();

            foreach (var metadataElement in xdoc.XPathSelectElements($"//Blobs/Blob/Metadata"))
            {
                var childElements  = metadataElement.Elements();
                var versionElement = childElements.Where(e => string.Equals(
                                                             versionMetadataElementName,
                                                             e.Name.LocalName,
                                                             StringComparison.OrdinalIgnoreCase))
                                     .FirstOrDefault();
                if (versionElement != null)
                {
                    supportedVersions.Add(versionElement.Value);
                }
            }

            var defaultVersion = GetDefaultVersion(platformName, sdkStorageBaseUrl);

            return(PlatformVersionInfo.CreateAvailableOnWebVersionInfo(supportedVersions, defaultVersion));
        }
Exemplo n.º 2
0
        protected PlatformVersionInfo GetAvailableVersionsFromStorage(
            string platformName,
            string versionMetadataElementName)
        {
            var httpClient = _httpClientFactory.CreateClient("general");

            var sdkStorageBaseUrl = GetPlatformBinariesStorageBaseUrl();
            var blobList          = httpClient
                                    .GetStringAsync($"{sdkStorageBaseUrl}/{platformName}?restype=container&comp=list&include=metadata")
                                    .Result;
            var xdoc = XDocument.Parse(blobList);
            var supportedVersions = new List <string>();

            foreach (var runtimeVersionElement in xdoc.XPathSelectElements(
                         $"//Blobs/Blob/Metadata/{versionMetadataElementName}"))
            {
                supportedVersions.Add(runtimeVersionElement.Value);
            }

            var defaultVersion = httpClient
                                 .GetStringAsync($"{sdkStorageBaseUrl}/{platformName}/default_version.txt")
                                 .Result;

            return(PlatformVersionInfo.CreateAvailableOnWebVersionInfo(supportedVersions, defaultVersion));
        }
        protected PlatformVersionInfo GetAvailableVersionsFromStorage(
            string platformName,
            string versionMetadataElementName)
        {
            var httpClient = _httpClientFactory.CreateClient("general");

            var sdkStorageBaseUrl = GetPlatformBinariesStorageBaseUrl();
            var blobList          = httpClient
                                    .GetStringAsync($"{sdkStorageBaseUrl}/{platformName}?restype=container&comp=list&include=metadata")
                                    .Result;
            var xdoc = XDocument.Parse(blobList);
            var supportedVersions = new List <string>();

            foreach (var runtimeVersionElement in xdoc.XPathSelectElements(
                         $"//Blobs/Blob/Metadata/{versionMetadataElementName}"))
            {
                supportedVersions.Add(runtimeVersionElement.Value);
            }

            // get default version
            var defaultVersionContent = httpClient
                                        .GetStringAsync($"{sdkStorageBaseUrl}/{platformName}/defaultVersion.txt")
                                        .Result;

            string defaultVersion = null;

            using (var stringReader = new StringReader(defaultVersionContent))
            {
                string line;
                while ((line = stringReader.ReadLine()) != null)
                {
                    // Ignore any comments in the file
                    if (!line.StartsWith("#") || !line.StartsWith("//"))
                    {
                        defaultVersion = line.Trim();
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(defaultVersion))
            {
                throw new InvalidOperationException("Default version cannot be empty.");
            }

            return(PlatformVersionInfo.CreateAvailableOnWebVersionInfo(supportedVersions, defaultVersion));
        }