WF — 如何使用自定义活动而不在单独的工作流活动库中创建它?

发布于 2024-08-03 15:48:33 字数 2117 浏览 9 评论 0原文

我正在努力完成一些看起来应该很简单的事情。我有一个状态机工作流控制台应用程序,其中包含工作流。我为其创建了一个自定义活动。此活动绝不会在其他任何地方使用。我只想在我的工作流程中使用此活动,但是:

  1. 它没有出现在工具箱中。
  2. 我无法将其从解决方案资源管理器拖到工作流设计器上。

我绝对不想创建一个单独的状态机工作流活动库,因为这只会让我的解决方案变得混乱。就像我说的,我永远不会在任何其他项目中使用此活动,所以我想将其限制在这个项目中......但我只是不知道如何将其传递给设计师!我要疯了吗!?

这是该活动的代码:

public partial class GameSearchActivity: Activity
{
    public GameSearchActivity()
    {
        InitializeComponent();
    }

    public static DependencyProperty QueryProperty = System.Workflow.ComponentModel.DependencyProperty.Register("Query", typeof(string), typeof(GameSearchActivity));
    [Description("Query")]
    [Category("Dependency Properties")]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public string Query
    {
        get
        {
            return ((string)(base.GetValue(GameSearchActivity.QueryProperty)));
        }
        set
        {
            base.SetValue(GameSearchActivity.QueryProperty, value);
        }
    }

    public static DependencyProperty ResultsProperty = System.Workflow.ComponentModel.DependencyProperty.Register("Results", typeof(string), typeof(GameSearchActivity));
    [Description("Results")]
    [Category("Dependency Properties")]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public IEnumerable<Game_GamePlatform> Results
    {
        get
        {
            return ((IEnumerable<Game_GamePlatform>)(base.GetValue(GameSearchActivity.ResultsProperty)));
        }
        set
        {
            base.SetValue(GameSearchActivity.ResultsProperty, value);
        }
    }

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        IDataService ds = executionContext.GetService<IDataService>();
        Results = ds.SearchGames(Query);

        return ActivityExecutionStatus.Closed;
    }
}

谢谢。


编辑:

好的,所以我发现如果我将项目类型从控制台应用程序更改为类库,自定义活动会出现在工具箱中。然而,这是不可接受的。它必须是控制台/Windows 应用程序。

有人知道解决这个问题的方法吗?

I am trying to accomplish something that seems like it should be very simple. I have a State Machine Workflow Console Application with a workflow in it. I have created a custom activity for it. This activity will NEVER be used ANYWHERE ELSE. I just want to use this activity on my workflow, but:

  1. It does not appear in the toolbox.
  2. I cannot drag it from the Solution Explorer onto the workflow designer.

I absolutely do not want to create a separate State Machine Workflow Activity Library, since that will just clutter my solution. Like I said, I will never use this activity in any other project, so I would like to keep it confined to this one...but I just can't figure out how to get it onto the designer! Am I going crazy!?

Here is the code for the activity:

public partial class GameSearchActivity: Activity
{
    public GameSearchActivity()
    {
        InitializeComponent();
    }

    public static DependencyProperty QueryProperty = System.Workflow.ComponentModel.DependencyProperty.Register("Query", typeof(string), typeof(GameSearchActivity));
    [Description("Query")]
    [Category("Dependency Properties")]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public string Query
    {
        get
        {
            return ((string)(base.GetValue(GameSearchActivity.QueryProperty)));
        }
        set
        {
            base.SetValue(GameSearchActivity.QueryProperty, value);
        }
    }

    public static DependencyProperty ResultsProperty = System.Workflow.ComponentModel.DependencyProperty.Register("Results", typeof(string), typeof(GameSearchActivity));
    [Description("Results")]
    [Category("Dependency Properties")]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    public IEnumerable<Game_GamePlatform> Results
    {
        get
        {
            return ((IEnumerable<Game_GamePlatform>)(base.GetValue(GameSearchActivity.ResultsProperty)));
        }
        set
        {
            base.SetValue(GameSearchActivity.ResultsProperty, value);
        }
    }

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        IDataService ds = executionContext.GetService<IDataService>();
        Results = ds.SearchGames(Query);

        return ActivityExecutionStatus.Closed;
    }
}

Thanks.


EDIT:

OK, so I've discovered that if I change the project type from Console Application to Class Library, the custom activity appears in the toolbox. However, this is not acceptable. It needs to be a Console/Windows Application.

Anyone know a way around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掌心的温暖 2024-08-10 15:48:33

您似乎发现了 Visual Studio 中的一个错误。我确信您可以破解它以使其工作,但是,您是否考虑过使用它并将工作流位保留在类库中并从简单的控制台应用程序引用它们?是的,这会创建一个 EXE 和一个 DLL,但这样做的成本微不足道,而且实际上可以更好地分离各层(UI 与业务逻辑),并在将来实现更好的重用。

It looks like you've uncovered a bug in Visual Studio. I'm sure you could hack it to make it work, but, have you considered going with it and keeping the workflow bits in a class library and referencing them from a simple console application? Yes, this creates an EXE and a DLL, but the cost of doing so is trivial and actually separates your layers better (UI versus business logic) and enables better reuse in the future.

温折酒 2024-08-10 15:48:33

我离开了我的机器,所以我无法检查这个想法,但是您是否尝试过进入设计器的代码文件并手动插入最少的代码,然后返回设计器看看它是否存在?

您还没有说明设计者是否创建 XAML 还是 C#,但即使是 XAML,您也应该能够编辑 XML 来执行此操作。

I'm away from my machine so I can't check this idea but have you tried going into the designer's code file and manually inserting the minimal code and then going back into the designer to see if it's there?

You haven't said whether you've got the designer creating XAML or C# but even if it's XAML, you should be able to edit the XML to do that.

-柠檬树下少年和吉他 2024-08-10 15:48:33

您所要做的就是构建项目。如果编译成功,它应该显示在工具箱中。设计者仅读取上次成功构建的活动。

All you have to do is build the project. If it compiles successfully, it should show up in the toolbox. The designer only reads the activities from whatever the last successful build was.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文