14 November, 2011

FIM 2010: How to use std. EnumerateResourcesActivity

This actually originates in an error in the Microsoft.RessourceManagement WF-activities, but none the less – it is a problem for many people on how to use this specific Activity.

When dragging on a EnumerateResourcesActivity to your design surface – you do not immediately see a lot of possibilities for enumerating the retrieved values! The only mandatory values you can set from the designer/properties dialog are:

- XPathFilter (what to search for…)
- ActorId (who is performing the readselection?)

After dragging on enumerateResourcesActivity to design surface    Empty propertyGrid

Why is it not possible to retrieve the values enumerated by the Activity? This is due to the fact that the Activity designer built-in to the EnumerateResourcesActivity is wrong. You unfortunately need to go into the <activity>.designer.cs file to correct these errors manually ;-)

Great – so how to do?

1) Open the designer-file (<activity>.Designer.cs) and add a new CodeActivity to the class.


2) Instantiate the CodeActivity and set properties after this.CanModifyActivities=true:


Important is of course the eventHandler (.ExecuteCode += ….) on the codeactivity. This event wiring will point to a method you add to your main code class like this:

private void RetrieveEnumeratedValues(object sender, EventArgs e)
//code missing…
3) Now – the most important piece is actually this. You need to add this custom made codeActivity as a childactivity to the fimEnumerate activity.
In this way you have bound together the EnumerateResourceActivity and your own CodeActivity. Next is only to actually implement the enumerate code we just wired up. This is quite simple but requires you to use a (non-intuitive) static method called (EnumerateResourcesActivity.GetCurrentIterationItem) like this;
private void RetrieveEnumeratedValues(object sender, EventArgs e)
//run though each resource found by fimEnumerate (NOTE: this is a static method!)
var currentItem = EnumerateResourcesActivity.GetCurrentIterationItem((CodeActivity)sender) as ResourceType;

if (currentItem != null)
//add to local list for later processing...
As seen if the currentItem (non-null) has a value – it is added to a local List<T> (m_lst) for later processing. The method will be called for each item the fimEnumerate activity has retrieved from FIM.
Again – another example of how (counter) intuitive FIM actually is to work with!

StackOverflow Tags:

No comments:

iPhone/XCode - not all cases are equal!

This bit me! Having made some changes to an iPhone application (Obj-C); everything worked fine in the simulator. But, when deploying the s...