I spent some time today to apply some changes to a system Velocity IT and K2 built for a UK defence customer.
K2 blackearl is used for this workflow solution and ASP.NET is used as the UI (user interface) technology. The SourceCode.Workflow.Client .NET assembly is used to integrate the UI and the workflow.
K2 Automated Testing Software
BenchQA allows full test automation of K2, including fully automated K2 SmartForms and K2 Workflow testing. It promotes test driven development for K2 and ensures continued quality assurance for K2 solutions. Easily apply changes to test cases to accommodate changes to K2 apps and ensure all apps are regression tested to avoid defects and assure continuous quality.
The interesting part of this process is the use of System.Transactions to ensure all individual UI and K2 operations complete successfully to ensure the overall success of the transaction. One unwanted scenario is having an instantiated K2 workflow process that relies on some data, but data is missing due to an SQL exception after the K2 process is started. Transactions avoid these types of unwanted scenarios and ensure the overall integrity of the K2 system is maintained.
The code below demonstrates how both SQL and K2 participates in an atomic transaction.
1. using (TransactionScope ts = new TransactionScope())
{
2. db.SubmitChanges();
3. NewObject.ProcInstId = Workflow.StartSuggestionProcess(NewObject.Id);
4. db.SubmitChanges();
5. ts.Complete();
}
The code starts by defining a transaction scope (1) for the individual database (2, 4) and K2 operations (3). The StartSuggestionProcess operation is a helper method in the Workflow static class. It implements the SourceCode.Workflow.Client.Connection.StartProcessinstance method that creates a new instance of the K2 workflow process. If this process fails, the transaction won’t commit (5) and database changes won’t be applied.
An exception handler can be wrapped around the code to ensure the user is made aware of the failure and serials of the exception.
Transactions are important because they protect the overall integrity of a system. System.Transaction.TransactionScope is used to ensure that interdependent operations on the system (K2 and SQL in this example) are either all completed successfully or all cancelled successfully.