none
Working with sub-workflow in rehosted designer? RRS feed

  • Question

  • Is it possible to work with a sub-workflow (i.e. subset of the workflow in the designer). For example a sequence, a flowchart, or any activity inside the workflow.

    My idea is something like these:

    • Save the subworkflow to a file (for example, save the selected Sequence activity)
    • Load a saved subworkflow and add it into current workflow
    • Add a sub-workflow as an item in toolbox
    Are these even possible?
    Wednesday, November 24, 2010 4:01 AM

Answers

  • Hi Louis,

    - the following code snippet is a simple example for inserting a xaml activity selected by OpenFileDialog into the workflow:

    public class DynamicWorkflowSelector : IActivityTemplateFactory
    {
      public Activity Create(DependencyObject target)
      {
        DynamicActivity activity = null;
               
        OpenFileDialog dialog = new OpenFileDialog()
        {
          Title = "Select a xaml workflow",
          InitialDirectory = AppDomain.CurrentDomain.BaseDirectory,
          Multiselect = false,
          AddExtension = true,
          SupportMultiDottedExtensions = true,
          Filter = "Xaml files(*.xaml)|*.xaml"
        };
        if (dialog.ShowDialog() == DialogResult.OK)
        {
          using (FileStream stream = File.OpenRead(dialog.FileName))
          {
            activity = (DynamicActivity)ActivityXamlServices.Load(stream);
          }
        }
        return activity == null || activity.Implementation == null ? null : activity.Implementation(); 
      }
    }
    

    Thanks

    Roman 


    Roman Kiss, MVP Connected System Developer
    Friday, November 26, 2010 10:10 PM
  • Hi,

    ->"Save the subworkflow to a file (for example, save the selected Sequence activity) "
    Currently, this is not possible. however, you can write code to select some xaml string and save it.


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"

    Actually, I found out I could

     

    Selection selected = this.WorkflowDesigner.Context.Items.GetValue<Selection>();
    Activity act = selected.PrimarySelection.GetCurrentValue() as Activity;
    XamlServices.Save(filename, act);
    Can I add a non-compiled xaml code to the toolbox?

    Friday, November 26, 2010 7:01 AM

All replies

  • Hi,

    ->"Save the subworkflow to a file (for example, save the selected Sequence activity) "
    Currently, this is not possible. however, you can write code to select some xaml string and save it.

    ->"Load a saved subworkflow and add it into current workflow "
    In VS2010, every compiled workflow will appear toolbox as an activity. in your custom WF4 designer, you can add compiled workflow into toolbox by code:

       ToolboxControl ctrl = new ToolboxControl();
         ToolboxCategory categoryItems = new ToolboxCategory("MyActivities");
         ToolboxItemWrapper infoActivity = new ToolboxItemWrapper(typeof(MyActivityLibrary.PersonalInfoActivity));
         categoryItems.Add(infoActivity);

    ->"Add a sub-workflow as an item in toolbox "
    You can extract this sub-workflow and treat it as a workflow then build it and it will appear in the toolbox(VS2010) or add it into the toolbox manually.

    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"
    Friday, November 26, 2010 6:56 AM
    Moderator
  • Hi,

    ->"Save the subworkflow to a file (for example, save the selected Sequence activity) "
    Currently, this is not possible. however, you can write code to select some xaml string and save it.


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"

    Actually, I found out I could

     

    Selection selected = this.WorkflowDesigner.Context.Items.GetValue<Selection>();
    Activity act = selected.PrimarySelection.GetCurrentValue() as Activity;
    XamlServices.Save(filename, act);
    Can I add a non-compiled xaml code to the toolbox?

    Friday, November 26, 2010 7:01 AM
  • Hi Louis,

    - the following code snippet is a simple example for inserting a xaml activity selected by OpenFileDialog into the workflow:

    public class DynamicWorkflowSelector : IActivityTemplateFactory
    {
      public Activity Create(DependencyObject target)
      {
        DynamicActivity activity = null;
               
        OpenFileDialog dialog = new OpenFileDialog()
        {
          Title = "Select a xaml workflow",
          InitialDirectory = AppDomain.CurrentDomain.BaseDirectory,
          Multiselect = false,
          AddExtension = true,
          SupportMultiDottedExtensions = true,
          Filter = "Xaml files(*.xaml)|*.xaml"
        };
        if (dialog.ShowDialog() == DialogResult.OK)
        {
          using (FileStream stream = File.OpenRead(dialog.FileName))
          {
            activity = (DynamicActivity)ActivityXamlServices.Load(stream);
          }
        }
        return activity == null || activity.Implementation == null ? null : activity.Implementation(); 
      }
    }
    

    Thanks

    Roman 


    Roman Kiss, MVP Connected System Developer
    Friday, November 26, 2010 10:10 PM
  • Hi, Louis

    ->"Selection selected = this.WorkflowDesigner.Context.Items.GetValue<Selection>();"
    Good idea.


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"
    Wednesday, December 1, 2010 3:02 AM
    Moderator