Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Core.Presentation / System / ServiceModel / Activities / Presentation / SendDesigner.xaml.cs / 1305376 / SendDesigner.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.Core.Presentation; using System.Activities.Core.Presentation.Themes; using System.Activities.Presentation; using System.Activities.Presentation.Metadata; using System.Activities.Presentation.Model; using System.Activities.Presentation.PropertyEditing; using System.Activities.Presentation.View; using System.Activities.Statements; 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 SendDesigner { const string CorrelationsCategoryLabelKey = "correlationsCategoryLabel"; const string EndpointCategoryLabelKey = "endpointCategoryLabel"; 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 CreateReceiveReplyCommand = new RoutedCommand("CreateReceiveReply", typeof(SendDesigner)); [SuppressMessage(FxCop.Category.Performance, FxCop.Rule.InitializeReferenceTypeStaticFieldsInline, Justification = "PropertyValueEditors association needs to be done in the static constructor.")] static SendDesigner() { AttributeTableBuilder builder = new AttributeTableBuilder(); Type sendType = typeof(Send); builder.AddCustomAttributes(sendType, sendType.GetProperty("CorrelationInitializers"), PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor))); var categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(CorrelationsCategoryLabelKey)); var descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingCorrelatesWithHint", "Correlation handle")); builder.AddCustomAttributes(sendType, sendType.GetProperty("CorrelatesWith"), categoryAttribute, descriptionAttribute); builder.AddCustomAttributes(sendType, sendType.GetProperty("CorrelationInitializers"), categoryAttribute, BrowsableAttribute.Yes, PropertyValueEditor.CreateEditorAttribute(typeof(CorrelationInitializerValueEditor))); categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(EndpointCategoryLabelKey)); builder.AddCustomAttributes(sendType, sendType.GetProperty("Endpoint"), categoryAttribute, new TypeConverterAttribute(typeof(ExpandableObjectConverter))); descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingEndpointAddressHint", "")); builder.AddCustomAttributes(sendType, sendType.GetProperty("EndpointAddress"), categoryAttribute, descriptionAttribute); builder.AddCustomAttributes(sendType, sendType.GetProperty("EndpointConfigurationName"), categoryAttribute); categoryAttribute = new CategoryAttribute(EditorCategoryTemplateDictionary.Instance.GetCategoryTitle(MiscellaneousCategoryLabelKey)); builder.AddCustomAttributes(sendType, sendType.GetProperty("DisplayName"), categoryAttribute); builder.AddCustomAttributes(sendType, sendType.GetProperty("OperationName"), categoryAttribute); builder.AddCustomAttributes(sendType, sendType.GetProperty("ServiceContractName"), categoryAttribute, new TypeConverterAttribute(typeof(XNameConverter))); descriptionAttribute = new DescriptionAttribute(StringResourceDictionary.Instance.GetString("messagingValueHint", "")); builder.AddCustomAttributes(sendType, sendType.GetProperty("Content"), categoryAttribute, descriptionAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(SendContentPropertyEditor))); var advancedAttribute = new EditorBrowsableAttribute(EditorBrowsableState.Advanced); builder.AddCustomAttributes(sendType, sendType.GetProperty("Action"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes( sendType, "KnownTypes", advancedAttribute, categoryAttribute, PropertyValueEditor.CreateEditorAttribute(typeof(TypeCollectionPropertyEditor)), new EditorOptionsAttribute { Name = TypeCollectionPropertyEditor.AllowDuplicate, Value = false }); builder.AddCustomAttributes(sendType, sendType.GetProperty("ProtectionLevel"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes(sendType, sendType.GetProperty("SerializerOption"), advancedAttribute, categoryAttribute); builder.AddCustomAttributes(sendType, sendType.GetProperty("TokenImpersonationLevel"), advancedAttribute, categoryAttribute); Action = sendType.GetProperty("Action").Name; Type sendMessageContentType = typeof(SendMessageContent); Message = sendMessageContentType.GetProperty("Message").Name; DeclaredMessageType = sendMessageContentType.GetProperty("DeclaredMessageType").Name; MetadataStore.AddAttributeTable(builder.CreateTable()); ArgumentFixer.RegisterArgumentFixer( new ActivityArgumentFixer ( (send, isLocation) => { if (isLocation) { return null; } SendMessageContent content = send.Content as SendMessageContent; return content != null ? content.Message : null; }, (send, argument) => { Fx.Assert(argument is InArgument, "Only InArgument could be passed to here"); SendMessageContent content = send.Content as SendMessageContent; if (content != null) { content.Message = (InArgument)argument; } } ) ); } public SendDesigner() { 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)) { SendMessageContent messageContent = ((Send)this.ModelItem.GetCurrentValue()).Content as SendMessageContent; this.ModelItem.Properties[DeclaredMessageType].SetValue(null == messageContent ? null : messageContent.Message.ArgumentType); } } protected override void OnReadOnlyChanged(bool isReadOnly) { this.txtOperationName.IsReadOnly = isReadOnly; } void OnCreateReceiveReplyExecute(object sender, ExecutedRoutedEventArgs e) { ModelItem container; ModelItem flowStepContainer; using (ModelEditingScope scope = this.ModelItem.BeginEdit((string)this.FindResource("createReceiveReplyDescription"))) { //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 Send activities.Insert(index, SendDesigner.CreateReceiveReply(container, this.ModelItem)); } //special case handling for Flowchart else if (this.ModelItem.IsItemInFlowchart(out container, out flowStepContainer)) { Activity replyActivity = SendDesigner.CreateReceiveReply(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(ReceiveReply).Name)); } scope.Complete(); } //always copy reply to clipboard Func callback = CreateReceiveReply; CutCopyPasteHelper.PutCallbackOnClipBoard(callback, typeof(ReceiveReply), this.ModelItem); e.Handled = true; } static ReceiveReply CreateReceiveReply(ModelItem target, object context) { ReceiveReply reply = null; ModelItem send = (ModelItem)context; if (null != send) { Send sendInstance = (Send)send.GetCurrentValue(); string name = null; //if no correlation is set - create one if (null == sendInstance.CorrelatesWith) { Variable handleVariable = null; //first, look for root variable scope ModelItemCollection variableScope = VariableHelper.FindRootVariableScope(send).GetVariableCollection(); if (null != variableScope) { ModelItemCollection correlations = send.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, send.GetEditingContext()); VisualBasicValue expression = new VisualBasicValue { ExpressionText = name }; InArgument handle = new InArgument (expression); correlations.Add(new RequestReplyCorrelationInitializer { CorrelationHandle = handle }); } } } //create receive reply reply = new ReceiveReply() { DisplayName = string.Format(CultureInfo.CurrentUICulture, "ReceiveReplyFor{0}", send.Properties["DisplayName"].ComputedValue), Request = (Send)send.GetCurrentValue(), }; } else { MessageBox.Show( (string)StringResourceDictionary.Instance["sendActivityCreateReplyErrorLabel"] ?? "Source 'Send' 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("editSendContent")); if (SendContentDialog.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
- Preprocessor.cs
- ButtonStandardAdapter.cs
- DateTimeStorage.cs
- WebServiceHost.cs
- DurationConverter.cs
- CodeSubDirectory.cs
- TrackingRecord.cs
- DoubleKeyFrameCollection.cs
- XmlEnumAttribute.cs
- SqlDelegatedTransaction.cs
- EntryIndex.cs
- ObjectListCommand.cs
- RequestQueue.cs
- ToolStripMenuItem.cs
- _NestedSingleAsyncResult.cs
- UnicodeEncoding.cs
- LifetimeServices.cs
- ControlBuilder.cs
- _AutoWebProxyScriptWrapper.cs
- UIElement.cs
- ComplexBindingPropertiesAttribute.cs
- HashCodeCombiner.cs
- ByteConverter.cs
- LinearGradientBrush.cs
- FrameworkElement.cs
- HttpResponse.cs
- IntSecurity.cs
- SessionState.cs
- XmlSchemaSimpleType.cs
- UnsafeCollabNativeMethods.cs
- XomlCompilerParameters.cs
- FormClosingEvent.cs
- EventSetter.cs
- MissingMethodException.cs
- AppSecurityManager.cs
- PrimitiveSchema.cs
- PixelShader.cs
- BitmapEffectGeneralTransform.cs
- MergeFilterQuery.cs
- Column.cs
- TabControl.cs
- SecurityHeaderElementInferenceEngine.cs
- _DigestClient.cs
- _ShellExpression.cs
- SQLStringStorage.cs
- FilteredDataSetHelper.cs
- GenericEnumConverter.cs
- SimpleBitVector32.cs
- ProcessManager.cs
- DbTypeMap.cs
- contentDescriptor.cs
- DropShadowEffect.cs
- PreProcessor.cs
- PointAnimationUsingKeyFrames.cs
- _LocalDataStore.cs
- JoinSymbol.cs
- EventSinkHelperWriter.cs
- Processor.cs
- Range.cs
- RoleGroup.cs
- AnnotationHighlightLayer.cs
- TabletCollection.cs
- AnonymousIdentificationModule.cs
- BrowserTree.cs
- Point3DCollectionValueSerializer.cs
- TextFormatter.cs
- XPathDescendantIterator.cs
- ComponentEditorForm.cs
- WebExceptionStatus.cs
- CommonRemoteMemoryBlock.cs
- DataSetMappper.cs
- BulletDecorator.cs
- SchemaNotation.cs
- QueryAsyncResult.cs
- DesignerAttributeInfo.cs
- BindingGroup.cs
- PersonalizableTypeEntry.cs
- TypedRowHandler.cs
- XamlVector3DCollectionSerializer.cs
- SamlAuthorizationDecisionClaimResource.cs
- RewritingValidator.cs
- CultureTableRecord.cs
- ValuePattern.cs
- DbMetaDataColumnNames.cs
- SingleConverter.cs
- ColorMatrix.cs
- FrameAutomationPeer.cs
- Directory.cs
- DesignerActionList.cs
- InkPresenterAutomationPeer.cs
- NetworkStream.cs
- FileDialogPermission.cs
- CompilerInfo.cs
- RuleInfoComparer.cs
- SqlDataSourceParameterParser.cs
- DrawingServices.cs
- ToolboxService.cs
- XmlCountingReader.cs
- IisTraceListener.cs
- XmlWriterSettings.cs