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
- StatusBarDrawItemEvent.cs
- HttpCookieCollection.cs
- GridViewRowEventArgs.cs
- ProvideValueServiceProvider.cs
- ItemContainerPattern.cs
- XmlSerializableReader.cs
- FixedSOMGroup.cs
- SoapReflectionImporter.cs
- TypeUtils.cs
- BitmapMetadataBlob.cs
- Point3DAnimationUsingKeyFrames.cs
- ListItem.cs
- FindRequestContext.cs
- dtdvalidator.cs
- CodeDOMUtility.cs
- HttpWrapper.cs
- WebPermission.cs
- DispatcherSynchronizationContext.cs
- PartialCachingControl.cs
- DesignerAttribute.cs
- DateTimeParse.cs
- RSAOAEPKeyExchangeFormatter.cs
- ComplexTypeEmitter.cs
- ConfigXmlReader.cs
- ISO2022Encoding.cs
- SqlTrackingQuery.cs
- ConstructorNeedsTagAttribute.cs
- Gdiplus.cs
- CookieHandler.cs
- SerializableAttribute.cs
- TextDecorationCollectionConverter.cs
- MembershipValidatePasswordEventArgs.cs
- precedingquery.cs
- SpellCheck.cs
- ClientBuildManagerCallback.cs
- SourceItem.cs
- DocumentStatusResources.cs
- ContentPosition.cs
- WindowsListViewGroup.cs
- SkewTransform.cs
- SplitContainer.cs
- CacheSection.cs
- SharedDp.cs
- TextEditorDragDrop.cs
- Panel.cs
- XXXInfos.cs
- RemotingAttributes.cs
- TextLineBreak.cs
- WrapperEqualityComparer.cs
- FaultDesigner.cs
- CheckBoxList.cs
- TreeNode.cs
- EncoderFallback.cs
- SiteMembershipCondition.cs
- StickyNote.cs
- TraceContext.cs
- CompatibleIComparer.cs
- ObjRef.cs
- ColumnReorderedEventArgs.cs
- SingleTagSectionHandler.cs
- COM2TypeInfoProcessor.cs
- PasswordBox.cs
- CancellableEnumerable.cs
- Pair.cs
- SqlGenerator.cs
- XsdBuilder.cs
- URLEditor.cs
- ListViewGroupConverter.cs
- ClaimTypeRequirement.cs
- SizeFConverter.cs
- RawStylusInput.cs
- ConstraintCollection.cs
- TreeViewImageIndexConverter.cs
- QuerySettings.cs
- XsdCachingReader.cs
- TypeConverterHelper.cs
- GridViewColumnHeader.cs
- OracleBFile.cs
- ProcessThreadCollection.cs
- DataGridViewDataConnection.cs
- TextParagraphView.cs
- ProjectionCamera.cs
- EventMappingSettings.cs
- HotCommands.cs
- DataGrid.cs
- HybridDictionary.cs
- ToggleButton.cs
- Thumb.cs
- HttpResponse.cs
- StateChangeEvent.cs
- XmlSchemaFacet.cs
- IntSecurity.cs
- TypeUtils.cs
- FrameworkContentElement.cs
- URLMembershipCondition.cs
- Setter.cs
- CheckBoxField.cs
- AsymmetricSignatureDeformatter.cs
- DeviceFilterDictionary.cs
- AsyncCompletedEventArgs.cs