Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.WorkflowServices / System / Workflow / Activities / ChannelToken.cs / 1305376 / ChannelToken.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Workflow.Activities { using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Diagnostics.CodeAnalysis; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Design; using System.Workflow.ComponentModel.Serialization; using System.Xml; [DesignerSerializer(typeof(DependencyObjectCodeDomSerializer), typeof(CodeDomSerializer))] [TypeConverter(typeof(ChannelTokenTypeConverter))] public sealed class ChannelToken : DependencyObject, IPropertyValueProvider { [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] internal static readonly DependencyProperty EndpointNameProperty = DependencyProperty.Register("EndpointName", typeof(string), typeof(ChannelToken), new PropertyMetadata(null)); [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] internal static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(ChannelToken), new PropertyMetadata(null, DependencyPropertyOptions.Metadata, new Attribute[] { new BrowsableAttribute(false) })); [SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] internal static readonly DependencyProperty OwnerActivityNameProperty = DependencyProperty.Register("OwnerActivityName", typeof(string), typeof(ChannelToken), new PropertyMetadata(null, DependencyPropertyOptions.Metadata, new Attribute[] { new TypeConverterAttribute(typeof(PropertyValueProviderTypeConverter)) })); public ChannelToken() { } internal ChannelToken(string name) { this.Name = name; } [DefaultValue(null)] [SR2Description(SR2DescriptionAttribute.ChannelToken_EndpointName_Description)] public string EndpointName { get { return (string) GetValue(EndpointNameProperty); } set { SetValue(EndpointNameProperty, value); } } [Browsable(false)] [DefaultValue(null)] [SR2Description(SR2DescriptionAttribute.ChannelToken_Name_Description)] public string Name { get { return (string) GetValue(NameProperty); } set { SetValue(NameProperty, value); } } [DefaultValue(null)] [TypeConverter(typeof(PropertyValueProviderTypeConverter))] [SR2Description(SR2DescriptionAttribute.ChannelToken_OwnerActivityName_Description)] public string OwnerActivityName { get { return (string) GetValue(OwnerActivityNameProperty); } set { SetValue(OwnerActivityNameProperty, value); } } ICollection IPropertyValueProvider.GetPropertyValues(ITypeDescriptorContext context) { StringCollection names = new StringCollection(); if (string.Equals(context.PropertyDescriptor.Name, "OwnerActivityName", StringComparison.Ordinal)) { ISelectionService selectionService = context.GetService(typeof(ISelectionService)) as ISelectionService; if (selectionService != null && selectionService.SelectionCount == 1 && selectionService.PrimarySelection is Activity) { // add empty string as an option // names.Add(string.Empty); Activity currentActivity = selectionService.PrimarySelection as Activity; foreach (Activity activity in GetEnclosingCompositeActivities(currentActivity)) { string activityId = activity.QualifiedName; if (!names.Contains(activityId)) { names.Add(activityId); } } } } return names; } internal static LogicalChannel GetLogicalChannel(Activity activity, ChannelToken endpoint, Type contractType) { if (activity == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activity"); } if (endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpoint"); } if (contractType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractType"); } return GetLogicalChannel(activity, endpoint.Name, endpoint.OwnerActivityName, contractType); } internal static LogicalChannel GetLogicalChannel(Activity activity, string name, string ownerActivityName, Type contractType) { if (activity == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activity"); } if (string.IsNullOrEmpty(name)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("name", SR2.GetString(SR2.Error_ArgumentValueNullOrEmptyString)); } if (contractType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractType"); } Activity contextActivity = activity.ContextActivity; Activity owner = null; if (contextActivity == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing))); } if (string.IsNullOrEmpty(ownerActivityName)) { owner = contextActivity.RootActivity; } else { while (contextActivity != null) { owner = contextActivity.GetActivityByName(ownerActivityName, true); if (owner != null) { break; } contextActivity = contextActivity.Parent; if (contextActivity != null) { contextActivity = contextActivity.ContextActivity; } } } if (owner == null && !string.IsNullOrEmpty(ownerActivityName)) { owner = Helpers.ParseActivityForBind(activity, ownerActivityName); } if (owner == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException(SR2.GetString(SR2.Error_ContextOwnerActivityMissing))); } LogicalChannel logicalChannel = null; LogicalChannelCollection collection = owner.GetValue(LogicalChannelCollection.LogicalChannelCollectionProperty) as LogicalChannelCollection; if (collection == null) { collection = new LogicalChannelCollection(); owner.SetValue(LogicalChannelCollection.LogicalChannelCollectionProperty, collection); logicalChannel = new LogicalChannel(name, contractType); collection.Add(logicalChannel); } else if (!collection.Contains(name)) { logicalChannel = new LogicalChannel(name, contractType); collection.Add(logicalChannel); } else { logicalChannel = collection[name]; } if (logicalChannel.ContractType != contractType) { logicalChannel = null; } return logicalChannel; } internal static LogicalChannel Register(Activity activity, ChannelToken endpoint, Type contractType) { if (activity == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("activity"); } if (endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpoint"); } if (contractType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractType"); } LogicalChannel logicalChannel = GetLogicalChannel(activity, endpoint, contractType); if (logicalChannel == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InvalidOperationException(SR2.GetString(SR2.Error_FailedToRegisterChannel, endpoint.Name))); } return logicalChannel; } private static IEnumerable GetEnclosingCompositeActivities(Activity startActivity) { Activity currentActivity = null; StackactivityStack = new Stack (); activityStack.Push(startActivity); while ((currentActivity = activityStack.Pop()) != null) { if (currentActivity.Enabled) { yield return currentActivity; } activityStack.Push(currentActivity.Parent); } yield break; } } } // 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
- GroupBoxRenderer.cs
- WebPartDisplayModeCancelEventArgs.cs
- Rect3D.cs
- KeyInstance.cs
- DBSchemaTable.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- ObjectItemConventionAssemblyLoader.cs
- CodePropertyReferenceExpression.cs
- RequestValidator.cs
- SqlProvider.cs
- ObjectRef.cs
- FrameworkTextComposition.cs
- AdvancedBindingEditor.cs
- DataGridViewCellContextMenuStripNeededEventArgs.cs
- WebPartConnection.cs
- FindCriteria11.cs
- UserControlBuildProvider.cs
- CompositionAdorner.cs
- BaseCollection.cs
- ObjRef.cs
- ResolveRequestResponseAsyncResult.cs
- BrushValueSerializer.cs
- GenerateHelper.cs
- StorageConditionPropertyMapping.cs
- SafeViewOfFileHandle.cs
- FragmentNavigationEventArgs.cs
- MetadataCacheItem.cs
- HtmlHistory.cs
- TraceSource.cs
- ControlCollection.cs
- InputLangChangeEvent.cs
- DataGridViewButtonColumn.cs
- RotateTransform3D.cs
- DefaultBinder.cs
- ContentElementAutomationPeer.cs
- ConnectionStringsExpressionBuilder.cs
- Button.cs
- LongTypeConverter.cs
- cookiecollection.cs
- DispatcherExceptionEventArgs.cs
- DockPattern.cs
- FixedDSBuilder.cs
- TraceProvider.cs
- CacheChildrenQuery.cs
- StrokeCollection2.cs
- TreeViewItemAutomationPeer.cs
- X509IssuerSerialKeyIdentifierClause.cs
- Annotation.cs
- Expander.cs
- DataServiceEntityAttribute.cs
- HwndTarget.cs
- SelectingProviderEventArgs.cs
- HostingEnvironment.cs
- PrimitiveDataContract.cs
- DesignTimeTemplateParser.cs
- PersistenceMetadataNamespace.cs
- UIElementPropertyUndoUnit.cs
- ActiveXHelper.cs
- GroupQuery.cs
- Throw.cs
- SqlMethods.cs
- DataGridViewSelectedRowCollection.cs
- XmlDataSourceView.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- TitleStyle.cs
- OracleConnectionFactory.cs
- XmlQueryStaticData.cs
- SoapTypeAttribute.cs
- GridViewDeleteEventArgs.cs
- XmlSchemaAnyAttribute.cs
- Rijndael.cs
- ExpressionEditorAttribute.cs
- DataViewManager.cs
- ControlParameter.cs
- TemplateGroupCollection.cs
- WebPartConnectionsEventArgs.cs
- XPathDocumentBuilder.cs
- Vector3DAnimationUsingKeyFrames.cs
- AssertUtility.cs
- X509Certificate2.cs
- RtfToken.cs
- objectresult_tresulttype.cs
- MetadataArtifactLoaderResource.cs
- TextDpi.cs
- PieceDirectory.cs
- WindowsGraphics.cs
- RequestQueue.cs
- PenThreadWorker.cs
- SchemaRegistration.cs
- TcpChannelHelper.cs
- MDIControlStrip.cs
- Repeater.cs
- TextElementEnumerator.cs
- FunctionMappingTranslator.cs
- SiteMapSection.cs
- GridViewRowPresenterBase.cs
- PersonalizationProviderHelper.cs
- TdsValueSetter.cs
- TemplateComponentConnector.cs
- PkcsUtils.cs