Tuesday, April 10, 2007

I'm also heading up a team that will be migrating existing businessprocesses to a workflow proces layer. It's exciting, because workflow foundation (WF) allows me to model an entire proces, instead of building small pieces and connecting them in code. This offers superior insight into the real businessproces and thus gives flexibility and power because for the first time, I can really sit down with an analist and explain 'code'. (our UML diagrams are outdated ;-) ). Because we then have a common understanding of the proces, we can feel at ease when modifying it.

Currently I'm working on having the workflow determine the 'actions' that a user (or machine) can perform in some state. WF has the ability to show the possible state transitions and that seems to be the logical piece of information I need to query and present to our client-side code (which well then enable/disable certain commands in the screens). However, it is completely useless because of two things:
1. it does not take into account the role a user is in
2. it will just display the possible transitions, but not the HandleExternalEventActivities (HEEA) that lead to them.

Therefor, I have build my own query. I'm aware that I've probably overlooked some hidden away funtionality, but until then, my code will do perfectly fine!

Given a workflow instance, I will first retrieve the waiting queue's. Then I will iterate the queueInfo objects. In my case, I will only use HEEA activities to handle the queue's, your workflow might differ. I will find that HEEA using the GetActivityByName method. Then I will check if it has roles assigned to it. I will simply check if the given role is in that array.
Next, I will have to lookup the correlationtoken, that might be used. If it is, I'm most interested in the correlationproperty. I will put that combination into my own struct (ProcesCommando). Add it to the list and return it!

ReadOnlyCollection<WorkflowQueueInfo> queues = instance.GetWorkflowQueueData();
foreach(WorkflowQueueInfo info in queues)
{
if(info.QueueName.Equals("SetStateQueue"))
{
continue;
}
else
{
foreach(string subscribedActivity in info.SubscribedActivityNames)
{
HandleExternalEventActivity heea =
instance.GetWorkflowDefinition().GetActivityByName(subscribedActivity) as HandleExternalEventActivity;

Debug.Assert(heea != null,
"Currently only expecting HandleExternalEventActivities");

#region check roles
if(heea.Roles != null)
{
// there are roles defined, so we need to check if the given role is included

bool inRole = false;
// TODO: use predicate
foreach (WorkflowRole workflowRole in heea.Roles)
{
if (workflowRole.Name.Equals(role.Name))
{
inRole = true;
break;
}
}

if (!inRole)
continue; // next subscribed activity.

// apparently the webworkflowrole does not implement equals and gethashcode correctly, so we can't do a 'contains'
// if(!heea.Roles.Contains(role))
// {
// // it does not, so this subscribed activity should never be executed
// continue;
// }
}
#endregion

#region possible correlation
string correlatie = String.Empty;
if (heea.CorrelationToken != null)
{
// there is a correlationtoken, so let's get the correlationproperty

EventQueueName queuename = info.QueueName as EventQueueName;
CorrelationProperty[] corProps = queuename.GetCorrelationValues();

Debug.Assert(corProps.Length == 1,
"Currently expecting exactly one correlation value");
correlatie = corProps[0].Value.ToString();
}

#endregion
ProcesCommands.Add(new ProcesCommando(heea.EventName, correlatie));
}
}

}
return ProcesCommands;

 

Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):