Friday, 14 October 2011

Constraining Dropped Activities

In my last post I described making modifications to the standard FlowDecision activity to make it more usable, and mentioned there were a couple of modifications I needed to make to the code to make it more usable.

One is constraining the types of activity that can be dropped into the FlowDecision. Where I left off on that last post was something that looked as follows…


The problem here is at present I can drop anything into the FlowDecision – instead I need to constrain this to only activities that return a boolean result, i.e. something derived from Activity<Boolean>. I’m using the WorkflowItemPresenter in my designer and there’s a property on there named AllowedItemType which does just the job – however what I need to do is be able to pass a generic type into this type. A quick search around the web had something close, so here’s what I now have in the XAML…

local:GenericType x:Key="mustReturnBool" BaseType="{x:Type sa:Activity`1}"
TypeParam="{x:Type sys:Boolean
}" />

sap:WorkflowItemPresenter Item="{Binding ModelItem.Condition}"
HintText="Drop a condition here" AllowedItemType="{StaticResource mustReturnBool

So here I have a markup extension (local:GenericType) and have referenced this in the workflow item presenter. The markup extension defines the class we’re deriving from which is a generic type taking one argument so is defined as Activity`1 (if this took 3 arguments you would define this as Activity`3). I’ve then defined the type parameter as an instance of Boolean, and so at runtime this will create a type which is Activity<Boolean>.

Note: If you happen to cut & paste the line from the XAML that includes sa:Activity`1 this will (most annoyingly) be pasted back in as sa:Activity’1 – i.e. the grave character has been replaced with a single quote. So, beware!

The markup extension is shown below…

/// <summary>
A markup extension allowing generic types to be used in XAML
/// </summary>
public class GenericType :
/// <summary>
Defines the base type to derive from
/// </summary>
public Type BaseType { get; set; }

/// <summary>
Defines the collection of type parameters
/// </summary>
public Type[] TypeParams { get; set; }

/// <summary>
Defines the singular type parameter
/// </summary>
public Type TypeParam { get; set; }

/// <summary>
Default constructor
/// </summary>
public GenericType() { }

/// <summary>
Return the generic type constructed from the base Type and Type parameters
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
public override object ProvideValue(IServiceProvider serviceProvider)
Type retVal = null;

if (null != TypeParam)
retVal = BaseType.MakeGenericType(TypeParam);
retVal = BaseType.MakeGenericType(TypeParams);
return retVal;

With this in place I can try dragging any old activity onto the FlowDecision and now it won’t permit me to drop anything other than activities that derive from the correct type.

The Code

I’ve updated the code from the last article to include this new capability. Click here to download a .zip.


frankie said...

If you are a good developer and have good logical skills then you must start your own network. Because i can see a potential in you that what i guess from your blog.

Oliver Maurice said...

This blog article has all the info you need to know on how to write good essay structure so make sure to check it out

Julie T. Kirwan said...

asphalt xtreme mod apk jurassic survival mod apk dragon mania legends mod apk

guri said...

This blog article has all the info you need to know on how to write good essay structure. If you are a good developer and have good logical skills then you must start your own network

Sophie Grace said...

Excellent article! We are linking to this particularly great article on our website. Keep up the great writing. net worth

guri said...

This blog articlehas all the info you need to know on how to write good essay structure so make sure to check it out.

meldaresearchusa said...

We offer medicine essay writing that meets all the instructions that the client provided and they also seek the services of cheap nursing term papers and observe the academic writing standards that students should follow.

Angel Claudia said...

In order to provide quality custom research papers when client seek pre written research papers, we have hired professional custom writing services writers who can provide students with help in their business courses.

jacklinemelda said...

Our essay writing help service services are very affordable as we provide you with work that is at a golden equilibrium, try our top paper writing services today.

Assignment Help said...

We offer best and Successful solutions to increase your academic grade. so contact us.
MBA Assignment Help

harsh sharma said...

Tutuapp Apk

Showbox Apk

Spotify Premium Apk

Psiphon for PC

Netflix Premium Apk

WPA WPS Tester Premium Apk

Puremelda said...

Ensuring our clients get 100% Already Written Essay Writing Services is one of the strategies we have adopted in becoming the best provider of do Literature Review Service in the industry.

Puremelda said...

Our top-notch writers have access to peer-reviewed articles, Essay Writer Services and online databases that are essential in writing Best Custom Writing Services on any chosen topic.

meldaresearchusa said...

Anyone seeking high-quality Purchase Term Paper will want to hire a qualified writer to handle their Custom College Papers on time and offer best Custom Papers for College.

Florahmelda said...

Students seek professional Custom Papers Writing assistance from Top Rated Term Papers Writingcompany to accomplish any type of essay assigned to them. When you request for urgent Professional Custom Research Paper, they strive to meet your professors’ requirements.

Puremelda said...

Custom Term Paper Service industry has grown steadily in provision of Legitimate Term Paper Services and high quality Custom Term Paper Writing Services which is preferred by scholars worldwide.

Sankar said...

I have read your blog its very attractive and impressive. I like it your blog.
Final Year Projects for CSE in Dot Net

.Net Training in Chennai

Final Year Project Centers in Chennai

Dot Net Training in Chennai

Sam said...

At MyAssignmenthelp, our professional writers provide custom assignment help for the students who want to excel in their academics.

noor said...

افضل شركة تنظيف بالمدينة المنورة

شركة مكافحة حشرات بالمدينة المنورة

شركة تنظيف بالمدينة المنورة

شركة تنظيف منازل بالمدينة المنورة

shorya said...

Browse through the best fitness bands under 5000 with wide range of facilities and offers. Get the best fitness tracker in India. best fitness band in india under 5000

Mihir Mane said...

Hire freelance models, singers, actors for your next upcoming project for any artists job. Browse latest models portfolio, singers, make it female actor and actress in India. jobs for dancers

abhikhurana said...

Become a Santa for you parents and gift them with the best and amazing unique gifts. Buy best gifts for parents and get exciting offers for every purchase. gifts for brother

sanjupawar said...

One stop for all your requirements for viral news, know what is happening around India, get all the details at your fingertip. india trending

Survey said...

Very good write-up. I certainly love this website. lowes survey

albertsons survey

. walmart survey

Adele Hansley said...

Thanks for sharing, Sample assignment is the best assignment experts that provides CHC33015 Assessment Answers. Due to many different reasons, such as less time, subject knowledge etc, university students find it complex to craft their assignments on time.