A small example of using Workflow Core as part of an ASP.NET Core 5 web application.
Usage:
- Clone this repository.
- Create a C:\Development\SmtpPickupDirectory directory. Emails generated by the system get placed here.
- Open the solution in Visual Studio 2019.
- Run WorkflowCoreWebsite project.
- Browse to https://localhost:44389/Home/Contact
- Submit the contact form.
- [GUID].eml files should get added to the C:\Development\SmtpPickupDirectory folder.
- Use an email client like Outlook or Thunderbird to view the .eml files.
- Watch a couple emails get added to that folder by waiting for a couple minutes. It'll be the same email repeated.
- Clicking the "Acknowledge receipt" link in an email will stop the emails from being sent for that contact form submission.
Explanation:
- When the form on the Home/Contact page is submitted a "ContactFormWorkflow" is started with the data from the form.
- The ContactFormWorkflow.cs waits for a "ContactFormAcknowledged" event, and starts a recurring step in parallel that resends an email with the information in the form every 30 seconds until the email is acknowledged by going to the URL provided by the "Acknowledge receipt" link.
- Clicking the "Acknowledge receipt" runs the Home/Ack/{id} controller action, which fires the "ContactFormAcknowledged" with the key (
id
in the context of the action) that is provided. - The "ContactFormAcknowledged" event triggers wait for event step in the ContactFormWorkflow that then changes ContactForm.Acknowledged from
false
totrue
using theOutput
step. That finishes the wait for step. - The next time the recurring step checks its
until
condition (remember, it runs every 30 seconds) it will see that ContactForm.Acknowledged is nowtrue
, skip performing its action, and finish the step. - The completion of both steps within the parallel step will result in the parallel step finishing.
- The parallel step is the last step, once it completes, the workflow completes.
Key classes and methods:
- Controllers.HomeController.Contact methods
- Controllers.HomeController.Ack method
- Workflows.ContactFormWorkflow class
- Workflows.Steps.EmailAdmins class
- Startup class