Giter Club home page Giter Club logo

wf-rehost-roslyn's Introduction

WF Rehosted Designer with Roslyn C# Expression Editor

The rehostable designer in Workflow Foundation is limited to only allow Visual Basic expressions. This project is to show how it is possible to use Roslyn for C# expressions. Roslyn is used to parse the code into syntax trees that can be used to fill completion windows. The user interface is powered by AvalonEdit.

High level steps needed to implement the custom expression editor:

  1. Implement the IExpressionEditorService interface. This interface manages the creation and destruction of expression editors.
  2. Implement the IExpressionEditorInstance interface. This interface implements the UI for expression editing UI.
  3. Publish the IExpressionEditorService in your rehosted workflow application.
  4. Implement a custom Expression Activity Editor with C# expression support a WPF based text editor component like AvalonEdit (https://github.com/icsharpcode/AvalonEdit) and register it to the ExpressionTextBox used by workflow designer.
  5. Use Roslyn to parse the code into syntax trees that can be used for IntelliSense.

While it is not a fully working custom expression editor implementation, it implements a custom Expression Activity Editor and shows how to work around below .NET workflow runtime issues you hit attempting above steps.

  1. Expression Editor defaults to VB expressions when implementing custom expression editor. When rehosting the workflow designer, the workflow runtime uses .NET framework 4.0 by default and this should be set to .NET 4.5 or higher to use the C# expression support. You can do this by using DesignerConfigurationService class as shown below.

    DesignerConfigurationService configurationService = wd.Context.Services.GetService<DesignerConfigurationService>();
    configurationService.TargetFrameworkName = new FrameworkName(".NETFramework", new System.Version(4, 5));
    
  2. By default, workflow runtime does not allow loading XAML from untrusted source. You can again use the DesignerConfigurationService class to configure the workflow designer as shown below.

    configurationService.LoadingFromUntrustedSourceEnabled = true;
    
  3. When loading custom XAML, workflow runtime defaults to VB in rehosted designer. Set the below XAML attached property to indicate workflow runtime that you are using C# expressions in your workflow.

    sap2010:ExpressionActivityEditor.ExpressionActivityEditor="C#"
    

Links to useful resources

Rehosting the Workflow Designer

Using a Custom Expression Editor

AvalonEdit on GitHub

wf-rehost-roslyn's People

Contributors

dmetzgar avatar erikcai8 avatar orosandrei avatar srinibanala avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.