Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / XAML

WF4 Custom activities for message mediation

Rate me:
Please Sign up or sign in to vote.
4.98/5 (25 votes)
20 Dec 2012CPOL24 min read 108.3K   2K   72  
This article describes a design, implementation, and usage of custom message mediation activities for a XAML workflow.
//*****************************************************************************
//    Description.....WF4 Message Mediation Library
//                                
//    Author..........Roman Kiss, rkiss@pathcom.com
//    Copyright © 2009 ATZ Consulting Inc. (see included license.rtf file)         
//                        
//    Date Created:    07/07/09
//
//    Date        Modified By     Description
//-----------------------------------------------------------------------------
//    07/07/09    Roman Kiss     Initial Revision
//
//*****************************************************************************
//
#region Namespaces
using System;
using System.Activities;
using System.Activities.Presentation.Converters;
using System.Activities.Presentation.Model;
using System.Activities.Presentation.PropertyEditing;
using System.Linq;
using System.Windows;
using System.Xml.Linq;
using Microsoft.VisualBasic.Activities;
using RKiss.MessageMediationActivityLibrary.Design.Dialogs.Forms;
#endregion

namespace RKiss.MessageMediationActivityLibrary.Design.Editors
{

    public class MessageMediationEditor : XmlValueExpressionEditor
    {
        public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
        {
            try
            {
                if (propertyValue != null)
                {
                    ModelPropertyEntryToOwnerActivityConverter converter = new ModelPropertyEntryToOwnerActivityConverter();
                    ModelItem activity = (ModelItem)converter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null);
                    ModelItem item2 = (ModelItem)converter.Convert(propertyValue.ParentProperty, typeof(ModelItem), true, null);

                    // properties
                    var qSourceUri = item2.Properties.FirstOrDefault(p => p.Name == "SourceUri");

                    // values
                    string sourceUri = qSourceUri == null ? string.Empty : qSourceUri.ComputedValue as string;
                    string xmltext = propertyValue.Value != null ? ((propertyValue.Value as InArgument<XElement>).Expression as VisualBasicValue<XElement>).ExpressionText : string.Empty;

                    CreateMessageForm dialog = new CreateMessageForm(xmltext, sourceUri);
                    dialog.ShowDialog();
                    if (dialog.DialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        item2.Properties["SourceUri"].SetValue(dialog.SourceUri);
                        if (string.IsNullOrEmpty(dialog.XmlText))
                            propertyValue.Value = null;
                        else
                        {
                            var vbv = new VisualBasicValue<XElement>(dialog.XmlText);
                            propertyValue.Value = new InArgument<XElement>(vbv);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions