Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 工作流基础4 - ActuviyFunc & LT的结果;布尔>;即使Execute方法显示true,也始终为false_C#_Workflow Foundation 4_Custom Activity - Fatal编程技术网

C# 工作流基础4 - ActuviyFunc & LT的结果;布尔>;即使Execute方法显示true,也始终为false

C# 工作流基础4 - ActuviyFunc & LT的结果;布尔>;即使Execute方法显示true,也始终为false,c#,workflow-foundation-4,custom-activity,C#,Workflow Foundation 4,Custom Activity,Ello,我遇到了一个自定义活动的问题,该自定义活动执行对“ActivityFunc”的求值,并返回false,即使在Execute中求值为true。 这是我的活动 ScheduleFunc始终接受一个ActivityFunc,其中您的条件定义为ActivityFunc。不确定非泛型ActivityFunc来自何处。此外,CompletionCallback应该是CompletionCallback 更新: 我使用的测试代码是: IActivityTemplateFactory factory

Ello,我遇到了一个自定义活动的问题,该自定义活动执行对“ActivityFunc”的求值,并返回false,即使在Execute中求值为true。 这是我的活动


ScheduleFunc始终接受一个ActivityFunc,其中您的条件定义为ActivityFunc。不确定非泛型ActivityFunc来自何处。此外,CompletionCallback应该是CompletionCallback

更新: 我使用的测试代码是:

IActivityTemplateFactory factory = new Trigger();
var trigger = (Trigger)factory.Create(null);
trigger.Condition.Handler = new AlwaysTrue();
trigger.Child.Handler = new WriteLine()
{
    Text = "Its true."
};
WorkflowInvoker.Invoke(trigger);

class AlwaysTrue : CodeActivity<bool>
{
    protected override bool Execute(CodeActivityContext context)
    {
        return true;
    }
}
IActivityTemplateFactory工厂=新触发器();
var trigger=(trigger)factory.Create(null);
trigger.Condition.Handler=new AlwaysTrue();
trigger.Child.Handler=new WriteLine()
{
Text=“这是真的。”
};
WorkflowInvoker.Invoke(触发器);
类:代码活动
{
受保护的覆盖布尔执行(CodeActivityContext上下文)
{
返回true;
}
}
和IActivityTemplateFactory。创建:

Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
{
    return new Trigger()
    {
        Child = new ActivityAction()
        {
            DisplayName = "Trigger Child Action"
        },

        Condition = new ActivityFunc<bool>()
        {
            DisplayName = "Trigger Conditionals"
        },
        DisplayName = "Trigger"
    };
}
活动IActivityTemplateFactory.Create(System.Windows.DependencyObject目标)
{
返回新触发器()
{
Child=新的ActivityAction()
{
DisplayName=“触发子操作”
},
条件=新的ActivityFunc()
{
DisplayName=“触发条件”
},
DisplayName=“触发器”
};
}

您好,我以前从未见过一个人,他恰好与我共享IP

你做错了什么。在其他地方,就是这样

您正在使用的包含活动的DLL不是最新的,或者工作流定义已过期,并且不符合您认为的功能。或者是完全不同的东西

我已经精简了您的代码并将其压缩到一个示例项目中。想在这里看到它吗

这是一个简单的条件:

public sealed class AnTrigger : NativeActivity<bool>
{
    public bool ResultToSet { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        Result.Set(context, ResultToSet);
    }
}
这将导致工作流定义中的结果集,从而打破ActivityFunc模式

<!--If you see ActivityFunc.Result in your workflow, DELETE IT -->
<ActivityFunc.Result>
  <DelegateOutArgument x:TypeArguments="x:String" />
</ActivityFunc.Result>


2.CompletionCallback应该是CompletionCallback-CompletionCallback是一个CompletionCallback,我正在schedule方法中实例化它。除非有其他方法,否则我应该这样做?1.ScheduleFunc总是接受一个ActivityFunc,其中您的条件定义为ActivityFunc。不太清楚你的意思。ref在这里,我的条件定义为ActivityFunc.Hmm。似乎我失去了一些成形。它应该读ActivityFuncDuh,是的,我也这么做了。现在应该修好了。代码应该更有意义。这是我的测试工作流程,工作正常:IActivityTemplateFactory=new Trigger();var trigger=(trigger)factory.Create(null);trigger.Condition.Handler=new AlwaysTrue();trigger.Child.Handler=new WriteLine(){Text=“Its true.”;WorkflowInvoker.Invoke(触发器);
public sealed class AnTrigger : NativeActivity<bool>
{
    public bool ResultToSet { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        Result.Set(context, ResultToSet);
    }
}
public sealed class AnTriggerHost : NativeActivity, IActivityTemplateFactory
{
    public ActivityFunc<bool> Condition { get; set; }
    public ActivityAction Child { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        context.ScheduleFunc(Condition, OnConditionComplete);
    }

    private void OnConditionComplete(
        NativeActivityContext context, 
        ActivityInstance completedInstance, 
        bool result)
    {
        if (result)
            context.ScheduleAction(Child);
    }

    Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
    {
        // so I don't have to create UI for these, here's a couple samples
        // seq is the first child and will run as the first AnTrigger is configured to return true
        // so the first trigger evals to true and the first child runs, which
        var seq = new Sequence
        {
            DisplayName = "Chief Runs After First Trigger Evals True"
        };
        // prints this message to the console and
        seq.Activities.Add(new WriteLine { Text = "See this?  It worked." });
        // runs this second trigger host, which 
        seq.Activities.Add(
            new AnTriggerHost
            {
                DisplayName = "This is the SECOND host",
                Condition = new ActivityFunc<bool>
                {
                    // will NOT be triggered, so you will never see
                    Handler = new AnTrigger
                    {
                        ResultToSet = false,
                        DisplayName = "I return false guize"
                    }
                },
                Child = new ActivityAction
                {
                    // this activity write to the console.
                    Handler = new WriteLine
                    {
                        Text = "you won't see me"
                    }
                }
            });

        return new AnTriggerHost
        {
            DisplayName = "This is the FIRST host",
            Condition = new ActivityFunc<bool>
            {
                Handler = new AnTrigger
                {
                    ResultToSet = true,
                    DisplayName = "I return true!"
                }
            },
            Child = new ActivityAction
            {
                Handler = seq
            }
        };
    }
}
  <local:AnTriggerHost DisplayName="This is the FIRST host" >
    <local:AnTriggerHost.Child>
      <ActivityAction>
        <Sequence DisplayName="Chief Runs After First Trigger Evals True">
          <WriteLine Text="See this?  It worked." />
          <local:AnTriggerHost DisplayName="This is the SECOND host">
            <local:AnTriggerHost.Child>
              <ActivityAction>
                <WriteLine Text="you won't see me" />
              </ActivityAction>
            </local:AnTriggerHost.Child>
            <local:AnTriggerHost.Condition>
              <ActivityFunc x:TypeArguments="x:Boolean">
                <local:AnTrigger DisplayName="I return false guize" ResultToSet="False" />
              </ActivityFunc>
            </local:AnTriggerHost.Condition>
          </local:AnTriggerHost>
        </Sequence>
      </ActivityAction>
    </local:AnTriggerHost.Child>
    <local:AnTriggerHost.Condition>
      <ActivityFunc x:TypeArguments="x:Boolean">
        <local:AnTrigger DisplayName="I return true!" ResultToSet="True" />
      </ActivityFunc>
    </local:AnTriggerHost.Condition>
  </local:AnTriggerHost>
Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
{
    return new Child
    {
        InputText = new InArgument<string>(
            new VisualBasicValue<string>(Parent.InputTextVariable)),
        // the following demonstrates what NOT to do in the Create method. 
        // this BREAKS your ActivityFunc, which will ALWAYS return default(T)
        // DO NOT SET Result AT ANY TIME OR IN ANY PLACE
        // BEGIN ERROR
        Result = new OutArgument<string>()
        // END ERROR
    };
}
<!--If you see ActivityFunc.Result in your workflow, DELETE IT -->
<ActivityFunc.Result>
  <DelegateOutArgument x:TypeArguments="x:String" />
</ActivityFunc.Result>