Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Core.Presentation / System / ServiceModel / Activities / Presentation / ReceiveDesigner.xaml.cs / 1305376 / ReceiveDesigner.xaml.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.ServiceModel.Activities.Presentation { using Microsoft.VisualBasic.Activities; using System; using System.Activities; using System.Activities.Statements; using System.Activities.Core.Presentation.Themes; using System.Activities.Core.Presentation; using System.Activities.Presentation; using System.Activities.Presentation.Metadata; using System.Activities.Presentation.Model; using System.Activities.Presentation.View; using System.Activities.Presentation.PropertyEditing; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Reflection; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Runtime; using System.Activities.Presentation.Services; partial class ReceiveDesigner { const string CorrelationsCategoryLabelKey = "correlationsCategoryLabel"; const string MiscellaneousCategoryLabelKey = "miscellaneousCategoryLabel"; const string AdvancedCategoryLabelKey = "advancedCategoryLabel"; static string CorrelationHandleTypeNamespace = typeof(CorrelationHandle).Namespace; static string Message; static string Action; static string DeclaredMessageType; public static readonly RoutedCommand CreateSendReplyCommand = new RoutedCommand("CreateSendReply", typeof(ReceiveDesigner)); [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline, Justification = "PropertyValueEditors association needs to be done in the static constructor.")] static ReceiveDesigner() { AttributeTableBuilder builder = new AttributeTableBuilder(); Type receiveType = typeof(Receive); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelationInitializers"), PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor))); var categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(CorrelationsCategoryLabelKey)); var descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingCorrelatesWithHint", "")); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelatesWith"), categoryAttribute, descriptionAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelatesOn"), categoryAttribute, BrowsableAttribute.Yes, PropertyValueEditor.CreateEditorAttribute(typeof(CorrelatesOnValueEditor))); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CorrelationInitializers"), categoryAttribute, BrowsableAttribute.Yes, PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor))); categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(MiscellaneousCategoryLabelKey)); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("DisplayName"), categoryAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("OperationName"), categoryAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("ServiceContractName"), categoryAttribute, new TypeConverterAttribute(typeof(XNameConverter))); descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingValueHint", " ")); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Content"), categoryAttribute, descriptionAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(ReceiveContentPropertyEditor))); var advancedAttribute = new EditorBrowsableAttribute(EditorBrowsableState.Advanced); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("Action"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes( receiveType, "KnownTypes", advancedAttribute, categoryAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(TypeCollectionPropertyEditor)), new EditorOptionsAttribute { Name = TypeCollectionPropertyEditor.AllowDuplicate, Value = false }); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("ProtectionLevel"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("SerializerOption"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes(receiveType, receiveType.GetProperty("CanCreateInstance"), advancedAttribute, categoryAttribute); Action = receiveType.GetProperty("Action").Name; Type receiveMessageContentType = typeof(ReceiveMessageContent); Message = receiveMessageContentType.GetProperty("Message").Name; DeclaredMessageType = receiveMessageContentType.GetProperty("DeclaredMessageType").Name; MetadataStore.AddAttributeTable(builder.CreateTable()); ArgumentFixer.RegisterArgumentFixer( new ActivityArgumentFixer ( (receive, isLocation) => { if (!isLocation) { return null; } ReceiveMessageContent content = receive.Content as ReceiveMessageContent; return content != null ? content.Message : null; }, (receive, argument) => { Fx.Assert(argument is OutArgument, "Only OutArgument could be passed to here"); ReceiveMessageContent content = receive.Content as ReceiveMessageContent; if (content != null) { content.Message = (OutArgument)argument; } } ) ); } public ReceiveDesigner() { InitializeComponent(); } protected override void OnModelItemChanged(object newItem) { base.OnModelItemChanged(newItem); if (null != this.ModelItem) { this.ModelItem.PropertyChanged += OnModelItemPropertyChanged; } } void OnModelItemPropertyChanged(object sender, PropertyChangedEventArgs e) { if (string.Equals(e.PropertyName, Message)) { ReceiveMessageContent messageContent = ((Receive)this.ModelItem.GetCurrentValue()).Content as ReceiveMessageContent; this.ModelItem.Properties[DeclaredMessageType].SetValue(null == messageContent ? null : messageContent.Message.ArgumentType); } } protected override void OnReadOnlyChanged(bool isReadOnly) { this.txtOperationName.IsReadOnly = isReadOnly; } void OnCreateSendReplyExecute(object sender, ExecutedRoutedEventArgs e) { ModelItem container; ModelItem flowStepContainer; using (ModelEditingScope scope = this.ModelItem.BeginEdit((string)this.FindResource("createSendReplyDescription"))) { //special case handling for Sequence if (this.ModelItem.IsItemInSequence(out container)) { //get activities collection ModelItemCollection activities = container.Properties["Activities"].Collection; //get index of Send within collection and increment by one int index = activities.IndexOf(this.ModelItem) + 1; //insert created reply just after the Receive activities.Insert(index, ReceiveDesigner.CreateSendReply(container, this.ModelItem)); } //special case handling for Flowchart else if (this.ModelItem.IsItemInFlowchart(out container, out flowStepContainer)) { Activity replyActivity = ReceiveDesigner.CreateSendReply(container, this.ModelItem); FlowchartDesigner.DropActivityBelow(this.ViewStateService, this.ModelItem, replyActivity, 30); } else { ErrorReporting.ShowAlertMessage(string.Format(CultureInfo.CurrentUICulture, System.Activities.Core.Presentation.SR.CannotPasteSendReplyOrReceiveReply, typeof(SendReply).Name)); } scope.Complete(); } //always copy reply to clipboard Func callback = CreateSendReply; CutCopyPasteHelper.PutCallbackOnClipBoard(callback, typeof(SendReply), this.ModelItem); e.Handled = true; } static SendReply CreateSendReply(ModelItem target, object context) { SendReply reply = null; ModelItem receive = (ModelItem)context; if (null != receive) { Receive receiveInstance = (Receive)receive.GetCurrentValue(); string name = null; //if no correlation is set - create one if (null == receiveInstance.CorrelatesWith) { Variable handleVariable = null; //first, look for nearest variable scope ModelItemCollection variableScope = VariableHelper.FindRootVariableScope(receive).GetVariableCollection(); if (null != variableScope) { ModelItemCollection correlations = receive.Properties["CorrelationInitializers"].Collection; bool hasRequestReplyHandle = false; foreach (ModelItem item in correlations) { if (item.ItemType.IsAssignableFrom(typeof(RequestReplyCorrelationInitializer))) { hasRequestReplyHandle = true; break; } } if (!hasRequestReplyHandle) { //create unique variable name name = variableScope.CreateUniqueVariableName("__handle", 1); //create variable handleVariable = Variable.Create(name, typeof(CorrelationHandle), VariableModifiers.None); //add it to the scope variableScope.Add(handleVariable); //setup correlation ImportDesigner.AddImport(CorrelationHandleTypeNamespace, receive.GetEditingContext()); VisualBasicValue expression = new VisualBasicValue { ExpressionText = name }; InArgument handle = new InArgument (expression); correlations.Add(new RequestReplyCorrelationInitializer { CorrelationHandle = handle }); } } } reply = new SendReply() { DisplayName = string.Format(CultureInfo.CurrentUICulture, "SendReplyTo{0}", receive.Properties["DisplayName"].ComputedValue), Request = (Receive)receive.GetCurrentValue(), }; } else { MessageBox.Show( (string)StringResourceDictionary.Instance["receiveActivityCreateReplyErrorLabel"] ?? "Source 'Reply' element not found!", (string)StringResourceDictionary.Instance["MessagingActivityTitle"] ?? "Send", MessageBoxButton.OK, MessageBoxImage.Error); } return reply; } void OnDefineButtonClicked(object sender, RoutedEventArgs args) { UndoEngine.Bookmark bookmark = this.Context.Services.GetService ().CreateBookmark(StringResourceDictionary.Instance.GetString("editReceiveContent")); if (ReceiveContentDialog.ShowDialog(this.ModelItem, this.Context, this)) { bookmark.CommitBookmark(); } else { bookmark.RollbackBookmark(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TcpChannelFactory.cs
- HttpListenerContext.cs
- SemaphoreSecurity.cs
- ModelUIElement3D.cs
- XmlSignificantWhitespace.cs
- ClientSession.cs
- PropertyIDSet.cs
- LayoutManager.cs
- graph.cs
- CompatibleIComparer.cs
- SystemMulticastIPAddressInformation.cs
- ToolStripGripRenderEventArgs.cs
- TemplatedMailWebEventProvider.cs
- UnmanagedHandle.cs
- Hash.cs
- SplitterPanel.cs
- PropertyPathWorker.cs
- IListConverters.cs
- StrokeNodeEnumerator.cs
- TableAutomationPeer.cs
- UserControlParser.cs
- DelimitedListTraceListener.cs
- RegexRunner.cs
- ExpressionBindingCollection.cs
- WebFormDesignerActionService.cs
- DataBinder.cs
- SymDocumentType.cs
- ScalarOps.cs
- XmlSchemaInferenceException.cs
- SqlDependencyListener.cs
- SerializationFieldInfo.cs
- HashStream.cs
- IfElseDesigner.xaml.cs
- ByteKeyFrameCollection.cs
- ImageListImageEditor.cs
- CurrencyWrapper.cs
- DefaultValueAttribute.cs
- RowToFieldTransformer.cs
- TextBoxBase.cs
- AppliedDeviceFiltersEditor.cs
- HttpHeaderCollection.cs
- SqlRowUpdatedEvent.cs
- SamlSubject.cs
- PagerSettings.cs
- NavigationHelper.cs
- WebPartConnectionsConnectVerb.cs
- SqlProfileProvider.cs
- PersianCalendar.cs
- TreeNodeStyle.cs
- HtmlFormWrapper.cs
- counter.cs
- XmlSerializer.cs
- MetadataItemCollectionFactory.cs
- RequestCache.cs
- TaiwanCalendar.cs
- Utils.cs
- StringUtil.cs
- XmlDocumentType.cs
- ButtonFlatAdapter.cs
- WindowVisualStateTracker.cs
- XmlValueConverter.cs
- DebugView.cs
- PTProvider.cs
- SelectionUIHandler.cs
- DiagnosticStrings.cs
- ControlUtil.cs
- StrongNameKeyPair.cs
- WebPartManagerInternals.cs
- DataGridViewRowPrePaintEventArgs.cs
- AnnotationAdorner.cs
- MessageBodyMemberAttribute.cs
- ToolStripComboBox.cs
- UITypeEditors.cs
- FixedBufferAttribute.cs
- Internal.cs
- Label.cs
- CodePropertyReferenceExpression.cs
- RecognizedPhrase.cs
- RefreshEventArgs.cs
- ActiveXSite.cs
- ScrollItemPatternIdentifiers.cs
- CacheDependency.cs
- EmissiveMaterial.cs
- CorrelationRequestContext.cs
- Menu.cs
- SqlCacheDependencySection.cs
- Events.cs
- _CommandStream.cs
- ByteStream.cs
- Material.cs
- Transform3D.cs
- ListBindingHelper.cs
- TemplateBuilder.cs
- ComboBoxAutomationPeer.cs
- LabelLiteral.cs
- ITreeGenerator.cs
- PathBox.cs
- SR.Designer.cs
- smtpconnection.cs
- DataServiceEntityAttribute.cs