locked
Designer rehosted and custom activities in the toolbox. RRS feed

  • Question

  • I'm trying to use the designer rehosting example, but add an activity I create in the designer to the toolbox. (http://msdn2.microsoft.com/en-us/library/aa480213.aspx)

    I've managed to add the compiled workflow to the toolbox by specifying the type name and it's location, but the component isn't usable as an activity to a new workflow.

    Via debugger, I suspect that this is because the ToolboxItemAttribute is not present in the code generated.

    So in the Helpers class, in GenerateCodeFromXomlDocument() call I add

    activityTypeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("ToolboxItem", new CodeAttributeArgument(new CodePrimitiveExpression(true))));

    or

    activityTypeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("ToolboxItemAttribute", new CodeAttributeArgument(new CodePrimitiveExpression(true))));

    in the hopes that the attribute will be squirted into the partial class in the MyCode.cs file, but no such luck.

    Does anybody have experience / an idea how to do this?

    thanks,

    +N

    Wednesday, October 25, 2006 7:04 AM

Answers

  • I was doing it wrong in the wrong location.

    The right location and encantation is in WorkflowDesignerControl.WorkflowLoader:

    internal WorkflowLoader()

    {

    // Create the code compile unit

    codeBesideccu = new CodeCompileUnit();

    codeBesideccu.ReferencedAssemblies.Add("System.Workflow.Activities");

    CodeNamespace ns = new CodeNamespace("NH");

    ns.Imports.Add(new CodeNamespaceImport("System"));

    ns.Imports.Add(new CodeNamespaceImport("System.ComponentModel"));

    ns.Imports.Add(new CodeNamespaceImport("System.ComponentModel.Design"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel.Design"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel.Serialization"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel.Compiler"));

    ns.Imports.Add(new CodeNamespaceImport("System.Drawing"));

    ns.Imports.Add(new CodeNamespaceImport("System.Collections"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.Activities"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.ComponentModel"));

    ns.Imports.Add(new CodeNamespaceImport("System.Workflow.Runtime"));

    codeBesideccu.Namespaces.Add(ns);

    CodeTypeDeclaration ctd = new CodeTypeDeclaration("Workflow1");

    ctd.BaseTypes.Add("System.Workflow.Activities.SequentialWorkflowActivity");

    ctd.IsPartial = true;

    ctd.Attributes = MemberAttributes.Public;

    ////////////////////// add these lines:

    CodeAttributeDeclaration attrdecl = new CodeAttributeDeclaration(

    "System.ComponentModel.ToolboxItem",

    new CodeAttributeArgument(new CodePrimitiveExpression(true))

    );

    ctd.CustomAttributes.Add(attrdecl);

    CodeCommentStatement nurisComment = new CodeCommentStatement(new CodeComment("ToolboxItem decoration should do the trick.."));

    ctd.Comments.Add(nurisComment);

    ////////////////////// end added lines

    ns.Types.Add(ctd);

    }

     

    on to the next problem, extracting all the "standard" default namespace and class name ("foo.Workflow1") that it is user selectable, and that no collision occurs with the default when you compile an activity and later want to use it in your toolbox to insert into a new workflow.

    Wednesday, October 25, 2006 7:19 PM