How to do it...

To create a state machine, follow these steps:

  1. Open ConVMSVehicleTable in the designer. Right-click on the State Machines node and choose New State machine.
  2. Rename the new state machine InspStateMachine and complete the properties shown in the following table by creating labels for the Description and Label properties:
Property Value
Description Use this to control the inspection status.
Label Inspection status.
Data Field

InspStatus.

  1. Right-click on the new state machine definition and select New State.
  2. Complete the properties of this state using the following table:
Property Value
Enum Value NotInspected. Change this to Waiting, and then back to the default Label property.
Description The vehicle has not been inspected yet.
Label Not inspected (this should be the label ID from the ConVMSVehInspStatus::NotInspected element label).
State Kind Initial.

 

We will create a state for each element in the ConVMSVehInspStatus Base Enum, so it is a good idea to create description labels in advance and just paste them in. Use named labels for this, not numeric. I use a suffix of HT, which is short for Help Text, for labels that are used for both help text and descriptions of elements.

  1. Create the remaining states using the following table as a guide:
Enum Value Name State Kind Description
Waiting Waiting Intermediate The vehicle is awaiting inspection.
PendingApproval PendingApproval Intermediate The vehicle inspection is pending approval.
Complete Complete Final The vehicle inspection is complete.
  1. The result should look as follows:
  1. Now, we need to tell the state machine the transition rules. We will define these rules as follows:
    • NotInspected can only transition to Waiting.
    • Waiting can only transition to InProgress.
    • InProgress can transition to both Waiting and Complete.
    • Complete is the final state and cannot transition backward.
  1. Again, create the labels in advance. The following table explains the type of wording we should use:
Label ID Label
VehTransWaiting Add to the waiting list.
VehTransWaitingHT Add the vehicle to the list of vehicles awaiting inspection.
VehTransPending Start inspection.
VehTransPendingHT Start the vehicle inspection process.
VehTransBackWaiting Revert to waiting.
VehTransBackWaitingHT Place the vehicle back onto the waiting list.
VehTransComplete Complete inspection.
VehTransCompleteHT Complete and finalize the vehicle inspection.
  1. Next, right-click on the NotInspected state and select New State transition. This time, the Label and Description properties define the action, not the state. Set the properties that will define the transition to the Waiting state as follows:
Property Value
Description @ConVMS:VehTransWaitingHT
Label @ConVMS:VehTransWaiting
Name TransitionToWaiting
Transition To State Waiting
  1. Add a new transition state to the WaitingState state while using the following table as a guide:
Property Value
Description @ConVMS:VehTransPendingHT
Label @ConVMS:VehTransPending
Name TransitionToInPending
Transition To State PeningApproval
  1. Next, add two transition states to the PendingApproval state. The first is to revert back to waiting:
Property Value
Description @ConVMS:VehTransBackWaitingHT
Label @ConVMS:VehTransBackWaiting
Name TransitionToWaiting
Transition To State Waiting

  1. The second state to add to the PendingApproval state completes the state machine and should be configured as follows:
Property Value
Description @ConVMS:VehTransCompleteHT
Label @ConVMS:VehTransComplete
Name TransitionToComplete
Transition To State Complete
  1. Save your changes. The result should look as follows:
  1. The final step is to right-click on the InspStateMachine state machine and click on Generate. This generates the code that will be used to control the inspection status' progression.
If you get an error stating Given key does not exist in the dictionary, this is happening because the name of the state did not match the Enum Value property. This may be changed in future releases so that it can be named differently.
  1. The generated classes may not be added to your project immediately. To do this manually, locate the classes that start with ConVMSVehicleTableInspStateMachine and drag them on to the Classes node of your project. Don't modify these classes; these are shown in the following screenshot: