Office Workflow Designer Managed Extensibility Framework (MEF)

The latest check-in adds Managed Extensibility Framework (MEF) to enable expression builder plug-ins. In addition, the source code shows how to create a SharePointItems workflow activity designer.

The source code is located at http://desktopweb.codeplex.com/SourceControl/changeset/changes/9787.

SharePointItems Activity Designer

The SharePointItems activity designer located in SharePointItemsDesigner.xaml and QueryDesigner represent SharePoint item operations. The current version also shows a simple CamlWhere activity. With this activity designer, a workflow can perform GetItems, Delete and Update operations against a SharePoint list applying a single CamWhere query. A future release will add the ability to connect CamWhere activity logical operators.

Managed Extensibility Framework (MEF) Expression Builders

Numerous code changes were made to integrate MEF into the workflow designer. The changes enable the opportunity to create expression builder plug-ins.

Highlight of interfaces and classes added

abstract class ExpressionBuilderBase : IExpressionBuilder

abstract class ExpressionBuilderItemsProviderBase : IExpressionItemsProvider

abstract class ExpressionTypeConverterBase : IExpressionTypeConverter    

Example MEF Import

[ImportMany(AllowRecomposition = true)]
public ObservableCollection<Lazy<IExpressionExtension, IExpressionBuilderMetadata>> extensions { get; set; }

Resolve MEF builders

pathBuilder = this.ResolveBuilder(this.ExpressionPath);

if (pathBuilder != null)

{

    pathBuilder.ItemsProvider = Extension<IExpressionItemsProvider>

    (this.ExpressionPath,    
        ExpressionMappings.ExtensionAttributes.itemsProviderType.ToString());

    pathBuilder.Converter = Extension<IExpressionTypeConverter>

    (this.ExpressionPath,
        ExpressionMappings.ExtensionAttributes.converterType.ToString());

    pathBuilder.OnUpdated = Builder_OnUpdated;

    expressionMenu.Visibility = Visibility.Visible;

}

TExtensionType Generic Method

private TExtensionType Extension<TExtensionType>(string path, string extensionAttribute)

{

TExtensionType extension = default(TExtensionType);

List<Lazy<IExpressionExtension, IExpressionBuilderMetadata>>
    targetExtensions = null;

if (expressionMappings.ContainsKey(path))

{

if (expressionMappings[path].ExtensionElement.Attribute(extensionAttribute) != null)

{

string typeName = expressionMappings[path].ExtensionElement.Attribute(extensionAttribute).Value;

targetExtensions =

(extensions
    .Where(t => t.Metadata.Name.Equals(typeName))
    .Select(t => t))
    .ToList<Lazy
     <IExpressionExtension,IExpressionBuilderMetadata>>();

if (targetExtensions.Count > 0)

{

extension = (TExtensionType)targetExtensions[0].Value;

ExtensionContextName =
targetExtensions[0].Metadata.Name;

}

}

}

return extension;

}

Resolve Expression Builder

private IExpressionBuilder ResolveBuilder(string path)

{

IExpressionBuilder extension = Extension<IExpressionBuilder>(path, ExpressionMappings.ExtensionAttributes.builderType.ToString());

if (ExtensionContextName == “MenuItemsBuilder”)

{

extension.ItemsControl = this.expressionMenu;

}

return extension;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s