コード例 #1
0
        private List <RadioEpisode> PopulateEpisodeList(Item seriesRoot)
        {
            var cacheKey = seriesRoot.ID.ToString();

            if (_cacheService.Contains(cacheKey))
            {
                return(_cacheService.Get <List <RadioEpisode> >(cacheKey));
            }

            var allRadioEpisodeItems =
                seriesRoot.Axes.GetDescendants().Where(d => d.TemplateName == "Radio Episode").ToList();

            var allRadioEpisodes = new List <RadioEpisode>();

            foreach (var i in allRadioEpisodeItems)
            {
                var episode = BuildRadioEpisode(i);
                allRadioEpisodes.Add(episode);
            }
            allRadioEpisodes = allRadioEpisodes.OrderBy(e => e.Date).ToList();

            var expirationTime = ExpirationHelper.GetExpirationTime(HMPPS.Utilities.Settings.RadioEpisodesCacheTime);

            _cacheService.Store(cacheKey, allRadioEpisodes, expirationTime);

            return(allRadioEpisodes);
        }
コード例 #2
0
        public string GenerateJwtToken(IEnumerable <Claim> claims, string jwtTokenSecurityKey)
        {
            var tokenHandler = new JwtSecurityTokenHandler();

            var symmetricKey = Encoding.UTF8.GetBytes(jwtTokenSecurityKey);

            var now             = DateTime.UtcNow;
            var expiration      = ExpirationHelper.GetExpirationTime(86400); // 1 day in sec
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(claims),
                TokenIssuerName    = "self",
                AppliesToAddress   = _homePageAddress,
                Lifetime           = new Lifetime(now, expiration),
                SigningCredentials = new SigningCredentials(
                    new InMemorySymmetricSecurityKey(symmetricKey),
                    "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",
                    "http://www.w3.org/2001/04/xmlenc#sha256"),
            };

            var token       = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);

            return(tokenString);
        }