工作流基金会自定义分配活动



我在设计师中定义了这一点:

    <sap:WorkflowItemPresenter>
       <statements:Assign DisplayName="Assign"/>
    </sap:WorkflowItemPresenter>

我认为,如果我在那里添加分配,但我错了。

    [Browsable(false)]
    public Activity Body { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        ActivityInstance res = context.ScheduleActivity(Body, new CompletionCallback(OnExecuteComplete));
    }
    /// <summary>
    /// Called from Execute when Condition evaluates to true.
    /// </summary>
    /// <param name="context">The context.</param>
    /// <param name="instance">The instance.</param>
    public void OnExecuteComplete(NativeActivityContext context, ActivityInstance instance)
    {
        //to be added
    }

这是基类的代码。

我根本不需要更改分配活动,我只想访问NativeaCtivityContext。实际上,我正在尝试将其包裹起来,并在OneXecuteComplete方法中对上下文的属性进行一些检查。有没有办法实现这一目标?

编辑1:

dotnethitman建议并向我展示了WF 4重新安置的设计师 - 让Foreach Inargument Reator如何与这些曲目一起工作,我确实成功地解决了他的解决方案:

                    if (trackingEventArgs.Activity is Assign)
                    {
                        Assign ass = trackingEventArgs.Activity as Assign;
                        if (ass.To.Expression != null)
                        {
                            dynamic vbr = null;
                            if ((ass.To.Expression is VisualBasicReference<int>))
                            {
                          //vbr.ExpressionText will hold the value set in the To section of the Assign activity, one of the variables will reside here
                                vbr = ass.To.Expression as VisualBasicReference<int>;
                            }
                            else if ((ass.To.Expression is VisualBasicReference<string>))
                            {
                                vbr = ass.To.Expression as VisualBasicReference<string>;
                            }
                            ActivityStateRecord activityStateRecord = null;
                            if (trackingEventArgs.Record != null)
                                activityStateRecord = trackingEventArgs.Record as ActivityStateRecord;

                            if (activityStateRecord != null)
                            {
                                if (activityStateRecord.Arguments.Count > 0)
                                {
                    //checking if the variable defined in the To section is to be displayed in the watch window   
                     GlobalFunctions.WatchWindowViewModel.VariableDefinition existingVariable = GlobalFunctions.WatchWindowViewModel.Instance.VariableExists(vbr.ExpressionText);
                                    if (existingVariable != null)
                                    {
                                        foreach (KeyValuePair<string, object> argument in activityStateRecord.Arguments)
                                        {
                                            if (argument.Key.Equals("Value"))
                                            {
                                                Application.Current.Dispatcher.Invoke(
                                                    () =>
                                                    {
                                                        existingVariable.VariableValue.Clear();
                                                        existingVariable.VariableValue.Add(
                                                            argument.Value.ToString());
                                                    });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

我仍然面临一些丑陋的事情。在检查分配活动的参数时,我会得到密钥"值"。但是,如果我定义了一个名为" i"的变量,并希望看到其更改,因为该分配执行,我必须查看该VisualBasicReference&lt;>以检查与上面代码中所述的变量名称。这种做法确实有效,我设法涵盖了ints和strings,这暂时还好..但是我的代码中是否可以使用任何快捷方式?

编辑2 我今天有一个新想法,并把它奏效了:

这是库代码:

public sealed class CustomAssign : NativeActivity, IActivityTemplateFactory
{
    [Browsable(false)]
    public Activity Body { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        ActivityInstance res = context.ScheduleActivity(Body, new CompletionCallback(OnExecuteComplete));
    }
    /// <summary>
    /// Called from Execute when Condition evaluates to true.
    /// </summary>
    /// <param name="context">The context.</param>
    /// <param name="instance">The instance.</param>
    public void OnExecuteComplete(NativeActivityContext context, ActivityInstance instance)
    {
        //to be added
    }
    Activity IActivityTemplateFactory.Create(System.Windows.DependencyObject target)
    {
        return new CustomAssign
        {
            Body = new Assign()
        };
    }
}

和设计师:

<sap:ActivityDesigner x:Class="ARIASquibLibrary.Design.CustomAsignDesigner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
xmlns:statements="http://schemas.microsoft.com/netfx/2009/xaml/activities" Collapsible="False" BorderThickness="20" BorderBrush="Transparent">
<sap:ActivityDesigner.Template>
    <ControlTemplate TargetType="sap:ActivityDesigner">
        <Grid>
            <ContentPresenter HorizontalAlignment="Center"
                                      VerticalAlignment="Center"/>
        </Grid>
    </ControlTemplate>
</sap:ActivityDesigner.Template>
<DockPanel LastChildFill="True">
    <sap:WorkflowItemPresenter Item="{Binding Path=ModelItem.Body, Mode=TwoWay}"/>
</DockPanel>
</sap:ActivityDesigner>

因此,用几句话:我在自定义活动中托管了分配活动,并更改了控制模板,以便仅保留contentpresenter,而contentpresenter又将是分配。现在,通过将其拖放到设计师,您将完全具有原始外观,但具有编写代码的能力并检查:

中的执行步骤
 protected override void Execute(NativeActivityContext context)

 public void OnExecuteComplete(NativeActivityContext context, ActivityInstance instance)

为什么?通过上下文。dataContext,您可以在此活动所在的范围内获取所有变量和参数,以开发手表窗口。

而不是处理每个变量类型,只需将表达式转换为基本接口。

ITextExpression vbr = ass.To.Expression as ITextExpression;

您可以只访问表达式文本属性,而无需关心分配给表达式的变量类型。

GlobalFunctions.WatchWindowViewModel.VariableDefinition existingVariable = GlobalFunctions.WatchWindowViewModel.Instance.VariableExists(vbr.ExpressionText);

这应该适合(我希望)可以应用的所有变量类型。

相关内容

  • 没有找到相关文章

最新更新