Tank state machine
In this case we used a state machine of workflow foundation.
The
InitialState
wait an user interface event to set the manual dip.
The
SourceSelectionState
wait for source selection: manual / gauge.
The
QualityInspectionState
manage all quality inspection.
The
ConfirmationState
will manage user and SCADA confirmation.
The ReportingState will manage .NET code to compose a report and print (or
send via mail)
The TankReleasedForDistribution is the end of the state machine
The
Tank sample manager
will show you an asyncronous task with workflow foundation.
Initial state
Initialization
This is the first state of state machine. In real life job we can add here
more check as Is the tank available?, User is allowed to...? and so
on.
In this case we reset two variables that we use in next step
1private void setInternalVariables_ExecuteCode(object sender, EventArgs e)
2{
3 _TankHandoverConfirmation = false;
4 _TankHandoverScadaConfirmation = false;
5}
Set Tank Volume
This workflow wait for web service input (SetManualTankReading). After that convert
the value in volume. In this demo we didn't integrate the workflow with Mdf project
but this can be the code under convertManualDipreading:
1private void convertManualDipReadingToVolume_ExecuteCode(object sender, EventArgs e)
2{
3 Tank tank = new Tank("TankHandover");
4 ManualTankValue = ManualTankReading * tank.ConvertingFactor;
5}
After that, the flow check if the value is within tollerance or not.
Back
Source selection state
This state wait for a web service input to set the source value.
In this sample you can write client side some code as:
1protected void primaryTankSourceLinkButton_Click(object sender, EventArgs e)
2{
3 if (primaryTankSourceDropDownList.SelectedValue == "ManualDip")
4 {
5 TankHandover.SetPrimaryTankSource(PrimaryTankSource.ManualDip);
6 }
7 else
8 {
9 TankHandover.SetPrimaryTankSource(PrimaryTankSource.TankGauging);
10 }
11}
Pleace notice that you have to work with only a workflow instance a time. For that
reason we added the follow code to add the correct cookie to web service request.
1private TankHandover.TankHandover_WebService TankHandover
2{
3 get
4 {
5 TankHandover.TankHandover_WebService tankHandover =
6 new EmPy.WebUI.TankHandover.TankHandover_WebService();
7
8 Guid lastInstance = InstanceHelper.GetLastInstanceByTypeFullName("EmPy.TankHandover");
9 if (lastInstance != Guid.Empty)
10 {
11 tankHandover.CookieContainer = new System.Net.CookieContainer();
12 tankHandover.CookieContainer.Add(new Cookie("WF_WorkflowInstanceId",
13 lastInstance.ToString(), "/", "localhost"));
14 }
15
16 return tankHandover;
17 }
18}
In this way you can use one workflow instance from any web client (i.e. in
this use case you can have two users with two client in two different moments: one
for dip reading and one for quality inspection in an other office).
Back
Quality inspection state
This wait for quality inspection data. In real life job you can write a workflow
with a while activity to add all the needed data.
In Mdf you can use the EquipmentCapabilityTestResults to store the quality
inspection data. So you could write some code like:
1public void AddSomeQIData(string data)
2{
3 string equipmentCapabilityTestResultResultID = Sequence.GetNextValue("TestResult");
4 EquipmentCapabilityTestResult.Add(equipmentCapabilityTestResultResultID,
5 "Test on batch xxx", DateTime.Now, "RON", DateTime.MaxValue,
6 "TestDefinitionID", "1.0", "TankHandover", "Octane");
7
8 string resultID = Sequence.GetNextValue("Result");
9 ASCIIEncoding asciiEncoding = new ASCIIEncoding();
10 ResultsOfEquipmentCapabilityTestResult.Add(resultID, asciiEncoding.GetBytes(data),
11 equipmentCapabilityTestResultResultID);
12}
Back
Confirmation state
The initial anction of this state ask to SCADA a confirmation.
After that we can found two similar sequences that wait for a web service event
(one for user and one for SCADA)
Notice that we check if either activities was completed by the follow code:
1private void CheckConfirmationState(object sender, ConditionalEventArgs e)
2{
3 e.Result = _TankHandoverConfirmation && _TankHandoverScadaConfirmation;
4}
Back
Tank sample manager
This is the TankSampleManager flow that expose a web method (NewTankDataSampleAvailable)
to save new Tank data.
The storeTankDataSample activity will call some method to store data into
database.
1private void saveData()
2{
3
4
5 double sampleValue = ((Random)(new Random())).NextDouble() * 1000;
6
7
8 TankSampleManager.TankSampleManager_WebService tankSampleManager =
9 new EmPy.TMS.WebUI.TankSampleManager.TankSampleManager_WebService();
10
11 tankSampleManager.NewTankDataSampleAvailable(sampleValue);
12}
Back