예제 #1
0
 public void Build(IWorkflowBuilder builder)
 {
     builder
     .HttpEndpoint("/hello-world")
     .When(OutcomeNames.Done)
     .WriteHttpResponse(HttpStatusCode.OK, "<h1>Hello World!</h1>", "text/html");
 }
예제 #2
0
 public void Build(IWorkflowBuilder builder)
 {
     builder
     .HttpEndpoint("/faulty")
     .Then(MaybeThrow)
     .WriteHttpResponse(response => response.WithStatusCode(HttpStatusCode.OK).WithContentType("application/json").WithContent(WriteWorkflowInfoAsync));
 }
예제 #3
0
 public void Build(IWorkflowBuilder builder)
 {
     builder
     .HttpEndpoint(activity => activity.WithPath("/faulty").WithMethod(HttpMethod.Get.Method))
     .WriteLine("Catch this!")
     .Then(() => throw new ArithmeticException("Does not compute", new ArgumentException("Incorrect argument", new ArgumentOutOfRangeException("This is the root problem", default(Exception)))));
 }
예제 #4
0
 public void Build(IWorkflowBuilder builder)
 {
     builder
     .HttpEndpoint("/test")
     .Then <ReadQueryString>()
     .WriteHttpResponse(_ => HttpStatusCode.OK, GenerateSomeHtml, _ => "text/html");
 }
예제 #5
0
 public void Build(IWorkflowBuilder builder)
 {
     builder
     .HttpEndpoint("/_workflows/hello")
     .WriteLine(context =>
                $"Hello from Elsa! (correlationId={this.GetCorrelationId(context)})")
     .WriteHttpResponse(HttpStatusCode.OK, $"Hello from Elsa!", "text/html");
 }
    public void Build(IWorkflowBuilder builder)
    {
        builder
        // Build an endpoint that receives user credentials.
        .HttpEndpoint(httpEndpoint => httpEndpoint
                      .WithPath("/users/signup")
                      .WithMethod(HttpMethods.Post)
                      .WithReadContent()
                      .WithTargetType <User>())

        // Store the user in the database;
        .Then <StoreUser>(storeUser => storeUser
                          .WithUser(context => context.GetInput <HttpRequestModel>() !.GetBody <User>() with {
        }));
예제 #7
0
 public void Build(IWorkflowBuilder builder)
 {
     builder
     .HttpEndpoint(setup => setup
                   .WithPath("/safe-hello")
                   .WithMethod("GET")
                   .WithAuthorize()
                   .WithPolicy("IsAdmin"))
     .WriteHttpResponse(setup => setup.WithStatusCode(HttpStatusCode.OK)
                        .WithContent(context =>
     {
         var httpContext = context.GetService <IHttpContextAccessor>().HttpContext !;
         var user        = httpContext.User;
         return($"Hello {user.Identity!.Name}!");
     }));
 }
예제 #8
0
        public void Build(IWorkflowBuilder builder)
        {
            var serializer = builder.ServiceProvider.GetRequiredService <IContentSerializer>();

            builder
            // Configure a Receive HTTP Request trigger that executes on incoming HTTP POST requests.
            .HttpEndpoint(activity => activity.WithPath("/contacts").WithMethod(HttpMethods.Post).WithTargetType <Contact>()).WithName("HttpRequest")

            // Write something to the console to demonstrate that we can receive the outcome of the previous activity (HttpRequest) as an input to this WriteLine activity.
            .WriteLine(context => $"Received some contact details: {JsonConvert.SerializeObject(context.Input)}")

            // Write an HTTP response to demonstrate that we can access any activity's outcome using the activity name.
            .WriteHttpResponse(activity => activity
                               .WithStatusCode(HttpStatusCode.OK)
                               .WithContentType("application/json")
                               .WithContent(context =>
            {
                var request = context.GetOutputFrom <HttpRequestModel>("HttpRequest");
                var contact = request !.GetBody <Contact>();
                return(serializer.Serialize(contact));
            }));
        }
예제 #9
0
        public void Build(IWorkflowBuilder builder)
        {
            builder
            // Configure a Receive HTTP Request trigger that executes on incoming HTTP POST requests.
            .HttpEndpoint(activity => activity.WithPath("/register").WithMethod(HttpMethods.Post).WithTargetType <Registration>())

            // Store the registration as a workflow variable for easier access.
            .SetVariable(context => (Registration)((HttpRequestModel)(context.Input))?.Body)

            // Correlate the workflow by email address.
            .Correlate(context => context.GetVariable <Registration>() !.Email)

            // Write an HTTP response with a hyperlink to continue the workflow (notice the presence of the "correlation" query string parameter).
            .WriteHttpResponse(activity => activity
                               .WithStatusCode(HttpStatusCode.OK)
                               .WithContentType("text/html")
                               .WithContent(context =>
            {
                var registration = context.GetVariable <Registration>() !;
                return($"Welcome onboard, {registration.Name}! Please <a href=\"http://localhost:8201/confirm?correlation={registration.Email}\">confirm your registration</a>");
            }))

            // Configure another Receive HTTP Request trigger that executes on incoming HTTP GET requests.
            // This will cause the workflow to become suspended and executed once the request comes in.
            .HttpEndpoint(activity => activity.WithPath("/confirm"))

            // Write an HTTP response with a thank-you note.
            // Notice that the correct workflow instance is resumed base on the incoming correlation ID.
            .WriteHttpResponse(activity => activity
                               .WithStatusCode(HttpStatusCode.OK)
                               .WithContentType("text/html")
                               .WithContent(
                                   context =>
            {
                var registration = context.GetVariable <Registration>();
                return($"Thanks for confirming your registration, {registration.Name}!");
            }));
        }
예제 #10
0
 public void Build(IWorkflowBuilder builder) => builder
 .HttpEndpoint("/wf")
 //.StartWith<StartActivity>(c => c.ActivityId = "start")
 .Then <TestActivity>(c => c.ActivityId = "test")
 .WriteLine("Hello World!");
예제 #11
0
        public void Build(IWorkflowBuilder builder)
        {
            builder
            .HttpEndpoint(activity => activity
                          .WithMethod(HttpMethod.Post.Method)
                          .WithPath("/documents")
                          .WithReadContent())
            .SetVariable("Document", context => context.GetInput <HttpRequestModel>() !.Body)
            .WriteLine(context => $"Document received from {context.GetVariable<dynamic>("Document")!.Author.Name}")
            .WriteHttpResponse(activity => activity
                               .WithContent(context => "<h1>Request for Approval Sent</h1><p>Your document has been received and will be reviewed shortly.</p>")
                               .WithContentType("text/html")
                               .WithStatusCode(HttpStatusCode.OK).WithResponseHeaders(new HttpResponseHeaders {
                ["X-Powered-By"] = "Elsa Workflows"
            })
                               )
            .Then <Fork>(fork1 => fork1.WithBranches("Jack", "Lucy"), fork1 =>
            {
                fork1
                .When("Jack")
                .WriteLine(context => $"Jack approve url: \n {context.GenerateSignalUrl("Approve:Jack")}")
                .Then <Fork>(fork2 => fork2.WithBranches("Approve", "Reject"), fork2 =>
                {
                    fork2
                    .When("Approve")
                    .SignalReceived("Approve:Jack")
                    .SetVariable("Approved", context => context.SetVariable <int>("Approved", approved => approved == 0 ? 1 : approved))
                    .ThenNamed("JoinJack");

                    fork2
                    .When("Reject")
                    .SignalReceived("Reject:Jack")
                    .SetVariable <int>("Approved", 2)
                    .ThenNamed("JoinJack");
                }).WithName("ForkJack")
                .Add <Join>(x => x.WithMode(Join.JoinMode.WaitAny)).WithName("JoinJack")
                .ThenNamed("JoinJackLucy");

                fork1.When("Lucy")
                .WriteLine(context => $"Lucy approve url: \n {context.GenerateSignalUrl("Approve:Lucy")}")
                .Then <Fork>(fork2 => fork2.WithBranches("Approve", "Reject"),
                             fork2 =>
                {
                    fork2
                    .When("Approve")
                    .SignalReceived("Approve:Lucy")
                    .SetVariable("Approved", context => context.SetVariable <int>("Approved", approved => approved == 0 ? 1 : approved))
                    .ThenNamed("JoinLucy");

                    fork2
                    .When("Reject")
                    .SignalReceived("Reject:Lucy")
                    .SetVariable <int>("Approved", 2)
                    .ThenNamed("JoinLucy");
                }).WithName("ForkLucy")
                .Add <Join>(x => x.WithMode(Join.JoinMode.WaitAny)).WithName("JoinLucy")
                .ThenNamed("JoinJackLucy");
            }
                         )
            .Add <Join>(x => x.WithMode(Join.JoinMode.WaitAll)).WithName("JoinJackLucy")
            .WriteLine(context => $"Approved: {context.GetVariable<int>("Approved")}").WithName("AfterJoinJackLucy")
            .If(context => context.GetVariable <int>("Approved") == 1, @if =>
            {
                @if
                .When(OutcomeNames.True)
                .WriteLine(context => $"Document ${context.GetVariable<dynamic>("Document")!.Id} approved!`");

                @if
                .When(OutcomeNames.False)
                .WriteLine(context => $"Document ${context.GetVariable<dynamic>("Document")!.Id} rejected!`");
            });