public async Task <List <BkTag> > GetHotAsync()
    {
        var sw = Stopwatch.StartNew();
        var re = await GetHotAsyncCore();

        _logger.LogInformation("Get Hot Tags cost {Time} ms", sw.ElapsedMilliseconds);
        return(re);

        async Task <List <BkTag> > GetHotAsyncCore()
        {
            var options = await _userOptionsService.GetOptionsAsync();

            var all = await _tagsRepo.GetAllAsync();

            var result = all
                         .Where(x => x.RelatedBkCount > 0)
                         .OrderByDescending(x => x.ClickedCount)
                         .ThenByDescending(x => x.LastClickTime)
                         .ThenByDescending(x => x.RelatedBkCount)
                         .Take(options.HotTagsFeature?.ListCount ?? 10)
                         .ToList();

            return(result);
        }
    }
Esempio n. 2
0
    public async Task RunAsync()
    {
        var userOptions = await _userOptionsService.GetOptionsAsync();

        await Task.Delay(TimeSpan.FromSeconds(5));

        var now = DateTime.Now;

        if (userOptions?.PinyinFeature?.Enabled == true &&
            userOptions.PinyinFeature?.ExpireDate.HasValue == true &&
            userOptions.PinyinFeature.ExpireDate < now.AddDays(Consts.JwtExpiredWarningDays))
        {
            var days = (userOptions.PinyinFeature.ExpireDate.Value - now).Days;
            if (Math.Abs(days) < Consts.JwtExpiredWarningDays)
            {
                await _newNotification.PinyinTokenExpiredAsync(new PinyinTokenExpiredInput
                {
                    LeftDays = days
                });
            }
        }

        if (userOptions is
        {
            AcceptPrivacyAgreement : true,
            CloudBkFeature :
            {
                Enabled : true
            }
        })
    public async ValueTask StartAsync()
    {
        var userOptions = await _userOptionsService.GetOptionsAsync();

        if (userOptions is
        {
            AcceptPrivacyAgreement : false
        })
    public async Task <ServiceItem> CreateAsync()
    {
        var options = await _userOptionsService.GetOptionsAsync();

        var cloudBkProviderType = options.CloudBkFeature !.CloudBkProviderType;

        _logger.LogInformation("current provider: {CloudBkProviderType}", cloudBkProviderType);
        var service = _lifetimeScope.ResolveKeyed <ICloudService>(cloudBkProviderType);

        return(new ServiceItem(cloudBkProviderType, service));
    }
Esempio n. 5
0
    protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        var options = await _userOptionsService.GetOptionsAsync();

        var token = options?.PinyinFeature?.AccessToken;

        if (!string.IsNullOrEmpty(token))
        {
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", $"id_token=\"{token}\"");
        }
        //potentially refresh token here if it has expired etc.
        return(await base.SendAsync(request, cancellationToken).ConfigureAwait(false));
    }