Ello, I'm having an issue with a custom activity that preforms an evaluation of a `ActivityFunc ` and returns false even though it is evaluated in Execute to be true.
Here is my activity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.ComponentModel;
using System.Activities.Presentation;
namespace SomeActivities
{
///
/// Root of any number of activities used to check for a specific set of conditions to be true (Trigger Conditions)
///
public sealed class Trigger : NativeActivity, IActivityTemplateFactory
{
///
/// The initial Condition that determines if the trigger should be scheduled
///
/// The condition.
[RequiredArgument]
public ActivityFunc <bool> Condition { get; set; }
///
/// The resulting action that is scheduled if the Condition is true
///
/// The child.
[RequiredArgument]
public ActivityAction Child { get; set; }
///
/// Gets or sets the value holding whether or not the trigger matches the condition
///
/// The type of the match.
public MatchType MatchType{ get; set; }
private CompletionCallback<bool> OnExecutionCompleteCallBack;
protected override void Execute(NativeActivityContext context)
{
this.OnExecutionCompleteCallBack = this.OnConditionComplete;
context.ScheduleFunc<bool>(this.Condition, this.OnExecutionCompleteCallBack);
}
public void OnConditionComplete(NativeActivityContext context, ActivityInstance instance, bool result)
{
if (instance.State == ActivityInstanceState.Canceled)
{
context.Abort();
return;
}
//check if Condition evaluation returns true
//Always show as false
if (result)
{
//If so then schedule child Activity
context.ScheduleAction(Child);
}
}
Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
{
return new Trigger()
{
Child = new ActivityAction()
{
DisplayName = "Trigger Child Action"
},
Condition = new ActivityFunc<bool>()
{
DisplayName = "Trigger Conditionals",
Result = new DelegateOutArgument<bool>()
},
DisplayName = "Trigger",
MatchType = MatchType.Matches,
};
}
}
}
So when my condition is evaluated in the Execute Method it calls OnConditionComplete with the result (which is what is always false) even though if I print the result of the condition to be true. So is there something obviously wrong here that I don't see?
Update
Okay I think Marice talking about having the callback in the class and just having the OnConditionComplete method point to the callback. I did change that but haven't seen a change. If I could somehow retrieve the value from the ActivityFunc<bool> child
condition when its actually executing or save its value afterward, that would work great. I've played around with CacheMetadata's metadata to see if there was anything that I could find that would allow me to do so but haven't found anything as of yet.
Update 2
The problem apparently is coming from the ActivityFunc <bool> Condition
. I'm going to have to go through and check what the issue(s) with the Condition might be. Not sure if this should go to a new question or not since its technically not solved but I'll see about putting together a test Condition to go off of and if nothing else show where I'm at.
Okay this is a bare bones example of what I use as a child activity that always returns false even though it evaluates to true in the execution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Presentation;
using System.ComponentModel;
using System.Drawing;
namespace SomeActivities
{
public sealed class DataHandlerTypeName : NativeActivity,IActivityTemplateFactory
{
// Define an activity input argument of type string
[RequiredArgument]
public InArgument ImportContext { get; set; }
///
/// Gets or sets the handler type name to check.
///
/// The handler type name to check.
[RequiredArgument]
public string HandlerTypeNameToCheck { get; set; }
///
/// Performs the trigger check for the matching Data Type Handler Names
///
/// The context.
protected override void Execute(NativeActivityContext context)
{
var ic = this.ImportContext.Get(context);
if (1==1)
{
//context.SetValue(base.Result, true);
Result.Set(context, true);
}
else
{
//context.SetValue(base.Result, true);
Result.Set(context, false);
}
}
#region IActivityTemplateFactory Members
Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
{
return new DataHandlerTypeName()
{
ImportContext = this.ImportContext,
HandlerTypeNameToCheck = "Default"
};
}
#endregion
}
}