Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AsyncTaskCodeActivity #149

Merged
merged 13 commits into from
Jun 7, 2021
Merged

Conversation

Foxtrek64
Copy link
Contributor

@Foxtrek64 Foxtrek64 commented May 29, 2021

Fixes #145

  • Define VoidResult type (represents a void type since you can't return System.Void)
  • Define AsyncTaskCodeActivity type
  • Write unit tests
    • VoidResultTests
    • AsyncTaskCodeActivityTests

Usage Example:

public class DownloadWebPage : AsyncTaskCodeActivity<string>
{
    [RequiredArgument]
    [OverloadGroup("Address")]
    public InArgument<string> Url { get; set; }

    [RequiredArgument]
    [OverloadGroup("Address")]
    public InArgument<Uri> Uri { get; set; }

    protected override async Task<string> ExecuteAsync
    (
        AsyncCodeActivityContext context,
        CancellationToken cancellationToken
    )
    {
        var url = Url.Get(context);
        var uri = Uri.Get(context);

        var path = url ?? uri.AbsoluteUri;

        return await Download(path, cancellationToken);
    }

    private async Task<string> Download(string path, CancellationToken cancellationToken)
    {
        IFlurlResponse response = await path.GetAsync(cancellationToken);

        switch (response.StatusCode)
        {
            case 200:
                return await response.ResponseMessage.Content.ReadAsStringAsync();
            case 404:
                return "404: Not Found";
            default:
                return $"{response.StatusCode}: {response.ResponseMessage.ReasonPhrase}";
        }
    }
}

@Foxtrek64
Copy link
Contributor Author

PR is complete. Let me know if there are any changes you would like for me to make.

Also, sorry for the delay on this.

src/CoreWf/Attributes.cs Outdated Show resolved Hide resolved
src/CoreWf/VoidResult.cs Outdated Show resolved Hide resolved
@lbargaoanu lbargaoanu merged commit 411c9e2 into UiPath:master Jun 7, 2021
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add AsyncTaskCodeActivity type
2 participants