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
- BinaryConverter.cs
- PixelFormatConverter.cs
- DateTimeConverter2.cs
- dtdvalidator.cs
- DropShadowBitmapEffect.cs
- WinHttpWebProxyFinder.cs
- ProxyWebPartManagerDesigner.cs
- NativeMethodsCLR.cs
- EdmProperty.cs
- SqlNotificationRequest.cs
- XamlFilter.cs
- Clause.cs
- StrokeCollectionDefaultValueFactory.cs
- XamlStream.cs
- PnrpPermission.cs
- Globals.cs
- RuntimeConfigLKG.cs
- EntityContainer.cs
- SequenceRangeCollection.cs
- SendSecurityHeader.cs
- BuildResult.cs
- Size.cs
- XmlDomTextWriter.cs
- WindowsScrollBarBits.cs
- GradientSpreadMethodValidation.cs
- URLString.cs
- PersistenceProviderBehavior.cs
- DataContract.cs
- CookieParameter.cs
- ThrowHelper.cs
- GridViewEditEventArgs.cs
- GradientBrush.cs
- CodeVariableDeclarationStatement.cs
- InputGestureCollection.cs
- IdentityValidationException.cs
- Run.cs
- MeasurementDCInfo.cs
- WpfGeneratedKnownTypes.cs
- XmlAttributeOverrides.cs
- CommonObjectSecurity.cs
- DocumentXPathNavigator.cs
- WindowsListViewGroup.cs
- TableStyle.cs
- Calendar.cs
- EdmConstants.cs
- BinaryMessageEncodingElement.cs
- JsonEnumDataContract.cs
- ConsumerConnectionPoint.cs
- AtomEntry.cs
- OneWayChannelListener.cs
- RelAssertionDirectKeyIdentifierClause.cs
- altserialization.cs
- LinqDataSourceStatusEventArgs.cs
- EventLogEntry.cs
- WSSecurityOneDotZeroSendSecurityHeader.cs
- Timer.cs
- DbParameterCollectionHelper.cs
- RSACryptoServiceProvider.cs
- HtmlWindowCollection.cs
- XmlSchemaAttributeGroup.cs
- SkewTransform.cs
- DbMetaDataCollectionNames.cs
- MonthChangedEventArgs.cs
- BamlResourceContent.cs
- BypassElement.cs
- X509ImageLogo.cs
- ClassicBorderDecorator.cs
- PeerObject.cs
- HorizontalAlignConverter.cs
- EntityDataSourceSelectingEventArgs.cs
- Rotation3DAnimation.cs
- DefaultPropertyAttribute.cs
- LZCodec.cs
- MailMessageEventArgs.cs
- EventMap.cs
- SafePEFileHandle.cs
- XmlSerializerSection.cs
- HGlobalSafeHandle.cs
- XamlPoint3DCollectionSerializer.cs
- AttachedAnnotation.cs
- XmlEnumAttribute.cs
- FlowDocumentFormatter.cs
- TreeViewCancelEvent.cs
- DocumentXmlWriter.cs
- FloaterBaseParagraph.cs
- CodeParameterDeclarationExpression.cs
- IisTraceWebEventProvider.cs
- XmlSchemaValidator.cs
- Unit.cs
- _SSPIWrapper.cs
- SapiRecoInterop.cs
- ToolboxService.cs
- DataPointer.cs
- QuaternionKeyFrameCollection.cs
- BreakRecordTable.cs
- MatrixAnimationUsingPath.cs
- LocalizationComments.cs
- FormParameter.cs
- MultiSelectRootGridEntry.cs
- DataReaderContainer.cs