How to assign a default value at runtime with Workflow Foundation WF4? - workflow

Using Windows Workflow Foundation WF4, I've got a custom activity with a System.Guid property called UniqueId.
I want the user to be able to drag my activity onto a workflow and have it automatically generate a new GUID value for UniqueId.
What's the easiest way to assign a new, read-only GUID value to this property at design time?

The trick is to use an IActivityTemplateFactory and in the Create() build the activity with default properties as you want it. Then you add the IActivityTemplateFactory instead of the activity itself to the toolbox.

Related

In automic how to communicate between the job in workflow?

As we know that one job can call in multiple workflow.
I need an variable which give me the workflow name at time of runtime so that I can write this information in log.
It should not be global variable. it must be define with in the scope of workflow.
In the process tab - where I assume your code is and where you need the parent object (workflow in your case) - you can click on the "Variables..." menu item.
In the popped up variable picker you need to change to "Object" for "Category" and pick "Processor (name)".
This will provide the name of the superordinate (fancy word for parent) object - in your case the Workflow. Also available would be "Processor (RunID)" providing the ID.
This will insert the "system-variable" &$PROCESSOR#, which holds the name of the parent object or you simple copy that variable from my answer :)

AnyLogic - create objects dynamically on simulation time

Is it possible to dynamically create objects or modify them on run-time ?for example,on button click,another button created or change number of lines of a road?
When I write this code for a button Action,in run-time
road123.setBackwardLanesCount(3);
I get error below:
root:
road123: Markup element is already initiated and cannot be modified.Please use constructor without arguments,perform setup and finally call initialize() .function
You'll get that error with any object you attempt to create at runtime using a parameterized constructor. If you create the object with a simple constructor (just "()") and then set all of the parameters individually, you won't run into that issue. Check the Anylogic API for specific information about the object you are using, because some require you to call .initiliaze() on that object after setting all of it's parameters if you created it using a simple constructor. Furthermore, if you want to add the object to the screen at runtime you'll need to add this code to the function that creates it:
#Override
public void onDraw( Panel panel, Graphics2D graphics) {
obj.drawModel(panel, graphics, true);
}
where obj is replaced with the name of the object you created dynamically.

How to access the value of a Property argument from nested activities?

I'm sure there's something I'm missing here, but a lot of Googling hasn't uncovered it for me. The situation is like this:
We created a custom workflow designer that allows end users to build workflow definitions from various custom activities we define (Review, Submit, Notify, etc). These definitions (Xaml) get saved off to a Db and used to create workflow instances for long running processes in our system. The users can set properties on each of them (e.g. Review has a property argument: AllowedRoles). The problem is, I'm not able to pass those properties on to nested activities.
For example:
Review has an internal activity 'WriteStatus' that needs access to the 'AllowedRoles' property on Review. If 'AllowedRoles' is defined as a Property, WriteStatus can't "see" it to assign it's value. I can change it from a Property to an InArgument, but then I'm not able to map values to and from the property in the designer (these properties should be part of the definition, and not associated with any specific context).
Has anyone faced this issue or have advice on how I could approach the problem differently?
Thanks in advance!
Royce
I was able to get around the property vs InOurArgument problem by converting the XAML activities to code. This allowed me to set the properties on activities in code, and then pass them to inner activities inline. There may be a better way, but it's working out well so far.
public sealed class Test : Activity
{
public string Stuff { get; set; } // CLR Property
public Test()
{
Implementation = () => new WriteLine {Text = Stuff};
}
}

access class property in workflow foundation

so i am already invoking a workflow activity, with the "dataSet" containing an instance of my class Employee...
WorkflowInvoker.Invoke(wfManager.Activity, dataSet);
My Employee has a property called Department.
What i want is to edit a condition in my workflow xaml, but i am going to make it like this:
Employee.Department == "RND"
i am doing this in VS2012, and when i type Employee in the condition editor, i cannot access its properties. I just put my activity xaml file in the same project with my Employee class. What should i do more to access my class properties inside the activity xaml?
Basically you need to define an InArgument and map the external data to the arguments using a Dictionary. With that in place the object is available through the argument name.
See this blog post on how to pass data to an workflow.

Setting a dependency property's default value at design time in a Windows Workflow Foundation Custom Activity

I'm implementing a Custom Workflow and Activities to be reused in multiple projects and trying to get them to be as easy to use as possible. In this workflow I have a Property whose name is 'UserID' which I'd like to bind to a dependencyproperty in one of my activities. I can currently bind it at design time searching explicitly for the property each time I add one of these activities to the workflow, but I'd like for this activity to be binded automatically.
As far as i know (correct me if I'm wrong), to bind a dependency property at design time I need to specify a string of the form "Activity=NameOfWorkflow, Path=UserID" to the DefaultBindingProperty metadata tag, and I'd like the name of the workflow to be completed in some way. Any way of doing this?
Thanks
I finally managed to achieve this by attaching an ActivityToolboxItem to the Activity, and overriding a method in it that creates the instance shown in the designer. I used an ActivityBind object to bind the dependencyproperty to the workflow's property. To get the instance of the workflow, I just searched for an ancestor to my activity by calling act.Parent until the activity had no parent (and thus was the StateMachineWorkflowActivity itself)