Integrating Windows Workflow 4.0 into Office applications enables a Power User or a Business Analyst to customize a solution by designing workflow-driven business logic. Office workflows can break down the barriers between IT and Power Users. Workflow activities would generally be designed and written by an IT team. A Power User or a Business Analyst would create Office related solutions by designing a workflow containing code activities designed, tested and approved by IT.

Note A Windows Workflow designer, including custom activities and expression builders, are designed to be decoupled from the host application. Thus, any other client application could host a workflow. See the source code for an example Excel activity host application.  The current code base leverages the workflow designer that ships with .NET Framework 4.0. However, since workflow logic is defined as XAML, any custom view could be created to represent a workflow.

Word as a Workflow Host Application Sample Workflow Activities
image image
Excel as a Workflow Host Application  
image

Note how an Office Workflow reuses the SharePoint activities.

 

How to run a workflow hosted in Word

class SampleActivity : IClientActivity 
  { 
    public void Run(string workflowPath) 
    { 
      AutoResetEvent syncEvent = new AutoResetEvent(false); 

      var inputs = new Dictionary<String, Object> 
      { 
        {"ArgTitle",  title.Range.Text}, 
        {"ArgBody",  body.Range.Text}, 
        {"Handle", System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle} 
      }; 
      Activity wf = (Activity)ActivityXamlServices.Load(workflowPath); 

      WorkflowApplication wfApp = new WorkflowApplication(wf, inputs); 

      ... 
      wfApp.Run(); 
...

How to run a workflow hosted in Excel

class SampleActivity : IClientActivity
  {
    public void Run(string workflowPath)
    {
      AutoResetEvent syncEvent = new AutoResetEvent(false);

      var inputs = new Dictionary<String, Object>
        {
          {"ArgTitle",  Convert.ToString(Globals.ThisAddIn.Application.Names.Item("Title").RefersToRange.Value)},
          {"ArgBody",  Convert.ToString(Globals.ThisAddIn.Application.Names.Item("Body").RefersToRange.Value)},
          {"Handle", System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle}
        };

      Activity wf = (Activity)ActivityXamlServices.Load(workflowPath);

      WorkflowApplication wfApp = new WorkflowApplication(wf, inputs);

      ...
      wfApp.Run();
...

Last edited Oct 10, 2011 at 4:49 AM by dvana, version 10

Comments

No comments yet.