Custom Policy Activity update it's own properties at runtime

Hello,

How do you get a custom policy activity's ruleset to update a property on the activity instance

Thanks.



Answer this question

Custom Policy Activity update it's own properties at runtime

  • Socrates Kapetaneas

    I still haven't been able to resolve this issue.

    Also tried the following with same results...

    lData.role_name = ((TActivityQueue)executionContext.Activity).RoleName;

    I must be missing something - Dharma Shukla "Essential Windows Workflow Foundation" - p337 - indicates it's possible to update a property on an activity from a rule action.

    The only way I could get this to work is by setting up the property on the work flow class and then setting up a dependency property in the custom activity that refers back to the work flow property. Only then do I get a value from RoleName in the custom activity. This seems kind of dangerous though if I have multiple children executing in parallel...but further testing will bear this out.


  • Dan0001

    Hi,

    Do you mean updating a property of your custom policy activity If that is the case, this should do it:

    this.x.P where x is your Custom Policy Activity variable and P is the property to be updated.

    Thanks,

    Maggie



  • ahmedilyas

    Jurgen,

    I think I tried - in some form - to execute the rule directly against the activity instead of the root activity, and received errors. But I don't have the details at this time. So I will try it again in next day or 2 and advise.

    Thanks. John.


  • axelfxxx

    One possibility: if your custom activity is executing inside another activity that spawns new execution contexts, then your rule will be updating the "template" activity, not that actual instance of the activity that is executing. You can find more info on spawned contexts here:

    http://blogs.msdn.com/advancedworkflow/archive/2006/03/21/557121.aspx

    If this is the case, you would need to write more complicated rules to navigate to the correct activity instance, e.g. by accessing the DynamicActivity property on a While activity. A cleaner solution, might be to execute the rules directly against your custom activity and then navigate up the activity tree instead of down the tree. In other words, your rules might look something like:

    IF this.RootActivity.WorkFlowParameters["primary_market"].ToUpper() == "DALLAS"

    THEN this.RoleName = "TSDSOFTE"

    In your Execute method, then, you can change the line to:

    lRuleExecution = new RuleExecution(lRuleValidation, this, executionContext);



  • netmeister343943

    The "this" is the root workflow, not the activity. Are you trying to update the property as if it sat on the root workflow

  • soconne

    Maggie,

    So if the rule looked like the following...

    Rule Info...

    Condition - this.WorkFlowParameters["primary_market"].ToUpper() == "DALLAS"

    then action - ((TWTC.WF.WFActivities.TActivityQueue)this.GetActivityByName("taskCleanOrder")).RoleName = "TSDSOFTE"

    else action - ((TWTC.WF.WFActivities.TActivityQueue)this.GetActivityByName("taskCleanOrder")).RoleName = "TSDSOFTW"

    or the following...

    then action - this.taskCleanOrder.RoleName = "TSDSOFTE"

    else action - this.taskCleanOrder.RoleName = "TSDSOFTW"

    Then you would expect to access the RoleName property within the custom policy activity (taskCleanOrder) and see a value other then null

    But what I am seeing is null for "this.RoleName" in this line of code in the custom policy activity (see complete code below).

    lData.role_name = this.RoleName; // this.RoleName is null

    Am I missing something

    Thanks.

    taskCleanOrder

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

    {

    .... code omitted

    this.TrackData(this.getSLA(executionContext));

    .... code omitted

    }

    protected virtual IUpdateActivitySLAArg getSLA(ActivityExecutionContext executionContext)

    {

    IUpdateActivitySLAArg lData;

    RuleSet lRuleSet;

    Activity lRootActivity;

    RuleDefinitions lRuleDefinitions;

    RuleValidation lRuleValidation;

    RuleExecution lRuleExecution;

    // Find the root Activity

    lRootActivity = this.RootActivity(executionContext.Activity.Parent);

    if (lRootActivity != null)

    {

    // Get the RuleDefinitions from the root activity

    lRuleDefinitions = (RuleDefinitions)lRootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty);

    lRuleSet = lRuleDefinitions.RuleSets[this.AssignedToRuleSet.RuleSetName];

    lRuleValidation = new RuleValidation(lRootActivity.GetType(), null);

    lRuleExecution = new RuleExecution(lRuleValidation, lRootActivity, executionContext);

    lRuleSet.Execute(lRuleExecution);

    }

    lData = new t_update_activity_sla_arg();

    lData.activity_history_id = -1;

    lData.work_flow_instance_id = this.WorkflowInstanceId;

    lData.activity_qualified_name = this.QualifiedName;

    lData.user_name = TConstants.SYSTEM_AUDIT_ID;

    lData.activity_due_date = DateTime.UtcNow.AddHours(16);

    lData.event_type_id = Convert.ToInt32(TEventType.SLAUpdate);

    lData.role_name = this.RoleName; // .AssignedTo; // "TSDSOFTE";

    Debug.WriteLine(this.GetType().Name + ".getSLA. RoleName = " + this.RoleName + ", DateTime=" + DateTime.Now.ToString("F"));

    return lData;

    }

    Debug Info

    ***********************************************************
    User Tracking Record
    ***********************************************************
    EventDateTime: 2/26/2007 3:50:05 AM
    QualifiedName: taskCleanOrder
    ActivityType.FullName: TWTC.WF.WFActivities.TActivityQueue
    ActivityType.Name: TActivityQueue
    ContextGuid: f8f1de8c-6336-4166-939f-d50bef83eafe
    EventOrder: 11
    UserData: System.Workflow.Activities.Rules.RuleActionTrackingEvent
    TrackingDataItem: WorkFlowParameters
    TrackingDataItem.ToString(): System.Collections.Generic.Dictionary`2[System.String,System.String]
    TrackingDataItem: IsATTOrder
    TrackingDataItem.ToString(): True
    TrackingDataItem: EvalCleanOrderCount
    TrackingDataItem.ToString(): 1
    RuleActionTrackingEvent
    ***********************
    RuleName: ruleAssignedToTaskCleanOrder
    ConditionResult: True
    TActivityQueue.getSLA. RoleName = , DateTime=Monday, February 26, 2007 3:50:05 AM

    ***********************************************************
    User Tracking Record
    ***********************************************************
    EventDateTime: 2/26/2007 3:50:05 AM
    QualifiedName: taskCleanOrder
    ActivityType.FullName: TWTC.WF.WFActivities.TActivityQueue
    ActivityType.Name: TActivityQueue
    ContextGuid: f8f1de8c-6336-4166-939f-d50bef83eafe
    EventOrder: 12
    UserData: this.work_flow_instance_id = 1f92a5d6-99ef-4f11-8804-7ee3de00b7b4
    this.activity_qualified_name = taskCleanOrder
    this.activity_history_id = -1
    this.event_type_id = 1
    this.role_name =
    this.activity_due_date = 2/27/2007 1:50:05 AM
    this.user_name = SYSTEM

    TrackingDataItem: WorkFlowParameters
    TrackingDataItem.ToString(): System.Collections.Generic.Dictionary`2[System.String,System.String]
    TrackingDataItem: IsATTOrder
    TrackingDataItem.ToString(): True
    TrackingDataItem: EvalCleanOrderCount
    TrackingDataItem.ToString(): 1


  • Martin Kristensen

    Hi John,

    Is this problem resolved or are you still having issues

    -Kavita



  • barkingdog

    Kavita,

    I'm trying to update the property on the activity instance that is executing the ruleset as per the code samples I provided above.

    For brevity I am reiterating the code as follows...

    Rule Info...

    Condition - this.WorkFlowParameters["primary_market"].ToUpper() == "DALLAS"

    then action - ((TWTC.WF.WFActivities.TActivityQueue)this.GetActivityByName("taskCleanOrder")).RoleName = "TSDSOFTE"

    else action - ((TWTC.WF.WFActivities.TActivityQueue)this.GetActivityByName("taskCleanOrder")).RoleName = "TSDSOFTW"

    or the following...

    then action - this.taskCleanOrder.RoleName = "TSDSOFTE"

    else action - this.taskCleanOrder.RoleName = "TSDSOFTW"

    public partial class TActivityQueue // aka "taskCleanOrder"

    {

    private string _RoleName;

    public string RoleName

    {

    get { return _RoleName; }

    set { _RoleName = value; }

    }

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

    {

    .... code omitted

    ...Execute the ruleset above that is supposed to update RoleName property above so that I can use that value in the next statement

    this.TrackData(this.RoleName);

    .... code omitted

    }

    } //end of TActivityQueue


  • Custom Policy Activity update it's own properties at runtime