コード例 #1
0
    private async Task StartGettingQuotesAsync(string language)
    {
        var db = _connectionMultiplexer.GetDatabase();

        var iteration = 0;
        var count     = await db.SetLengthAsync(GetRedisKey(language))
                        .ConfigureAwait(false);

        while (count < CacheSize)
        {
            var text = await _textRetriever.GetNextTextValue(language)
                       .ConfigureAwait(false);

            await db.SetAddAsync(GetRedisKey(language), text)
            .ConfigureAwait(false);

            iteration++;

            if (iteration > 50)
            {
                count = await db.SetLengthAsync(GetRedisKey(language))
                        .ConfigureAwait(false);
            }
        }
    }
コード例 #2
0
    private async Task StartGettingQuotesAsync(string language)
    {
        while (_quoteQueues[language].Count < CacheSize)
        {
            var text = await _textRetriever.GetNextTextValue(language)
                       .ConfigureAwait(false);

            _quoteQueues[language].Enqueue(text);
        }
    }
コード例 #3
0
    public async ValueTask <string> GenerateTextAsync(TextGenerationConfigurationDto configuration)
    {
        if (!IsSupported(configuration.Language))
        {
            throw new NotSupportedException($"Language {configuration.Language} is not supported.");
        }

        if (configuration.Length < 0)
        {
            throw new InvalidOperationException("Cannot have negative length.");
        }

        var minLength = configuration.Length == 0
            ? 10 // Default value.
            : configuration.Length;

        var builder = new StringBuilder();

        while (builder.Length < Math.Min(minLength, MaxTextLength))
        {
            var quoteFromApi = await _textRetriever.GetNextTextValue(configuration.Language)
                               .ConfigureAwait(false);

            var chunks = configuration.TextType == Texts.TextStructure.Words
                ? quoteFromApi.Split('.').SelectMany(x => x.Split(' '))
                : quoteFromApi.Split('.');

            // TODO: Account for spaces.
            foreach (var chunk in chunks)
            {
                var allowed = true;
                foreach (var letter in chunk)
                {
                    if (!_allowedLetters.Contains(letter))
                    {
                        allowed = false;
                        break;
                    }
                }
                if (!allowed)
                {
                    continue;
                }

                if (configuration.ShouldContain.Count() > ShouldContainMinCount)
                {
                    allowed = false;
                }

                if (!allowed)
                {