Пример #1
0
    public async Task <ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        using var scope = _tracer?.StartSpan();

        try
        {
            Guard.Argument(ThreadUriString !).NotNull().NotEmpty().NotWhiteSpace();
        }
        catch (Exception exception)
        {
            scope?.Span.Log(exception);

            throw;
        }

        var uri = new Uri(ThreadUriString !, UriKind.Absolute);

        await foreach (var comment in _redditService.GetThreadCommentsAsync(uri))
        {
            foreach (var link in _messageService.GetLinksFromComment(comment))
            {
                Links.Add(link.OriginalString);
            }
        }

        scope?.Span.Log(
            nameof(ThreadUriString), ThreadUriString,
            "Links.Count", Links.Count);

        return(ExecutionResult.Next());
    }
Пример #2
0
    public Task <ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        using var scope = _tracer?.StartSpan();

        try
        {
            var(bytes, deliveryTag) = _messageQueueService.Consume();

            Guard.Argument(bytes)
            .NotNull()
            .NotEmpty()
            .DoesNotContain((byte)0);

            Message = System.Text.Encoding.UTF8.GetString(bytes);

            DeliveryTag = Guard.Argument(deliveryTag).Positive().Value;
        }
        catch (Helpers.RabbitMQ.Exceptions.QueueNotFoundException)
        { }
        catch (Helpers.RabbitMQ.Exceptions.QueueEmptyException)
        { }

        scope?.Span.Log(
            nameof(Message), Message,
            nameof(DeliveryTag), DeliveryTag
            );

        return(Task.FromResult(ExecutionResult.Next()));
    }
Пример #3
0
    public async Task <Uri> GetRandomSubredditAsync()
    {
        using var scope = _tracer?.StartSpan();

        var uri = new Uri("/r/random/.rss", UriKind.Relative);

        var headers = await _client.GetHeadersAsync(uri);

        var uriString = headers["Location"].Single();

        var subredditUri = new Uri(uriString, UriKind.Absolute)
                           .StripQuery();

        scope?.Span.SetTag(nameof(subredditUri), subredditUri.OriginalString);

        return(subredditUri);
    }
    public async Task <ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        using var scope = _tracer?.StartSpan();

        RandomSubredditUri = await _redditService.GetRandomSubredditAsync();

        scope?.Span.Log(
            nameof(RandomSubredditUri), RandomSubredditUri.OriginalString);

        return(ExecutionResult.Next());
    }
    public Task <ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        using var scope = _tracer?.StartSpan();

        Guard.Argument(DeliveryTag).NotNull().Positive();

        scope?.Span.Log(nameof(DeliveryTag), DeliveryTag?.ToString());

        _messageQueueService.Acknowledge(DeliveryTag !.Value);

        return(Task.FromResult(ExecutionResult.Next()));
    }
    public Task <ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        using var scope = _tracer?.StartSpan();

        Guard.Argument(Message !).NotNull().NotEmpty().NotWhiteSpace();

        scope?.Span.Log(nameof(Message), Message);

        var bytes = Encoding.UTF8.GetBytes(Message !);

        _messageQueueService.Publish(bytes);

        return(Task.FromResult(ExecutionResult.Next()));
    }
    public Task <ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        using var scope = _tracer?.StartSpan();

        Guard.Argument(Message !).NotNull().NotEmpty().NotWhiteSpace();

        MessageTypes = _evaluateMessageService.GetMessageTypes(Message !);

        Guard.Argument(MessageTypes)
        .NotNull()
        .NotEqual(Models.MessageTypes.None);

        scope?.Span.Log(
            nameof(Message), Message,
            nameof(MessageTypes), MessageTypes);

        return(Task.FromResult(ExecutionResult.Next()));
    }
Пример #8
0
    public async Task <ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        using var scope = _tracer?.StartSpan();

        Guard.Argument(UriString !).NotNull().NotEmpty().NotWhiteSpace().StartsWith("http");

        scope?.Span.Log(nameof(UriString), UriString);

        var uri = new Uri(UriString !, UriKind.Absolute);

        try
        {
            await _webClient.VisitLinkAsync(uri);
        }
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable CA1031  // Do not catch general exception types
        catch { }
#pragma warning restore CA1031  // Do not catch general exception types
#pragma warning restore IDE0079 // Remove unnecessary suppression

        return(ExecutionResult.Next());
    }
Пример #9
0
    public async Task <ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        using var scope = _tracer?.StartSpan();

        Guard.Argument(SubredditUriString !)
        .NotNull()
        .NotEmpty()
        .NotWhiteSpace()
        .Matches(@"^https:\/\/old\.reddit\.com\/r\/[_\d\w]+\/.rss\b");

        var subredditUri = new Uri(SubredditUriString !, UriKind.Absolute).StripQuery();

        await foreach (var uri in _redditService.GetSubredditThreadsAsync(subredditUri))
        {
            ThreadsUris.Add(uri.StripQuery().OriginalString);
        }

        scope?.Span.Log(
            nameof(SubredditUriString), SubredditUriString,
            "Count", ThreadsUris.Count);

        return(ExecutionResult.Next());
    }