Skip to main content

I am in the process of writing a server-side event wizard (code) and I'm at the point where I want my activity to have a number of actions outcomes coming out of it (success / failure, for example).


Looking at the default client event, it appears to do the following:


a) Create a data field called "outcome"
b) Create actions, as per user entered data
c) Create a line corresponding to each action
d) Put a rule on each line checking "outcome" to determine if the corresponding action has been taken.


Now, I can create the data field in code in the wizard, like so:



if (!base.Event.Activity.DataFields.Contains("Outcome"))
{
    DataField outcome = new DataField("Outcome", "");
    outcome.Category = "Outcomes";
    base.Event.Activity.DataFields.Add(outcome);
}



Attempting to create actions, like so, results in the error "only client events can have actions"



if (!base.Event.Actions.Contains("Success"))
{
    EventAction success = new EventAction();
    success.Name = "Success";
    base.Event.Actions.Add(success);
}
if (!base.Event.Actions.Contains("Failure"))
{
    EventAction failure = new EventAction();
    failure.Name = "Failure";
    base.Event.Actions.Add(failure);
}



Also, creating lines & linerules looks to be impossible since those are abstract classes.


So, I am at a bit of a loss. How do I have multiple paths leading out of my server event based on the results of said server event execution?


Thank you

Unfortunately I can't think of a way because as the error implies, Actions only apply to activities with client events.

Ok, what I have done is changed my event to be a client event (not sure what the implications of this are). Now I can create my actions programatically, but I still don't have any lines coming out of my activity.


 My guess would be I have to add the lines programatically, but as I mentioned, the line and linerule classes are abstract.


If there is a better way to do this or if I am barking up the wrong tree, please let me know.


Basically, I have an event which executes some C# code, which calls a web service, which will either succeed or fail, that success or failure should then determine the path the process should follow (e.g. retry, log failure, notify user, etc).


Ok, I realised a few truths today. Firstly, using a client event is not what I need, so I have scrapped that idea.


I also discovered that DefaultLine and DefaultLineRule are the concrete implementations of Line and LineRule. So, in order to add lines to my activity, I need to do the following:



DefaultLine success = new DefaultLine();
success.StartActivity = base.Event.Activity;
success.MetaData = "Success";
success.Name = "Success";
DefaultLineRule successRule = new DefaultLineRule();
successRule.PropertyName = "Outcome";
success.LineRule = successRule;


DefaultLine failure = new DefaultLine();
failure.StartActivity = base.Event.Activity;
failure.MetaData = "Failure";
failure.Name = "Failure";


DefaultLineRule failureRule = new DefaultLineRule();
failureRule.PropertyName = "Outcome";
failure.LineRule = failureRule;


base.Extender.Process.Lines.Add(success);
base.Extender.Process.Lines.Add(failure);


Great, brilliant, sensational.


The problem now is that these lines don't appear to be very well behaved lines. When I try to wizard them to find out if the rules have been set properly, I get the process wizard rather than the line wizard.


Ok, no problem, I add these lines to set the wizard correctly:



success.WizardDefinition = new DefaultLineWizardDefinition();
failure.WizardDefinition = new DefaultLineWizardDefinition();


That works up to a point, but then it complains about a missing "WizardElement", so I am stuck again. I have a feeling it may be related to the corresponding propertywizard, but I am not sure.


It turns out that what I really wanted to do was create outcomes, and then based on those outcomes create a bunch of lines with rules on them, depending on what the outcome was. I have no need for actions because actions are intended to be invoked by a user.


To create outcomes, you first need to create an SucceedingRule of type DefaultOutcomeSucceedingRule:



base.Event.Activity.SucceedingRule = new DefaultOutcomeSucceedingRule();


Once you have this rule, you can attach new OutcomeItem objects to it.



OutcomeItem item = new OutcomeItem(rule);
rule.Outcomes.Add(item);
item.Name = "Success";


Finally, once you have your outcomeitems created and attached to your OutcomeSucceedingRule, you can generate the lines and rules automagically through this call:



SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultLinesForOutcomes(rule);


Now, all I need to do is figure out how to trigger an outcome :)


Reply