Ejemplo n.º 1
0
 public static async Task <GetSireneAccessTokenResponse> RunAsync(GetSireneAccessTokenRequest request)
 {
     return(await RunAsync(
                request,
                GetLocalCacheKey,
                GetLocalCacheAsync,
                SetLocalCacheAsync
                ));
 }
Ejemplo n.º 2
0
        public static async Task <GetSireneAccessTokenResponse> RunAsync(
            GetSireneAccessTokenRequest request,
            GetCacheKey getCacheKey,
            GetCacheAsync getCache,
            SetCacheAsync setCache
            )
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (!request.IsValid)
            {
                throw new ArgumentException(nameof(request));
            }

            API.GetSireneAccessTokenResponse respAccessToken;

            if (request.IsCheckCache)
            {
                respAccessToken = await getCache?.Invoke(getCacheKey?.Invoke(request));

                if (respAccessToken != null)
                {
                    Configuration.Instance.LogInformation($"Sirene access token loaded from cache: {JsonConvert.SerializeObject(respAccessToken)}");
                }
                if (respAccessToken?.Age < AgeMax && !(respAccessToken?.IsExpired ?? true))
                {
                    Configuration.Instance.LogInformation("Sirene access token recycled.");
                    return(respAccessToken);
                }
                Configuration.Instance.LogInformation("Sirene access token out of date.");
            }

            Configuration.Instance.LogInformation("Request new Sirene access token.");

            respAccessToken = await GetSireneAccessTokenAsync();

            await setCache?.Invoke(getCacheKey?.Invoke(request), respAccessToken);

            return(respAccessToken);
        }
Ejemplo n.º 3
0
 public static string GetLocalCacheKey(GetSireneAccessTokenRequest request) => "sirene_token.json";