public void Build(IWorkflowBuilder builder)
 {
     builder.Add <WatchDirectory>(setup =>
     {
         setup.Set(x => x.Directory, "C:\\Temp\\FileWatcher2");
         setup.Set(x => x.ChangeType, WatcherChangeTypes.Created);
     })
     .WriteLine("FileWatcherWorkflowSkip received file");
 }
예제 #2
0
        public void Build(IWorkflowBuilder builder)
        {
            // Demonstrating that we can create activities and connect to them later on by using the activity builder reference.
            var join = builder.Add <Join>(x => x.WithMode(Join.JoinMode.WaitAny));

            join.Finish();

            builder
            // The workflow context type of this workflow.
            .WithContextType <Document>()

            // Accept HTTP requests to submit new documents.
            .HttpEndpoint <Document>("/documents")

            // Store the document as the workflow context. It will be saved automatically when the workflow gets suspended.
            .Then(context => context.SetWorkflowContext(context.GetInput <HttpRequestModel>() !.GetBody <Document>())).LoadWorkflowContext()

            // Write an HTTP response.
            .WriteHttpResponse(
                activity => activity
                .WithStatusCode(HttpStatusCode.OK)
                .WithContentType("text/html")
                .WithContent(context => $"Document received with ID {GetDocumentId(context)}! Awaiting Approve or Reject response."))

            // Fork execution into two branches: an Approve branch and a Reject branch.
            .Then <Fork>(
                fork => fork.WithBranches("Approve", "Reject"),
                fork =>
            {
                var approveBranch = fork
                                    .When("Approve")
                                    .HttpEndpoint <Comment>(context => $"/documents/{GetDocumentId(context)}/approve")
                                    .Then(StoreComment);

                var rejectBranch = fork
                                   .When("Reject")
                                   .HttpEndpoint <Comment>(context => $"/documents/{GetDocumentId(context)}/reject")
                                   .Then(StoreComment);

                WriteResponse(approveBranch, document => $"Thanks for approving document {document!.DocumentId}!").Then(join);
                WriteResponse(rejectBranch, document => $"Thanks for rejecting document {document!.DocumentId}!").Then(join);
            });