示例#1
0
        public async Task <MyGetApiResponse> GetPackagesAsync()
        {
            if (_response != null)
            {
                return(_response);
            }

            try
            {
                using (var client = new CliHttpClient(TimeSpan.FromMinutes(10)))
                {
                    var responseMessage = await client.GetAsync(
                        $"{CliUrls.WwwRocketIo}api/myget/packages/"
                        );

                    _response = JsonConvert.DeserializeObject <MyGetApiResponse>(Encoding.Default.GetString(await responseMessage.Content.ReadAsByteArrayAsync()));
                }
            }
            catch (Exception)
            {
                Logger.LogError("Unable to get latest preview version.");
                throw;
            }

            return(_response);
        }
示例#2
0
        protected virtual async Task <string> GetLatestVersion(
            JProperty package,
            string currentVersion,
            bool includePreviews = false,
            bool switchToStable  = false)
        {
            if (_fileVersionStorage.ContainsKey(package.Name))
            {
                return(_fileVersionStorage[package.Name]);
            }

            var newVersion = currentVersion;

            if (includePreviews || (!switchToStable && currentVersion.Contains("-preview")))
            {
                if (_myGetApiResponse == null)
                {
                    _myGetApiResponse = await _myGetPackageListFinder.GetPackagesAsync();
                }

                var mygetPackage = _myGetApiResponse.Packages.FirstOrDefault(p => p.Id == package.Name);
                if (mygetPackage != null)
                {
                    newVersion = mygetPackage.Versions.Last();
                }
            }
            else
            {
                newVersion = CmdHelper.RunCmdAndGetOutput($"npm show {package.Name} version");
            }

            _fileVersionStorage[package.Name] = newVersion;

            return(newVersion);
        }