こんにちは、'ActivityFunc' の評価を実行し、Execute で true と評価されても false を返すカスタム アクティビティに問題があります。ここに私の活動があります
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,
};
}
}
}
したがって、私の条件が Execute メソッドで評価されると、条件の結果を true に出力しても、OnConditionComplete が結果 (常に false) で呼び出されます。それで、私が見ていない明らかに間違っていることがありますか?
アップデート
Marice は、クラス内にコールバックを持ち、OnConditionComplete メソッドがコールバックを指すようにすることについて話していると思います。私はそれを変更しましたが、変更は見られませんでした。実際に実行したときに条件から値を取得しActivityFunc<bool> child
たり、後でその値を保存したりできれば、それはうまくいくでしょう。私は CacheMetadata のメタデータをいじって、それを可能にするものがあるかどうかを確認しましたが、まだ何も見つかりませんでした。
更新 2
問題は明らかに ActivityFunc <bool> Condition
. 条件に問題がある可能性があるかどうかを調べて確認する必要があります。技術的に解決されていないため、これが新しい質問に進むべきかどうかはわかりませんが、テスト条件をまとめてオフにすることについて見ていきます。
これは、実行時に true と評価されても常に false を返す子アクティビティとして使用するものの基本的な例です。
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
}
}