1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.ServiceModel.Activities.Presentation
8 using System.Activities.Core.Presentation.Themes;
9 using System.Activities.Presentation;
10 using System.Activities.Presentation.Model;
11 using System.Activities.Presentation.Metadata;
12 using System.Activities.Presentation.PropertyEditing;
13 using System.Collections.Generic;
14 using System.ComponentModel;
15 using System.Diagnostics.CodeAnalysis;
18 using System.Windows.Input;
19 using System.Activities;
21 partial class SendReplyDesigner
23 const string CorrelationsCategoryLabelKey = "correlationsCategoryLabel";
24 const string EndpointCategoryLabelKey = "endpointCategoryLabel";
25 const string MiscellaneousCategoryLabelKey = "miscellaneousCategoryLabel";
26 const string AdvancedCategoryLabelKey = "advancedCategoryLabel";
27 static string Message;
29 static string DeclaredMessageType;
31 [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline,
32 Justification = "PropertyValueEditors association needs to be done in the static constructor.")]
33 static SendReplyDesigner()
35 AttributeTableBuilder builder = new AttributeTableBuilder();
36 Type sendType = typeof(SendReply);
38 builder.AddCustomAttributes(sendType, sendType.GetProperty("CorrelationInitializers"), PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor)));
40 var categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(CorrelationsCategoryLabelKey));
42 builder.AddCustomAttributes(sendType, sendType.GetProperty("CorrelationInitializers"), categoryAttribute, BrowsableAttribute.Yes,
43 PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor)));
45 categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(MiscellaneousCategoryLabelKey));
47 builder.AddCustomAttributes(sendType, sendType.GetProperty("DisplayName"), categoryAttribute);
48 var descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingValueHint", "<Value to bind>"));
49 builder.AddCustomAttributes(sendType, sendType.GetProperty("Content"), categoryAttribute, descriptionAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(SendContentPropertyEditor)));
50 builder.AddCustomAttributes(sendType, sendType.GetProperty("Request"),
52 PropertyValueEditor.CreateEditorAttribute(typeof(ActivityXRefPropertyEditor)));
54 var advancedAttribute = new EditorBrowsableAttribute(EditorBrowsableState.Advanced);
55 builder.AddCustomAttributes(sendType, sendType.GetProperty("Action"), categoryAttribute, advancedAttribute);
57 Action = sendType.GetProperty("Action").Name;
59 Type sendMessageContentType = typeof(SendMessageContent);
60 Message = sendMessageContentType.GetProperty("Message").Name;
61 DeclaredMessageType = sendMessageContentType.GetProperty("DeclaredMessageType").Name;
63 MetadataStore.AddAttributeTable(builder.CreateTable());
65 Func<Activity, IEnumerable<ArgumentAccessor>> argumentAccessorGenerator = (activity) => new ArgumentAccessor[]
69 Getter = (ownerActivity) =>
71 SendReply sendReply = (SendReply)ownerActivity;
72 SendMessageContent content = sendReply.Content as SendMessageContent;
73 return content != null ? content.Message : null;
75 Setter = (ownerActivity, arg) =>
77 SendReply sendReply = (SendReply)ownerActivity;
78 SendMessageContent content = sendReply.Content as SendMessageContent;
81 content.Message = arg as InArgument;
86 ActivityArgumentHelper.RegisterAccessorsGenerator(sendType, argumentAccessorGenerator);
89 public SendReplyDesigner()
91 InitializeComponent();
94 protected override void OnModelItemChanged(object newItem)
96 base.OnModelItemChanged(newItem);
97 if (null != this.ModelItem)
99 this.ModelItem.PropertyChanged += OnModelItemPropertyChanged;
103 void OnModelItemPropertyChanged(object sender, PropertyChangedEventArgs e)
105 if (string.Equals(e.PropertyName, Message))
107 SendMessageContent messageContent = ((SendReply)this.ModelItem.GetCurrentValue()).Content as SendMessageContent;
108 this.ModelItem.Properties[DeclaredMessageType].SetValue(null == messageContent ? null : messageContent.Message.ArgumentType);
112 void OnDefineButtonClicked(object sender, RoutedEventArgs args)
114 using (EditingScope scope = this.Context.Services.GetRequiredService<ModelTreeManager>().CreateEditingScope(StringResourceDictionary.Instance.GetString("editSendContent"), true))
116 if (SendContentDialog.ShowDialog(this.ModelItem, this.Context, this))