You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@ -0,0 +1,53 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Activities;
|
||||
using System.Activities.Core.Presentation;
|
||||
|
||||
sealed class ActivityXRefConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(targetType == typeof(string) || targetType == typeof(object)))
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new NotSupportedException());
|
||||
}
|
||||
if (null == value)
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new ArgumentNullException("value"));
|
||||
}
|
||||
ModelItem activity = value as ModelItem;
|
||||
string displayName = value as string;
|
||||
|
||||
string formatString = (parameter as string) ?? "{0}";
|
||||
|
||||
if (null != activity && typeof(Activity).IsAssignableFrom(activity.ItemType))
|
||||
{
|
||||
displayName = ((string)activity.Properties["DisplayName"].ComputedValue);
|
||||
}
|
||||
|
||||
if (null == displayName)
|
||||
{
|
||||
displayName = "<null>";
|
||||
}
|
||||
else if (displayName.Length == 0)
|
||||
{
|
||||
displayName = "...";
|
||||
}
|
||||
|
||||
return string.Format(CultureInfo.CurrentUICulture, formatString, displayName);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new NotSupportedException());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Configuration;
|
||||
using System.ServiceModel.Configuration;
|
||||
using System.Activities.Presentation;
|
||||
|
||||
partial class BindingEditor
|
||||
{
|
||||
public static readonly DependencyProperty BindingProperty =
|
||||
DependencyProperty.Register("Binding",
|
||||
typeof(object),
|
||||
typeof(BindingEditor),
|
||||
new PropertyMetadata(OnBindingChanged));
|
||||
|
||||
List<BindingDescriptor> bindingElements = new List<BindingDescriptor>();
|
||||
|
||||
bool isInitializing;
|
||||
|
||||
public BindingEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public object Binding
|
||||
{
|
||||
get { return GetValue(BindingProperty); }
|
||||
set { SetValue(BindingProperty, value); }
|
||||
}
|
||||
|
||||
void LoadBindings()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.bindingElements.Add(new BindingDescriptor { BindingName = (string)(this.TryFindResource("bindingEditorEmptyBindingLabel") ?? "none"), Value = null });
|
||||
Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration();
|
||||
ServiceModelSectionGroup section = ServiceModelSectionGroup.GetSectionGroup(machineConfig);
|
||||
if (null != section && null != section.Bindings)
|
||||
{
|
||||
this.bindingElements.AddRange(section.Bindings.BindingCollections
|
||||
.OrderBy(p => p.BindingName)
|
||||
.Select<BindingCollectionElement, BindingDescriptor>(p => new BindingDescriptor() { BindingName = p.BindingName, Value = p }));
|
||||
}
|
||||
}
|
||||
catch (ConfigurationErrorsException err)
|
||||
{
|
||||
ErrorReporting.ShowErrorMessage(err.Message);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInitialized(EventArgs e)
|
||||
{
|
||||
base.OnInitialized(e);
|
||||
this.isInitializing = true;
|
||||
LoadBindings();
|
||||
this.ItemsSource = this.bindingElements;
|
||||
this.SelectedIndex = 0;
|
||||
this.isInitializing = false;
|
||||
}
|
||||
|
||||
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
|
||||
{
|
||||
base.OnSelectionChanged(e);
|
||||
if (!this.isInitializing)
|
||||
{
|
||||
|
||||
BindingDescriptor entry = (BindingDescriptor)e.AddedItems[0];
|
||||
if (null == entry.Value)
|
||||
{
|
||||
Binding = null;
|
||||
}
|
||||
// try to avoid blowing away any binding that has been custom-tweaked in XAML.
|
||||
else if (Binding == null || !(Binding is ModelItem) || !((ModelItem)Binding).ItemType.Equals(entry.Value.BindingType))
|
||||
{
|
||||
Binding instance = (Binding)Activator.CreateInstance(entry.Value.BindingType);
|
||||
instance.Name = entry.BindingName;
|
||||
Binding = instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OnBindingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
BindingEditor editor = (BindingEditor)sender;
|
||||
object newValue = args.NewValue;
|
||||
|
||||
Type bindingType = null;
|
||||
ModelItem item = newValue as ModelItem;
|
||||
string bindingName = null;
|
||||
if (item != null)
|
||||
{
|
||||
bindingType = item.ItemType;
|
||||
bindingName = (string)item.Properties["Name"].ComputedValue;
|
||||
}
|
||||
else if (newValue != null)
|
||||
{
|
||||
bindingType = newValue.GetType();
|
||||
if (typeof(Binding).IsAssignableFrom(bindingType))
|
||||
{
|
||||
bindingName = ((Binding)newValue).Name;
|
||||
}
|
||||
}
|
||||
|
||||
// Make combo appear empty if the binding is not one of the ones known to us, e.g., has been custom-tweaked in XAML.
|
||||
BindingDescriptor toSelect = null;
|
||||
Func<BindingDescriptor, bool> where = p => null != p.Value && p.Value.BindingType == bindingType;
|
||||
if (editor.bindingElements.Count(where) > 1)
|
||||
{
|
||||
toSelect = editor.bindingElements.Where(where).Where(p => string.Equals(p.BindingName, bindingName)).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
toSelect = editor.bindingElements.Where(where).FirstOrDefault();
|
||||
}
|
||||
//prevent OnSelectionChanged now - the binding is set directly to the object, no need to set again through event handler
|
||||
editor.isInitializing = true;
|
||||
if (null != toSelect)
|
||||
{
|
||||
editor.SelectedItem = toSelect;
|
||||
}
|
||||
else
|
||||
{
|
||||
editor.SelectedIndex = 0;
|
||||
}
|
||||
//allow selection changed events to be consumed again
|
||||
editor.isInitializing = false;
|
||||
}
|
||||
|
||||
sealed class BindingDescriptor
|
||||
{
|
||||
public string BindingName
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public BindingCollectionElement Value
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return BindingName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Activities.Presentation.PropertyEditing;
|
||||
using System.Activities.Core.Presentation.Themes;
|
||||
|
||||
sealed class BindingPropertyValueEditor : PropertyValueEditor
|
||||
{
|
||||
public BindingPropertyValueEditor()
|
||||
{
|
||||
this.InlineEditorTemplate = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("Binding_InlineEditorTemplate");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Runtime;
|
||||
using System.Activities.Core.Presentation;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
sealed class ContentButtonTitleConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
object content = value;
|
||||
if (content != null && content is ModelItem)
|
||||
{
|
||||
content = ((ModelItem)content).GetCurrentValue();
|
||||
}
|
||||
if (content == null)
|
||||
{
|
||||
return SR.DefineContent;
|
||||
}
|
||||
else
|
||||
{
|
||||
//string contentTypeName = content.GetType().Name;
|
||||
if (content is ReceiveMessageContent || content is SendMessageContent)
|
||||
{
|
||||
return SR.ViewMessageContent;
|
||||
}
|
||||
else if (content is ReceiveParametersContent || content is SendParametersContent)
|
||||
{
|
||||
return SR.ViewParameterContent;
|
||||
}
|
||||
else
|
||||
{
|
||||
Fx.Assert(false, "Content must be of either ReceiveMessageContent, ReceiveParametersContent, SendMessageContent or SendParametersContent.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new NotSupportedException());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,315 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Activities.Presentation;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using System.Xml;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Xml.Linq;
|
||||
|
||||
partial class ContentCorrelationTypeExpander
|
||||
{
|
||||
static readonly DependencyPropertyKey IsSelectionValidPropertyKey = DependencyProperty.RegisterReadOnly(
|
||||
"IsSelectionValid",
|
||||
typeof(bool),
|
||||
typeof(ContentCorrelationTypeExpander),
|
||||
new UIPropertyMetadata(false, OnIsSelectionValidChanged));
|
||||
|
||||
public static readonly DependencyProperty IsSelectionValidProperty = IsSelectionValidPropertyKey.DependencyProperty;
|
||||
|
||||
public static readonly RoutedEvent IsSelectionValidChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"IsSelectionValidChanged",
|
||||
RoutingStrategy.Bubble,
|
||||
typeof(RoutedEventHandler),
|
||||
typeof(ContentCorrelationTypeExpander));
|
||||
|
||||
public static readonly RoutedEvent SelectionChangedEvent = EventManager.RegisterRoutedEvent(
|
||||
"SelectionChanged",
|
||||
RoutingStrategy.Bubble,
|
||||
typeof(RoutedEventHandler),
|
||||
typeof(ContentCorrelationTypeExpander));
|
||||
|
||||
public static readonly DependencyProperty TypesToExpandProperty = DependencyProperty.Register(
|
||||
"TypesToExpand",
|
||||
typeof(IList<ExpanderTypeEntry>),
|
||||
typeof(ContentCorrelationTypeExpander),
|
||||
new UIPropertyMetadata(null, OnTypesToExpandChanged));
|
||||
|
||||
static readonly DependencyPropertyKey SelectedTypeEntryPropertyKey = DependencyProperty.RegisterReadOnly(
|
||||
"SelectedTypeEntry",
|
||||
typeof(ExpanderTypeEntry),
|
||||
typeof(ContentCorrelationTypeExpander),
|
||||
new UIPropertyMetadata(null));
|
||||
|
||||
public static readonly DependencyProperty SelectedTypeEntryProperty = SelectedTypeEntryPropertyKey.DependencyProperty;
|
||||
|
||||
static readonly Type[] PrimitiveTypesInXPath = new Type[]
|
||||
{
|
||||
typeof(DateTime),
|
||||
typeof(TimeSpan),
|
||||
typeof(XmlQualifiedName),
|
||||
typeof(Uri),
|
||||
typeof(Guid),
|
||||
typeof(XmlElement),
|
||||
typeof(string),
|
||||
typeof(object),
|
||||
typeof(Decimal),
|
||||
typeof(XElement),
|
||||
};
|
||||
|
||||
MemberInfo[] path = null;
|
||||
Type selectedType = null;
|
||||
|
||||
public ContentCorrelationTypeExpander()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event RoutedEventHandler IsSelectionValidChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
AddHandler(IsSelectionValidChangedEvent, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
RemoveHandler(IsSelectionValidChangedEvent, value);
|
||||
}
|
||||
}
|
||||
|
||||
public event RoutedEventHandler SelectionChanged
|
||||
{
|
||||
add
|
||||
{
|
||||
AddHandler(SelectionChangedEvent, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
RemoveHandler(SelectionChangedEvent, value);
|
||||
}
|
||||
}
|
||||
public bool IsSelectionValid
|
||||
{
|
||||
get { return (bool)GetValue(IsSelectionValidProperty); }
|
||||
private set { SetValue(IsSelectionValidPropertyKey, value); }
|
||||
}
|
||||
|
||||
public IList<ExpanderTypeEntry> TypesToExpand
|
||||
{
|
||||
get { return (IList<ExpanderTypeEntry>)GetValue(TypesToExpandProperty); }
|
||||
set { SetValue(TypesToExpandProperty, value); }
|
||||
}
|
||||
|
||||
public ExpanderTypeEntry SelectedTypeEntry
|
||||
{
|
||||
get { return (ExpanderTypeEntry)GetValue(SelectedTypeEntryProperty); }
|
||||
private set { SetValue(SelectedTypeEntryPropertyKey, value); }
|
||||
}
|
||||
|
||||
public Type GetSelectedType()
|
||||
{
|
||||
return this.selectedType;
|
||||
}
|
||||
|
||||
public MemberInfo[] GetMemberPath()
|
||||
{
|
||||
return this.path;
|
||||
}
|
||||
|
||||
void RaiseSelectionValidChanged()
|
||||
{
|
||||
this.RaiseEvent(new RoutedEventArgs(IsSelectionValidChangedEvent, this));
|
||||
}
|
||||
|
||||
void OnTypesToExpandChanged()
|
||||
{
|
||||
this.typeExpander.ItemsSource = this.TypesToExpand;
|
||||
this.emptyContent.Visibility = null == this.TypesToExpand || 0 == this.TypesToExpand.Count ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
void OnTypeExpanderLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.typeExpander.Focus();
|
||||
}
|
||||
|
||||
void OnTreeViewItemLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var item = (TreeViewItem)sender;
|
||||
if (null != item.Header)
|
||||
{
|
||||
if (item.Header is ExpanderTypeEntry)
|
||||
{
|
||||
item.IsExpanded = true;
|
||||
}
|
||||
else if (item.Header is Type)
|
||||
{
|
||||
var type = (Type)item.Header;
|
||||
item.IsExpanded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTreeViewItemMouseAccept(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var item = sender as TreeViewItem;
|
||||
if (null != item && item.Header is ExpanderTypeEntry)
|
||||
{
|
||||
this.SelectedTypeEntry = (ExpanderTypeEntry)item.Header;
|
||||
}
|
||||
if (null != item && item.IsSelected && item.IsSelectionActive)
|
||||
{
|
||||
this.Accept(item);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTreeViewItemKeyboardAccept(object sender, KeyEventArgs e)
|
||||
{
|
||||
var item = sender as TreeViewItem;
|
||||
if (null != item && item.Header is ExpanderTypeEntry)
|
||||
{
|
||||
this.SelectedTypeEntry = (ExpanderTypeEntry)item.Header;
|
||||
}
|
||||
if (null != item && item.IsSelected && item.IsSelectionActive && Key.Enter == e.Key && Keyboard.Modifiers == ModifierKeys.None)
|
||||
{
|
||||
this.Accept(item);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Accept(TreeViewItem item)
|
||||
{
|
||||
bool isType = item.Header is ExpanderTypeEntry;
|
||||
bool isMember = item.Header is MemberInfo;
|
||||
if (isMember)
|
||||
{
|
||||
var members = new List<MemberInfo>(1);
|
||||
while (null != item && item.Header is MemberInfo)
|
||||
{
|
||||
var member = (MemberInfo)item.Header;
|
||||
members.Insert(0, member);
|
||||
|
||||
if (item.Tag is TreeViewItem)
|
||||
{
|
||||
item = (TreeViewItem)item.Tag;
|
||||
}
|
||||
else
|
||||
{
|
||||
item = null;
|
||||
}
|
||||
}
|
||||
this.SelectedTypeEntry = (ExpanderTypeEntry)item.Header;
|
||||
this.selectedType = this.SelectedTypeEntry.TypeToExpand;
|
||||
this.path = members.ToArray();
|
||||
}
|
||||
else if (isType)
|
||||
{
|
||||
this.SelectedTypeEntry = (ExpanderTypeEntry)item.Header;
|
||||
this.selectedType = this.SelectedTypeEntry.TypeToExpand;
|
||||
this.path = new MemberInfo[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SelectedTypeEntry = null;
|
||||
this.selectedType = null;
|
||||
this.path = null;
|
||||
}
|
||||
this.IsSelectionValid = isType || isMember;
|
||||
this.RaiseEvent(new RoutedEventArgs(SelectionChangedEvent, this));
|
||||
}
|
||||
|
||||
//The following types are considered as primitives as far as XPath generation is concerned and shouldn't be expanded any more
|
||||
// 1. CLR built-in types
|
||||
// 2. Byte array, DateTime, TimeSpan, GUID, Uri, XmlQualifiedName, XmlElement and XmlNode array [This includes XElement and XNode array from .NET 3.5]
|
||||
// 3. Enums
|
||||
// 4. Arrays and Collection classes including List<T>, Dictionary<K,V> and Hashtable (Anything that implements IEnumerable or IDictionary or is an array is treated as a collection).
|
||||
// 5. Type has [CollectionDataContract] attribute
|
||||
internal static bool IsPrimitiveTypeInXPath(Type type)
|
||||
{
|
||||
return ((type.IsPrimitive) || type.IsEnum || PrimitiveTypesInXPath.Any((item => item == type))
|
||||
|| (typeof(IEnumerable).IsAssignableFrom(type)) || typeof(IDictionary).IsAssignableFrom(type) || type.IsArray
|
||||
|| (type.GetCustomAttributes(typeof(CollectionDataContractAttribute), false).Length > 0));
|
||||
}
|
||||
|
||||
static void OnIsSelectionValidChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
((ContentCorrelationTypeExpander)sender).RaiseSelectionValidChanged();
|
||||
}
|
||||
|
||||
static void OnTypesToExpandChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var control = (ContentCorrelationTypeExpander)sender;
|
||||
control.Dispatcher.BeginInvoke(new Action(() => { control.OnTypesToExpandChanged(); }), DispatcherPriority.Render);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class TypeEntryContainer
|
||||
{
|
||||
public string DisplayText { get; set; }
|
||||
public IList<ExpanderTypeEntry> Items { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.DisplayText ?? base.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ExpanderTypeEntry : DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty NameProperty = DependencyProperty.Register(
|
||||
"Name",
|
||||
typeof(string),
|
||||
typeof(ExpanderTypeEntry),
|
||||
new UIPropertyMetadata(string.Empty));
|
||||
|
||||
public static readonly DependencyProperty TypeToExpandProperty = DependencyProperty.Register(
|
||||
"TypeToExpand",
|
||||
typeof(Type),
|
||||
typeof(ExpanderTypeEntry),
|
||||
new UIPropertyMetadata(null));
|
||||
|
||||
public static readonly DependencyProperty TagProperty = DependencyProperty.Register(
|
||||
"Tag",
|
||||
typeof(object),
|
||||
typeof(ExpanderTypeEntry),
|
||||
new UIPropertyMetadata(null));
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return (string)GetValue(NameProperty); }
|
||||
set { SetValue(NameProperty, value); }
|
||||
}
|
||||
|
||||
public Type TypeToExpand
|
||||
{
|
||||
get { return (Type)GetValue(TypeToExpandProperty); }
|
||||
set { SetValue(TypeToExpandProperty, value); }
|
||||
}
|
||||
|
||||
public Type[] TypeToExpandSource
|
||||
{
|
||||
get { return new Type[] { this.TypeToExpand }; }
|
||||
}
|
||||
|
||||
public object Tag
|
||||
{
|
||||
get { return GetValue(TagProperty); }
|
||||
set { SetValue(TagProperty, value); }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name ?? "<null>";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,216 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Presentation.Hosting;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
|
||||
class ContentDialogViewModel<TMessage, TParameter> : INotifyPropertyChanged
|
||||
where TMessage : new()
|
||||
where TParameter : new()
|
||||
{
|
||||
EditingMode editingMode = EditingMode.Message;
|
||||
ModelItem messageExpression;
|
||||
Type declaredMessageType;
|
||||
|
||||
public ContentDialogViewModel(ModelItem modelItem)
|
||||
{
|
||||
this.ModelItem = modelItem;
|
||||
InitializeMessageAndParameterData();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public bool IsEditingEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return !this.Context.Items.GetValue<ReadOnlyState>().IsReadOnly;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsMessageChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.editingMode == EditingMode.Message;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != this.IsMessageChecked)
|
||||
{
|
||||
this.editingMode = value ? EditingMode.Message : EditingMode.Parameter;
|
||||
OnModeChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsParameterChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.editingMode == EditingMode.Parameter;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != this.IsParameterChecked)
|
||||
{
|
||||
this.editingMode = value ? EditingMode.Parameter : EditingMode.Message;
|
||||
OnModeChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ModelItem ModelItem
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public EditingContext Context
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ModelItem.GetEditingContext();
|
||||
}
|
||||
}
|
||||
|
||||
public ModelItem MessageExpression
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.messageExpression;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.messageExpression = value;
|
||||
if (this.PropertyChanged != null)
|
||||
{
|
||||
this.PropertyChanged(this, new PropertyChangedEventArgs("MessageExpression"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Type DeclaredMessageType
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.declaredMessageType;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.declaredMessageType = value;
|
||||
if (this.PropertyChanged != null)
|
||||
{
|
||||
this.PropertyChanged(this, new PropertyChangedEventArgs("DeclaredMessageType"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDictionary
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public Type UnderlyingArgumentType
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public ObservableCollection<DynamicArgumentWrapperObject> DynamicArguments
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
internal bool OnOk()
|
||||
{
|
||||
ModelProperty contentProperty = this.ModelItem.Properties["Content"];
|
||||
if (this.editingMode == EditingMode.Parameter)
|
||||
{
|
||||
contentProperty.SetValue(new TParameter());
|
||||
DynamicArgumentDesigner.WrapperCollectionToModelItem(this.DynamicArguments,
|
||||
contentProperty.Value.Properties["Parameters"].Value,
|
||||
this.IsDictionary, this.UnderlyingArgumentType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.DeclaredMessageType == null && this.MessageExpression == null)
|
||||
{
|
||||
contentProperty.SetValue(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
contentProperty.SetValue(new TMessage());
|
||||
contentProperty.Value.Properties["Message"].SetValue(this.MessageExpression);
|
||||
contentProperty.Value.Properties["DeclaredMessageType"].SetValue(this.DeclaredMessageType);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InitializeMessageAndParameterData()
|
||||
{
|
||||
ModelItem parameterModelItem;
|
||||
ModelTreeManager modelTreeManager = (this.ModelItem as IModelTreeItem).ModelTreeManager;
|
||||
|
||||
ModelItem contentModelItem = this.ModelItem.Properties["Content"].Value;
|
||||
if (contentModelItem == null)
|
||||
{
|
||||
this.messageExpression = modelTreeManager.WrapAsModelItem(new TMessage()).Properties["Message"].Value;
|
||||
this.declaredMessageType = null;
|
||||
parameterModelItem = modelTreeManager.WrapAsModelItem(new TParameter()).Properties["Parameters"].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (contentModelItem.ItemType == typeof(TMessage))
|
||||
{
|
||||
this.editingMode = EditingMode.Message;
|
||||
this.messageExpression = contentModelItem.Properties["Message"].Value;
|
||||
this.declaredMessageType = (Type)contentModelItem.Properties["DeclaredMessageType"].ComputedValue;
|
||||
parameterModelItem = modelTreeManager.WrapAsModelItem(new TParameter()).Properties["Parameters"].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.editingMode = EditingMode.Parameter;
|
||||
this.messageExpression = modelTreeManager.WrapAsModelItem(new TMessage()).Properties["Message"].Value;
|
||||
this.declaredMessageType = null;
|
||||
parameterModelItem = contentModelItem.Properties["Parameters"].Value;
|
||||
}
|
||||
}
|
||||
|
||||
bool isDictionary;
|
||||
Type underlyingArgumentType;
|
||||
this.DynamicArguments = DynamicArgumentDesigner.ModelItemToWrapperCollection(
|
||||
parameterModelItem,
|
||||
out isDictionary,
|
||||
out underlyingArgumentType);
|
||||
|
||||
this.IsDictionary = isDictionary;
|
||||
this.UnderlyingArgumentType = underlyingArgumentType;
|
||||
}
|
||||
|
||||
void OnModeChanged()
|
||||
{
|
||||
if (this.PropertyChanged != null)
|
||||
{
|
||||
this.PropertyChanged(this, new PropertyChangedEventArgs("IsMessageChecked"));
|
||||
this.PropertyChanged(this, new PropertyChangedEventArgs("IsParameterChecked"));
|
||||
}
|
||||
}
|
||||
|
||||
enum EditingMode
|
||||
{
|
||||
Message,
|
||||
Parameter
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation.Converters
|
||||
{
|
||||
using System.Activities.Presentation.Converters;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel.Activities;
|
||||
|
||||
class ReceiveMessageContentSearchableStringConverter : SearchableStringConverter
|
||||
{
|
||||
public override IList<string> Convert(object value)
|
||||
{
|
||||
List<string> results = new List<string>();
|
||||
ReceiveMessageContent content = value as ReceiveMessageContent;
|
||||
if (null != content)
|
||||
{
|
||||
results.AddRange(new ArgumentSearchableStringConverter().Convert(content.Message));
|
||||
results.AddRange(new TypeSearchableStringConverter().Convert(content.DeclaredMessageType));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation.Converters
|
||||
{
|
||||
using System.Activities;
|
||||
using System.Activities.Presentation.Converters;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel.Activities;
|
||||
|
||||
class ReceiveParametersContentSearchableStringConverter : SearchableStringConverter
|
||||
{
|
||||
public override IList<string> Convert(object value)
|
||||
{
|
||||
List<string> results = new List<string>();
|
||||
ReceiveParametersContent content = value as ReceiveParametersContent;
|
||||
if (null != content)
|
||||
{
|
||||
foreach (KeyValuePair<string, OutArgument> param in content.Parameters)
|
||||
{
|
||||
results.Add(param.Key);
|
||||
results.Add(param.Value.GetType().Name);
|
||||
results.AddRange(new ArgumentSearchableStringConverter().Convert(param.Value));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation.Converters
|
||||
{
|
||||
using System.Activities.Presentation.Converters;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel.Activities;
|
||||
|
||||
class SendMessageContentSearchableStringConverter : SearchableStringConverter
|
||||
{
|
||||
public override IList<string> Convert(object value)
|
||||
{
|
||||
List<string> results = new List<string>();
|
||||
SendMessageContent content = value as SendMessageContent;
|
||||
if (null != content)
|
||||
{
|
||||
results.AddRange(new ArgumentSearchableStringConverter().Convert(content.Message));
|
||||
results.AddRange(new TypeSearchableStringConverter().Convert(content.DeclaredMessageType));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation.Converters
|
||||
{
|
||||
using System.Activities;
|
||||
using System.Activities.Presentation.Converters;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel.Activities;
|
||||
|
||||
class SendParametersContentSearchableStringConverter : SearchableStringConverter
|
||||
{
|
||||
public override IList<string> Convert(object value)
|
||||
{
|
||||
List<string> results = new List<string>();
|
||||
SendParametersContent content = value as SendParametersContent;
|
||||
if (null != content)
|
||||
{
|
||||
foreach (KeyValuePair<string, InArgument> param in content.Parameters)
|
||||
{
|
||||
results.Add(param.Key);
|
||||
results.Add(param.Value.GetType().Name);
|
||||
results.AddRange(new ArgumentSearchableStringConverter().Convert(param.Value));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation.Converters
|
||||
{
|
||||
using System.Activities;
|
||||
using System.Activities.Presentation.Converters;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel;
|
||||
|
||||
class XPathMessageQuerySearchableStringConverter : SearchableStringConverter
|
||||
{
|
||||
public override IList<string> Convert(object value)
|
||||
{
|
||||
IList<string> results = new List<string>();
|
||||
XPathMessageQuery messageQuery = value as XPathMessageQuery;
|
||||
if (messageQuery != null)
|
||||
{
|
||||
results.Add(messageQuery.Expression);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Activities.Core.Presentation.Themes;
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Presentation.Converters;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Activities.Presentation.PropertyEditing;
|
||||
using System.Activities.Presentation.View;
|
||||
using System.Windows;
|
||||
using System.Runtime;
|
||||
using System.Windows.Controls;
|
||||
|
||||
sealed class CorrelatesOnValueEditor : DialogPropertyValueEditor
|
||||
{
|
||||
public CorrelatesOnValueEditor()
|
||||
{
|
||||
this.InlineEditorTemplate = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("CorrelatesOnDesigner_InlineTemplate");
|
||||
}
|
||||
|
||||
public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
|
||||
{
|
||||
ModelPropertyEntryToOwnerActivityConverter propertyEntryConverter = new ModelPropertyEntryToOwnerActivityConverter();
|
||||
|
||||
ModelItem modelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null);
|
||||
EditingContext context = modelItem.GetEditingContext();
|
||||
|
||||
this.ShowDialog(modelItem, context);
|
||||
}
|
||||
|
||||
public void ShowDialog(ModelItem activity, EditingContext context)
|
||||
{
|
||||
Fx.Assert(activity != null, "Activity model item shouldn't be null!");
|
||||
Fx.Assert(context != null, "EditingContext shouldn't be null!");
|
||||
|
||||
|
||||
string bookmarkTitle = (string)this.InlineEditorTemplate.Resources["bookmarkTitle"];
|
||||
|
||||
UndoEngine undoEngine = context.Services.GetService<UndoEngine>();
|
||||
Fx.Assert(null != undoEngine, "UndoEngine should be available");
|
||||
|
||||
using (EditingScope scope = context.Services.GetRequiredService<ModelTreeManager>().CreateEditingScope(bookmarkTitle, true))
|
||||
{
|
||||
if ((new EditorWindow(activity, context)).ShowOkCancel())
|
||||
{
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class EditorWindow : WorkflowElementDialog
|
||||
{
|
||||
public EditorWindow(ModelItem activity, EditingContext context)
|
||||
{
|
||||
this.ModelItem = activity;
|
||||
this.Context = context;
|
||||
this.Owner = activity.View;
|
||||
this.EnableMaximizeButton = false;
|
||||
this.EnableMinimizeButton = false;
|
||||
this.MinHeight = 250;
|
||||
this.MinWidth = 450;
|
||||
this.WindowResizeMode = ResizeMode.CanResize;
|
||||
this.WindowSizeToContent = SizeToContent.Manual;
|
||||
var template = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("CorrelatesOnDesigner_DialogTemplate");
|
||||
|
||||
var presenter = new ContentPresenter()
|
||||
{
|
||||
Content = activity,
|
||||
ContentTemplate = template
|
||||
};
|
||||
this.Title = (string)template.Resources["controlTitle"];
|
||||
this.Content = presenter;
|
||||
this.HelpKeyword = HelpKeywords.CorrelatesOnDefinitionDialog;
|
||||
}
|
||||
|
||||
protected override void OnWorkflowElementDialogClosed(bool? dialogResult)
|
||||
{
|
||||
if (dialogResult.HasValue && dialogResult.Value)
|
||||
{
|
||||
var correlatesOnProperty = this.ModelItem.Properties["CorrelatesOn"];
|
||||
|
||||
if (correlatesOnProperty.IsSet && 0 == correlatesOnProperty.Dictionary.Count)
|
||||
{
|
||||
correlatesOnProperty.ClearValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,232 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Activities;
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Activities.Presentation.View;
|
||||
using System.Windows.Input;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime;
|
||||
using System.Activities.Presentation.Hosting;
|
||||
using System.Windows.Controls;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
internal partial class CorrelationDataDesigner
|
||||
{
|
||||
const string KeyPrefix = "key";
|
||||
|
||||
public static readonly DependencyProperty ActivityProperty = DependencyProperty.Register(
|
||||
"Activity",
|
||||
typeof(ModelItem),
|
||||
typeof(CorrelationDataDesigner),
|
||||
new UIPropertyMetadata(OnActivityChanged));
|
||||
|
||||
public static readonly DependencyProperty CorrelationInitializeDataProperty = DependencyProperty.Register(
|
||||
"CorrelationInitializeData",
|
||||
typeof(ObservableCollection<CorrelationDataWrapper>),
|
||||
typeof(CorrelationDataDesigner),
|
||||
new UIPropertyMetadata(OnCorrelationDataChanged));
|
||||
|
||||
public static readonly DependencyProperty CorrelationHandleProperty = DependencyProperty.Register(
|
||||
"CorrelationHandle",
|
||||
typeof(ModelItem),
|
||||
typeof(CorrelationDataDesigner));
|
||||
|
||||
public static readonly RoutedCommand AddNewDataCommand = new RoutedCommand("AddNewDataCommand", typeof(CorrelationDataDesigner));
|
||||
|
||||
DataGridHelper correlationDataDGHelper;
|
||||
|
||||
public ModelItem Activity
|
||||
{
|
||||
get { return (ModelItem)GetValue(ActivityProperty); }
|
||||
set { SetValue(ActivityProperty, value); }
|
||||
}
|
||||
|
||||
public ObservableCollection<CorrelationDataWrapper> CorrelationInitializeData
|
||||
{
|
||||
get { return (ObservableCollection<CorrelationDataWrapper>)GetValue(CorrelationInitializeDataProperty); }
|
||||
set { SetValue(CorrelationInitializeDataProperty, value); }
|
||||
}
|
||||
|
||||
public ModelItem CorrelationHandle
|
||||
{
|
||||
get { return (ModelItem)GetValue(CorrelationHandleProperty); }
|
||||
set { SetValue(CorrelationHandleProperty, value); }
|
||||
}
|
||||
|
||||
public CorrelationDataDesigner()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
//create data grid helper
|
||||
this.correlationDataDGHelper = new DataGridHelper(this.correlationInitializers, this);
|
||||
//add binding to handle Add new entry clicks
|
||||
this.CommandBindings.Add(new CommandBinding(AddNewDataCommand, OnAddNewDataExecuted));
|
||||
//provide callback to add new row functionality
|
||||
this.correlationDataDGHelper.AddNewRowCommand = AddNewDataCommand;
|
||||
//add title for "add new row" button
|
||||
this.correlationDataDGHelper.AddNewRowContent = (string)this.FindResource("addNewEntry");
|
||||
|
||||
CorrelationDataWrapper.Editor = this;
|
||||
}
|
||||
|
||||
protected override void OnInitialized(EventArgs e)
|
||||
{
|
||||
base.OnInitialized(e);
|
||||
this.Loaded += this.OnCorrelationDataDesignerLoaded;
|
||||
}
|
||||
|
||||
void OnCorrelationDataDesignerLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
bool isReadOnly = this.Activity != null ? this.Activity.GetEditingContext().Items.GetValue<ReadOnlyState>().IsReadOnly : false;
|
||||
this.correlationInitializers.IsReadOnly = isReadOnly;
|
||||
this.correlationHandleETB.IsReadOnly = isReadOnly;
|
||||
}
|
||||
|
||||
void OnExpressionTextBoxLoaded(object sender, RoutedEventArgs args)
|
||||
{
|
||||
((ExpressionTextBox)sender).IsIndependentExpression = true;
|
||||
}
|
||||
|
||||
//user clicked Add new data
|
||||
void OnAddNewDataExecuted(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
//generate unique dictionary key
|
||||
string keyName = this.CorrelationInitializeData.GetUniqueName<CorrelationDataWrapper>(KeyPrefix, item => item.Key);
|
||||
//create new key value pair and add it to the dictionary
|
||||
CorrelationDataWrapper wrapper = new CorrelationDataWrapper(keyName, null);
|
||||
this.CorrelationInitializeData.Add(wrapper);
|
||||
//begin row edit after adding new entry
|
||||
this.correlationDataDGHelper.BeginRowEdit(wrapper, this.correlationInitializers.Columns[1]);
|
||||
}
|
||||
|
||||
static void OnActivityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var item = e.NewValue as ModelItem;
|
||||
if (null != item && !item.IsAssignableFrom<InitializeCorrelation>())
|
||||
{
|
||||
Fx.Assert("CorrelationDataDesigner can only used to edit CorrelationData property of InitializeCorrelation activity");
|
||||
}
|
||||
}
|
||||
|
||||
static void OnCorrelationDataChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
(sender as CorrelationDataDesigner).correlationInitializers.ItemsSource = e.NewValue as ObservableCollection<CorrelationDataWrapper>;
|
||||
}
|
||||
|
||||
internal void CommitEdit()
|
||||
{
|
||||
if ((this.Activity != null) && (this.Activity.ItemType == typeof(InitializeCorrelation)))
|
||||
{
|
||||
using (ModelEditingScope scope = this.Activity.BeginEdit((string)this.FindResource("editCorrelationDataDescription")))
|
||||
{
|
||||
this.Activity.Properties[InitializeCorrelationDesigner.CorrelationPropertyName].SetValue(this.CorrelationHandle);
|
||||
ModelItemCollection correlationDataCollection = this.Activity.Properties[InitializeCorrelationDesigner.CorrelationDataPropertyName].Dictionary.Properties["ItemsCollection"].Collection;
|
||||
correlationDataCollection.Clear();
|
||||
foreach (CorrelationDataWrapper wrapper in this.CorrelationInitializeData)
|
||||
{
|
||||
correlationDataCollection.Add(new ModelItemKeyValuePair<string, InArgument<string>>
|
||||
{
|
||||
Key = wrapper.Key,
|
||||
Value = wrapper.Value != null ? wrapper.Value.GetCurrentValue() as InArgument<string> : null
|
||||
});
|
||||
}
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void ValidateKey(CorrelationDataWrapper wrapper, string oldKey)
|
||||
{
|
||||
string newKey = wrapper.Key;
|
||||
if (string.IsNullOrEmpty(newKey))
|
||||
{
|
||||
ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, System.Activities.Core.Presentation.SR.NullOrEmptyKeyName));
|
||||
wrapper.Key = oldKey;
|
||||
}
|
||||
else
|
||||
{
|
||||
// At this point, the key of the entry has already been changed. If there are
|
||||
// entries with duplicate keys, the number of those entries is greater than 1.
|
||||
// Thus, we only need to check the entry count.
|
||||
int entryCount = this.CorrelationInitializeData.Count(entry => entry.Key == newKey);
|
||||
if (entryCount > 1)
|
||||
{
|
||||
ErrorReporting.ShowErrorMessage(string.Format(CultureInfo.CurrentCulture, System.Activities.Core.Presentation.SR.DuplicateKeyName, newKey));
|
||||
wrapper.Key = oldKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnEditingControlLoaded(object sender, RoutedEventArgs args)
|
||||
{
|
||||
DataGridHelper.OnEditingControlLoaded(sender, args);
|
||||
}
|
||||
|
||||
void OnEditingControlUnloaded(object sender, RoutedEventArgs args)
|
||||
{
|
||||
DataGridHelper.OnEditingControlUnloaded(sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CorrelationDataWrapper : DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty KeyProperty =
|
||||
DependencyProperty.Register("Key", typeof(string), typeof(CorrelationDataWrapper), new UIPropertyMetadata(string.Empty, OnKeyChanged));
|
||||
|
||||
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
DependencyProperty.Register("Value", typeof(ModelItem), typeof(CorrelationDataWrapper));
|
||||
|
||||
bool isValidating;
|
||||
public ModelItem Value
|
||||
{
|
||||
get { return (ModelItem)GetValue(ValueProperty); }
|
||||
set { SetValue(ValueProperty, value); }
|
||||
}
|
||||
|
||||
public string Key
|
||||
{
|
||||
get { return (string)GetValue(KeyProperty); }
|
||||
set { SetValue(KeyProperty, value); }
|
||||
}
|
||||
|
||||
public static CorrelationDataDesigner Editor
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public CorrelationDataWrapper()
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new NotSupportedException());
|
||||
}
|
||||
|
||||
internal CorrelationDataWrapper(string key, ModelItem value)
|
||||
{
|
||||
//Skip validation when first populate the collection
|
||||
this.isValidating = true;
|
||||
this.Key = key;
|
||||
this.Value = value;
|
||||
this.isValidating = false;
|
||||
}
|
||||
|
||||
static void OnKeyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
CorrelationDataWrapper wrapper = sender as CorrelationDataWrapper;
|
||||
if ((wrapper != null) && (!wrapper.isValidating))
|
||||
{
|
||||
wrapper.isValidating = true;
|
||||
CorrelationDataWrapper.Editor.ValidateKey(wrapper, (string)e.OldValue);
|
||||
wrapper.isValidating = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,255 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Activities;
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Activities.Presentation.View;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
internal partial class CorrelationInitializerDesigner
|
||||
{
|
||||
DataGridHelper correlationInitializerDGHelper;
|
||||
|
||||
const string CorrelationInitializersKey = "CorrelationInitializers";
|
||||
|
||||
public static readonly DependencyProperty ActivityProperty = DependencyProperty.Register(
|
||||
"Activity",
|
||||
typeof(ModelItem),
|
||||
typeof(CorrelationInitializerDesigner),
|
||||
new UIPropertyMetadata(OnActivityChanged));
|
||||
|
||||
static readonly ICommand AddNewInitializerCommand = new RoutedCommand();
|
||||
|
||||
public CorrelationInitializerDesigner()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
public ModelItem Activity
|
||||
{
|
||||
get { return (ModelItem)GetValue(ActivityProperty); }
|
||||
set { SetValue(ActivityProperty, value); }
|
||||
}
|
||||
|
||||
ModelItemCollection CorrelationInitializers
|
||||
{
|
||||
get { return this.Activity.Properties[CorrelationInitializersKey].Collection; }
|
||||
}
|
||||
|
||||
protected override void OnInitialized(EventArgs args)
|
||||
{
|
||||
base.OnInitialized(args);
|
||||
|
||||
this.CommandBindings.Add(new CommandBinding(AddNewInitializerCommand, this.OnAddNewInitializerExecuted));
|
||||
|
||||
//create data grid helper
|
||||
this.correlationInitializerDGHelper = new DataGridHelper(this.correlationInitializers, this);
|
||||
this.correlationInitializerDGHelper.ShowValidationErrorAsToolTip = true;
|
||||
this.correlationInitializerDGHelper.AddNewRowContent = (string)this.FindResource("addNewInitializer");
|
||||
this.correlationInitializerDGHelper.AddNewRowCommand = CorrelationInitializerDesigner.AddNewInitializerCommand;
|
||||
}
|
||||
|
||||
void OnAddNewInitializerExecuted(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
var initializer = (CanUseQueryCorrelationInitializer(this.Activity) ?
|
||||
(CorrelationInitializer)new QueryCorrelationInitializer() : (CorrelationInitializer)new ContextCorrelationInitializer());
|
||||
var result = this.CorrelationInitializers.Add(initializer);
|
||||
var wrapper = new CorrelationInitializerEntry(result);
|
||||
this.correlationInitializerDGHelper.Source<IList>().Add(wrapper);
|
||||
this.correlationInitializerDGHelper.BeginRowEdit(wrapper);
|
||||
}
|
||||
|
||||
static bool CanUseQueryCorrelationInitializer(ModelItem activity)
|
||||
{
|
||||
bool result = true;
|
||||
if (null != activity)
|
||||
{
|
||||
if (activity.IsAssignableFrom<Receive>() || activity.IsAssignableFrom<Send>())
|
||||
{
|
||||
ModelItem serializationOption;
|
||||
activity.TryGetPropertyValue(out serializationOption, "SerializerOption");
|
||||
result = SerializerOption.XmlSerializer != (SerializerOption)serializationOption.GetCurrentValue();
|
||||
}
|
||||
else if (activity.IsAssignableFrom<SendReply>() || activity.IsAssignableFrom<ReceiveReply>())
|
||||
{
|
||||
ModelItem request;
|
||||
activity.TryGetPropertyValue(out request, "Request");
|
||||
result = CanUseQueryCorrelationInitializer(request);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void OnDataCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
foreach (CorrelationInitializerEntry entry in e.OldItems)
|
||||
{
|
||||
this.CorrelationInitializers.Remove(entry.ReflectedObject);
|
||||
entry.Dispose();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal void CleanupObjectMap()
|
||||
{
|
||||
}
|
||||
|
||||
void OnActivityChanged()
|
||||
{
|
||||
if (null != this.Activity)
|
||||
{
|
||||
var source = new ObservableCollection<CorrelationInitializerEntry>();
|
||||
|
||||
foreach (var entry in this.CorrelationInitializers)
|
||||
{
|
||||
var wrapper = new CorrelationInitializerEntry(entry);
|
||||
source.Add(wrapper);
|
||||
}
|
||||
|
||||
this.correlationInitializers.ItemsSource = source;
|
||||
source.CollectionChanged += this.OnDataCollectionChanged;
|
||||
}
|
||||
}
|
||||
|
||||
static void OnActivityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var activity = e.NewValue as ModelItem;
|
||||
if (null != activity && !activity.IsMessagingActivity())
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new NotSupportedException(activity.ItemType.FullName));
|
||||
}
|
||||
((CorrelationInitializerDesigner)sender).OnActivityChanged();
|
||||
}
|
||||
|
||||
void OnEditingControlLoaded(object sender, RoutedEventArgs args)
|
||||
{
|
||||
DataGridHelper.OnEditingControlLoaded(sender, args);
|
||||
}
|
||||
|
||||
void OnEditingControlUnloaded(object sender, RoutedEventArgs args)
|
||||
{
|
||||
DataGridHelper.OnEditingControlUnloaded(sender, args);
|
||||
}
|
||||
|
||||
internal sealed class CorrelationInitializerEntry : DesignObjectWrapper
|
||||
{
|
||||
internal static readonly string HandleProperty = "CorrelationHandle";
|
||||
internal static readonly string CorrelationTypeProperty = "CorrelationType";
|
||||
internal static readonly string MessageQuerySetModelPropertyProperty = "MessageQuerySet";
|
||||
|
||||
static readonly string[] Properties = new string[] { HandleProperty, CorrelationTypeProperty, MessageQuerySetModelPropertyProperty };
|
||||
|
||||
#region Initialize type properties code
|
||||
public static PropertyDescriptorData[] InitializeTypeProperties()
|
||||
{
|
||||
return new PropertyDescriptorData[]
|
||||
{
|
||||
new PropertyDescriptorData()
|
||||
{
|
||||
PropertyName = HandleProperty,
|
||||
PropertyType = typeof(InArgument),
|
||||
PropertySetter = (instance, newValue) =>
|
||||
{
|
||||
((CorrelationInitializerEntry)instance).SetHandle(newValue);
|
||||
},
|
||||
PropertyGetter = (instance) => (((CorrelationInitializerEntry)instance).GetHandle()),
|
||||
},
|
||||
new PropertyDescriptorData()
|
||||
{
|
||||
PropertyName = CorrelationTypeProperty,
|
||||
PropertyType = typeof(Type),
|
||||
PropertyValidator = (instance, newValue, errors) => (((CorrelationInitializerEntry)instance).ValidateCorrelationType(newValue, errors)),
|
||||
PropertySetter = (instance, newValue) =>
|
||||
{
|
||||
((CorrelationInitializerEntry)instance).SetCorrelationType(newValue);
|
||||
},
|
||||
PropertyGetter = (instance) => (((CorrelationInitializerEntry)instance).GetCorrelationType()),
|
||||
},
|
||||
new PropertyDescriptorData()
|
||||
{
|
||||
PropertyName = MessageQuerySetModelPropertyProperty,
|
||||
PropertyType = typeof(ModelProperty),
|
||||
PropertyGetter = (instance) => (((CorrelationInitializerEntry)instance).GetMessageQuerySetModelProperty()),
|
||||
},
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public CorrelationInitializerEntry()
|
||||
{
|
||||
throw FxTrace.Exception.AsError(new NotSupportedException());
|
||||
}
|
||||
|
||||
public CorrelationInitializerEntry(ModelItem initializer) : base(initializer)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string AutomationId
|
||||
{
|
||||
get { return ((ModelItemCollection)this.ReflectedObject.Parent).IndexOf(this.ReflectedObject).ToString(CultureInfo.InvariantCulture); }
|
||||
}
|
||||
|
||||
internal object GetHandle()
|
||||
{
|
||||
return this.ReflectedObject.Properties[HandleProperty].ComputedValue;
|
||||
}
|
||||
|
||||
void SetHandle(object value)
|
||||
{
|
||||
InArgument handle = (InArgument)(value is ModelItem ? ((ModelItem)value).GetCurrentValue() : value);
|
||||
this.ReflectedObject.Properties[HandleProperty].SetValue(handle);
|
||||
}
|
||||
|
||||
internal Type GetCorrelationType()
|
||||
{
|
||||
return this.ReflectedObject.ItemType;
|
||||
}
|
||||
|
||||
void SetCorrelationType(object value)
|
||||
{
|
||||
Type type = (Type)(value is ModelItem ? ((ModelItem)value).GetCurrentValue() : value);
|
||||
var source = (ModelItemCollection)this.ReflectedObject.Parent;
|
||||
int index = source.IndexOf(this.ReflectedObject);
|
||||
var oldInitalizer = (CorrelationInitializer)this.ReflectedObject.GetCurrentValue();
|
||||
var newInitializer = (CorrelationInitializer)Activator.CreateInstance(type);
|
||||
newInitializer.CorrelationHandle = oldInitalizer.CorrelationHandle;
|
||||
this.Dispose();
|
||||
source.RemoveAt(index);
|
||||
this.Initialize(source.Insert(index, newInitializer));
|
||||
this.RaisePropertyChangedEvent(MessageQuerySetModelPropertyProperty);
|
||||
}
|
||||
|
||||
bool ValidateCorrelationType(object value, List<string> errors)
|
||||
{
|
||||
Type type = (Type)(value is ModelItem ? ((ModelItem)value).GetCurrentValue() : value);
|
||||
var activity = this.ReflectedObject.Parent.Parent;
|
||||
if (typeof(QueryCorrelationInitializer).IsAssignableFrom(type) && !CorrelationInitializerDesigner.CanUseQueryCorrelationInitializer(activity))
|
||||
{
|
||||
errors.Add(System.Activities.Core.Presentation.SR.CorrelationInitializerNotSupported);
|
||||
}
|
||||
return 0 == errors.Count;
|
||||
}
|
||||
|
||||
internal ModelProperty GetMessageQuerySetModelProperty()
|
||||
{
|
||||
return this.ReflectedObject.Properties[MessageQuerySetModelPropertyProperty];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System.Activities.Core.Presentation.Themes;
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Presentation.Converters;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Activities.Presentation.PropertyEditing;
|
||||
using System.Activities.Presentation.View;
|
||||
using System.Runtime;
|
||||
using System.Windows;
|
||||
|
||||
sealed class CorrelationInitializerValueEditor : DialogPropertyValueEditor
|
||||
{
|
||||
public CorrelationInitializerValueEditor()
|
||||
{
|
||||
this.InlineEditorTemplate = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("CorrelationInitializer_InlineTemplate");
|
||||
}
|
||||
|
||||
public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
|
||||
{
|
||||
ModelPropertyEntryToOwnerActivityConverter propertyEntryConverter = new ModelPropertyEntryToOwnerActivityConverter();
|
||||
|
||||
ModelItem modelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null);
|
||||
EditingContext context = modelItem.GetEditingContext();
|
||||
|
||||
this.ShowDialog(modelItem, context);
|
||||
}
|
||||
|
||||
public void ShowDialog(ModelItem modelItem, EditingContext context)
|
||||
{
|
||||
Fx.Assert(modelItem != null, "Activity model item shouldn't be null!");
|
||||
Fx.Assert(context != null, "EditingContext shouldn't be null!");
|
||||
|
||||
|
||||
string bookmarkTitle = (string)this.InlineEditorTemplate.Resources["bookmarkTitle"];
|
||||
|
||||
UndoEngine undoEngine = context.Services.GetService<UndoEngine>();
|
||||
Fx.Assert(null != undoEngine, "UndoEngine should be available");
|
||||
|
||||
using (ModelEditingScope editingScope = modelItem.BeginEdit(bookmarkTitle, shouldApplyChangesImmediately: true))
|
||||
{
|
||||
if ((new EditorWindow(modelItem, context)).ShowOkCancel())
|
||||
{
|
||||
editingScope.Complete();
|
||||
}
|
||||
else
|
||||
{
|
||||
editingScope.Revert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class EditorWindow : WorkflowElementDialog
|
||||
{
|
||||
public EditorWindow(ModelItem activity, EditingContext context)
|
||||
{
|
||||
this.ModelItem = activity;
|
||||
this.Context = context;
|
||||
this.Owner = activity.View;
|
||||
this.EnableMaximizeButton = false;
|
||||
this.EnableMinimizeButton = false;
|
||||
this.MinWidth = 450;
|
||||
this.MinHeight = 250;
|
||||
this.WindowResizeMode = ResizeMode.CanResize;
|
||||
this.WindowSizeToContent = SizeToContent.Manual;
|
||||
var content = new CorrelationInitializerDesigner() { Activity = activity };
|
||||
this.Title = (string)content.Resources["controlTitle"];
|
||||
this.Content = content;
|
||||
this.HelpKeyword = HelpKeywords.AddCorrelationInitializersDialog;
|
||||
}
|
||||
|
||||
protected override void OnWorkflowElementDialogClosed(bool? dialogResult)
|
||||
{
|
||||
if (dialogResult.HasValue && dialogResult.Value)
|
||||
{
|
||||
((CorrelationInitializerDesigner)this.Content).CleanupObjectMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System;
|
||||
using System.Activities.Presentation.Metadata;
|
||||
using System.ComponentModel;
|
||||
using System.Activities.Presentation;
|
||||
|
||||
partial class CorrelationScopeDesigner
|
||||
{
|
||||
public CorrelationScopeDesigner()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
internal static void RegisterMetadata(AttributeTableBuilder builder)
|
||||
{
|
||||
Type type = typeof(CorrelationScope);
|
||||
builder.AddCustomAttributes(type, new DesignerAttribute(typeof(CorrelationScopeDesigner)));
|
||||
builder.AddCustomAttributes(type, type.GetProperty("Body"), BrowsableAttribute.No);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ServiceModel;
|
||||
using System.Activities.Presentation.Metadata;
|
||||
using System.Activities.Presentation.PropertyEditing;
|
||||
|
||||
sealed class EndpointDesigner
|
||||
{
|
||||
internal static void RegisterMetadata(AttributeTableBuilder builder)
|
||||
{
|
||||
Type endpointType = typeof(Endpoint);
|
||||
|
||||
var browsableAttribute = new BrowsableAttribute(false);
|
||||
builder.AddCustomAttributes(endpointType, endpointType.GetProperty("BehaviorConfigurationName"), browsableAttribute);
|
||||
builder.AddCustomAttributes(endpointType, endpointType.GetProperty("Headers"), browsableAttribute);
|
||||
builder.AddCustomAttributes(endpointType, endpointType.GetProperty("Identity"), browsableAttribute);
|
||||
builder.AddCustomAttributes(endpointType, endpointType.GetProperty("Name"), browsableAttribute);
|
||||
builder.AddCustomAttributes(endpointType, endpointType.GetProperty("ListenUri"), browsableAttribute);
|
||||
builder.AddCustomAttributes(endpointType, endpointType.GetProperty("ServiceContractName"), browsableAttribute);
|
||||
|
||||
builder.AddCustomAttributes(endpointType, endpointType.GetProperty("Binding"),
|
||||
PropertyValueEditor.CreateEditorAttribute(typeof(BindingPropertyValueEditor)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation.Factories
|
||||
{
|
||||
using System.Activities;
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Statements;
|
||||
using System.ServiceModel.Activities;
|
||||
using System.Windows;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.VisualBasic.Activities;
|
||||
using System.Activities.Presentation.View;
|
||||
using System.Activities.Presentation.Services;
|
||||
using System.Activities.Expressions;
|
||||
|
||||
public sealed class ReceiveAndSendReplyFactory : IActivityTemplateFactory
|
||||
{
|
||||
const string correlationHandleNamePrefix = "__handle";
|
||||
static string requiredAssemblyName = typeof(CorrelationHandle).Assembly.GetName().Name;
|
||||
static string requiredNamespace = typeof(CorrelationHandle).Namespace;
|
||||
|
||||
public Activity Create(DependencyObject target)
|
||||
{
|
||||
string correlationHandleName = ActivityDesignerHelper.GenerateUniqueVariableNameForContext(target, correlationHandleNamePrefix);
|
||||
|
||||
Variable<CorrelationHandle> requestReplyCorrelation = new Variable<CorrelationHandle> { Name = correlationHandleName };
|
||||
|
||||
Receive receive = new Receive
|
||||
{
|
||||
OperationName = "Operation1",
|
||||
ServiceContractName = XName.Get("IService", "http://tempuri.org/"),
|
||||
CorrelationInitializers =
|
||||
{
|
||||
new RequestReplyCorrelationInitializer
|
||||
{
|
||||
CorrelationHandle = new VariableValue<CorrelationHandle> { Variable = requestReplyCorrelation }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Sequence sequence = new Sequence()
|
||||
{
|
||||
Variables = { requestReplyCorrelation },
|
||||
Activities =
|
||||
{
|
||||
receive,
|
||||
new SendReply
|
||||
{
|
||||
DisplayName = "SendReplyToReceive",
|
||||
Request = receive,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
return sequence;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
//------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation.Factories
|
||||
{
|
||||
using System.Activities;
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Statements;
|
||||
using System.ServiceModel.Activities;
|
||||
using System.Windows;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.VisualBasic.Activities;
|
||||
using System.Activities.Presentation.View;
|
||||
using System.Activities.Presentation.Services;
|
||||
using System.Activities.Expressions;
|
||||
|
||||
public sealed class SendAndReceiveReplyFactory : IActivityTemplateFactory
|
||||
{
|
||||
const string correlationHandleNamePrefix = "__handle";
|
||||
static string requiredAssemblyName = typeof(CorrelationHandle).Assembly.GetName().Name;
|
||||
static string requiredNamespace = typeof(CorrelationHandle).Namespace;
|
||||
|
||||
public Activity Create(DependencyObject target)
|
||||
{
|
||||
string correlationHandleName = ActivityDesignerHelper.GenerateUniqueVariableNameForContext(target, correlationHandleNamePrefix);
|
||||
|
||||
Variable<CorrelationHandle> requestReplyCorrelation = new Variable<CorrelationHandle> { Name = correlationHandleName };
|
||||
|
||||
Send send = new Send
|
||||
{
|
||||
OperationName = "Operation1",
|
||||
ServiceContractName = XName.Get("IService", "http://tempuri.org/"),
|
||||
CorrelationInitializers =
|
||||
{
|
||||
new RequestReplyCorrelationInitializer
|
||||
{
|
||||
CorrelationHandle = new VariableValue<CorrelationHandle> { Variable = requestReplyCorrelation }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Sequence sequence = new Sequence()
|
||||
{
|
||||
Variables = { requestReplyCorrelation },
|
||||
Activities =
|
||||
{
|
||||
send,
|
||||
new ReceiveReply
|
||||
{
|
||||
DisplayName = "ReceiveReplyForSend",
|
||||
Request = send,
|
||||
},
|
||||
}
|
||||
};
|
||||
return sequence;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
//----------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.Activities.Presentation
|
||||
{
|
||||
using System;
|
||||
using System.Activities.Core.Presentation.Themes;
|
||||
using System.Activities.Presentation;
|
||||
using System.Activities.Presentation.Metadata;
|
||||
using System.Activities.Presentation.Converters;
|
||||
using System.Activities.Presentation.Model;
|
||||
using System.Activities.Presentation.PropertyEditing;
|
||||
using System.Activities.Presentation.View;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.Windows;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
partial class InitializeCorrelationDesigner
|
||||
{
|
||||
public const string CorrelationPropertyName = "Correlation";
|
||||
public const string CorrelationDataPropertyName = "CorrelationData";
|
||||
|
||||
public InitializeCorrelationDesigner()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline,
|
||||
Justification = "PropertyValueEditors association needs to be done in the static constructor.")]
|
||||
static InitializeCorrelationDesigner()
|
||||
{
|
||||
Type type = typeof(InitializeCorrelation);
|
||||
AttributeTableBuilder builder = new AttributeTableBuilder();
|
||||
|
||||
builder.AddCustomAttributes(type, type.GetProperty("Correlation"),
|
||||
new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingCorrelatesWithHint")));
|
||||
|
||||
builder.AddCustomAttributes(type, type.GetProperty("CorrelationData"),
|
||||
PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationDataValueEditor)),
|
||||
new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingCorrelationDataHint")));
|
||||
|
||||
builder.AddCustomAttributes(type, "CorrelationData", BrowsableAttribute.Yes);
|
||||
MetadataStore.AddAttributeTable(builder.CreateTable());
|
||||
}
|
||||
|
||||
void OnEditCorrelationData(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dlg = new CorrelationDataValueEditor();
|
||||
dlg.ShowDialog(this.ModelItem, this.ModelItem.GetEditingContext());
|
||||
this.UpdateButton();
|
||||
}
|
||||
|
||||
protected override void OnReadOnlyChanged(bool isReadOnly)
|
||||
{
|
||||
this.btnCorrelationData.IsEnabled = !isReadOnly;
|
||||
base.OnReadOnlyChanged(isReadOnly);
|
||||
}
|
||||
|
||||
protected override void OnModelItemChanged(object newItem)
|
||||
{
|
||||
base.OnModelItemChanged(newItem);
|
||||
this.UpdateButton();
|
||||
}
|
||||
|
||||
void UpdateButton()
|
||||
{
|
||||
this.btnCorrelationData.Content =
|
||||
this.ModelItem.Properties[CorrelationDataPropertyName].IsSet ? this.FindResource("viewTitle") : this.FindResource("defineTitle");
|
||||
}
|
||||
|
||||
internal sealed class CorrelationDataValueEditor : DialogPropertyValueEditor
|
||||
{
|
||||
public CorrelationDataValueEditor()
|
||||
{
|
||||
this.InlineEditorTemplate = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("CorrelationDataValueEditor_InlineTemplate");
|
||||
}
|
||||
|
||||
public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
|
||||
{
|
||||
ModelPropertyEntryToOwnerActivityConverter propertyEntryConverter = new ModelPropertyEntryToOwnerActivityConverter();
|
||||
|
||||
ModelItem modelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null);
|
||||
EditingContext context = modelItem.GetEditingContext();
|
||||
|
||||
this.ShowDialog(modelItem, context);
|
||||
}
|
||||
|
||||
public void ShowDialog(ModelItem modelItem, EditingContext context)
|
||||
{
|
||||
Fx.Assert(modelItem != null, "Activity model item shouldn't be null!");
|
||||
Fx.Assert(context != null, "EditingContext shouldn't be null!");
|
||||
|
||||
new EditorWindow(modelItem, modelItem.Properties[CorrelationPropertyName].Value, this.GetCorrelationDataWrapperCollection(modelItem), context).ShowOkCancel();
|
||||
}
|
||||
|
||||
ObservableCollection<CorrelationDataWrapper> GetCorrelationDataWrapperCollection(ModelItem modelItem)
|
||||
{
|
||||
ObservableCollection<CorrelationDataWrapper> wrapperCollection = null;
|
||||
if (modelItem.ItemType == typeof(InitializeCorrelation))
|
||||
{
|
||||
wrapperCollection = new ObservableCollection<CorrelationDataWrapper>();
|
||||
foreach (ModelItem entry in modelItem.Properties[CorrelationDataPropertyName].Dictionary.Properties["ItemsCollection"].Collection)
|
||||
{
|
||||
wrapperCollection.Add(new CorrelationDataWrapper((string)entry.Properties["Key"].ComputedValue, entry.Properties["Value"].Value));
|
||||
}
|
||||
}
|
||||
return wrapperCollection;
|
||||
}
|
||||
|
||||
sealed class EditorWindow : WorkflowElementDialog
|
||||
{
|
||||
public EditorWindow(ModelItem activity, ModelItem correlationHandler, ObservableCollection<CorrelationDataWrapper> correlationData, EditingContext context)
|
||||
{
|
||||
this.ModelItem = activity;
|
||||
this.Context = context;
|
||||
this.Owner = activity.View;
|
||||
this.MinHeight = 250;
|
||||
this.MinWidth = 450;
|
||||
this.EnableMaximizeButton = false;
|
||||
this.EnableMinimizeButton = false;
|
||||
this.WindowResizeMode = ResizeMode.CanResize;
|
||||
this.WindowSizeToContent = SizeToContent.Manual;
|
||||
var content = new CorrelationDataDesigner()
|
||||
{
|
||||
Activity = activity,
|
||||
CorrelationHandle = correlationHandler,
|
||||
CorrelationInitializeData = correlationData
|
||||
};
|
||||
this.Title = (string)content.Resources["controlTitle"];
|
||||
this.Content = content;
|
||||
this.HelpKeyword = HelpKeywords.InitializeCorrelationDialog;
|
||||
}
|
||||
|
||||
protected override void OnWorkflowElementDialogClosed(bool? dialogResult)
|
||||
{
|
||||
if ((dialogResult.HasValue) && (dialogResult.Value))
|
||||
{
|
||||
(this.Content as CorrelationDataDesigner).CommitEdit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user