Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / xsp / System / Web / UI / WebParts / WebPartConnection.cs / 1 / WebPartConnection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls.WebParts { using System; using System.Collections; using System.ComponentModel; using System.Diagnostics; using System.Security.Permissions; [ TypeConverter(typeof(ExpandableObjectConverter)), ParseChildren(true, "Transformers") ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class WebPartConnection { private string _consumerConnectionPointID; private string _consumerID; private bool _deleted; private string _id; private bool _isActive; private bool _isShared; private bool _isStatic; private string _providerConnectionPointID; private string _providerID; private WebPartTransformerCollection _transformers; private WebPartManager _webPartManager; public WebPartConnection() { _isStatic = true; _isShared = true; } // PERF: Consider caching [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public WebPart Consumer { get { string consumerID = ConsumerID; if (consumerID.Length == 0) { throw new InvalidOperationException(SR.GetString(SR.WebPartConnection_ConsumerIDNotSet)); } if (_webPartManager != null) { return _webPartManager.WebParts[consumerID]; } else { return null; } } } // PERF: Consider caching [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public ConsumerConnectionPoint ConsumerConnectionPoint { get { WebPart consumer = Consumer; if (consumer != null && _webPartManager != null) { return _webPartManager.GetConsumerConnectionPoint(consumer, ConsumerConnectionPointID); } else { return null; } } } [ DefaultValue(ConnectionPoint.DefaultIDInternal) ] public string ConsumerConnectionPointID { get { // return (!String.IsNullOrEmpty(_consumerConnectionPointID)) ? _consumerConnectionPointID : ConnectionPoint.DefaultID; } set { _consumerConnectionPointID = value; } } [ DefaultValue("") ] public string ConsumerID { get { return (_consumerID != null) ? _consumerID : String.Empty; } set { _consumerID = value; } } // True if this connection has been disconnected, but can not actually be removed. // Either a static or a shared connection. internal bool Deleted { get { return _deleted; } set { _deleted = value; } } [ DefaultValue("") ] public string ID { get { return (_id != null) ? _id : String.Empty; } set { _id = value; } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public bool IsActive { get { return _isActive; } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public bool IsShared { get { return _isShared; } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public bool IsStatic { get { return _isStatic; } } // PERF: Consider caching [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public WebPart Provider { get { string providerID = ProviderID; if (providerID.Length == 0) { throw new InvalidOperationException(SR.GetString(SR.WebPartConnection_ProviderIDNotSet)); } if (_webPartManager != null) { return _webPartManager.WebParts[providerID]; } else { return null; } } } // PERF: Consider caching [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public ProviderConnectionPoint ProviderConnectionPoint { get { WebPart provider = Provider; if (provider != null && _webPartManager != null) { return _webPartManager.GetProviderConnectionPoint(provider, ProviderConnectionPointID); } else { return null; } } } [ DefaultValue(ConnectionPoint.DefaultIDInternal) ] public string ProviderConnectionPointID { get { // return (!String.IsNullOrEmpty(_providerConnectionPointID)) ? _providerConnectionPointID : ConnectionPoint.DefaultID; } set { _providerConnectionPointID = value; } } [ DefaultValue("") ] public string ProviderID { get { return (_providerID != null) ? _providerID : String.Empty; } set { _providerID = value; } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ] public WebPartTransformer Transformer { get { if (_transformers == null || _transformers.Count == 0) { return null; } else { return _transformers[0]; } } } ///[ Browsable(false), EditorBrowsable(EditorBrowsableState.Never), PersistenceMode(PersistenceMode.InnerDefaultProperty), ] public WebPartTransformerCollection Transformers { get { if (_transformers == null) { _transformers = new WebPartTransformerCollection(); } return _transformers; } } internal void Activate() { // This method should only be called on WebPartConnections in the WebPartManager, so // _webPartManager should never be null. Debug.Assert(_webPartManager != null); Transformers.SetReadOnly(); WebPart providerWebPart = Provider; // Cannot be null because Activate() is only called on valid Connections Debug.Assert(providerWebPart != null); WebPart consumerWebPart = Consumer; // Cannot be null because Activate() is only called on valid Connections Debug.Assert(consumerWebPart != null); Control providerControl = providerWebPart.ToControl(); Control consumerControl = consumerWebPart.ToControl(); ProviderConnectionPoint providerConnectionPoint = ProviderConnectionPoint; // Cannot be null because Activate() is only called on valid Connections Debug.Assert(providerConnectionPoint != null); if (!providerConnectionPoint.GetEnabled(providerControl)) { consumerWebPart.SetConnectErrorMessage(SR.GetString( SR.WebPartConnection_DisabledConnectionPoint, providerConnectionPoint.DisplayName, providerWebPart.DisplayTitle)); return; } ConsumerConnectionPoint consumerConnectionPoint = ConsumerConnectionPoint; // Cannot be null because Activate() is only called on valid Connections Debug.Assert(consumerConnectionPoint != null); if (!consumerConnectionPoint.GetEnabled(consumerControl)) { consumerWebPart.SetConnectErrorMessage(SR.GetString( SR.WebPartConnection_DisabledConnectionPoint, consumerConnectionPoint.DisplayName, consumerWebPart.DisplayTitle)); return; } // Do not activate connections involving closed WebParts if (!providerWebPart.IsClosed && !consumerWebPart.IsClosed) { WebPartTransformer transformer = Transformer; if (transformer == null) { if (providerConnectionPoint.InterfaceType == consumerConnectionPoint.InterfaceType) { ConnectionInterfaceCollection secondaryInterfaces = providerConnectionPoint.GetSecondaryInterfaces(providerControl); if (consumerConnectionPoint.SupportsConnection(consumerControl, secondaryInterfaces)) { object dataObject = providerConnectionPoint.GetObject(providerControl); consumerConnectionPoint.SetObject(consumerControl, dataObject); _isActive = true; } else { consumerWebPart.SetConnectErrorMessage(SR.GetString( SR.WebPartConnection_IncompatibleSecondaryInterfaces, new string[] { consumerConnectionPoint.DisplayName, consumerWebPart.DisplayTitle, providerConnectionPoint.DisplayName, providerWebPart.DisplayTitle})); } } else { consumerWebPart.SetConnectErrorMessage(SR.GetString( SR.WebPartConnection_NoCommonInterface, new string[] { providerConnectionPoint.DisplayName, providerWebPart.DisplayTitle, consumerConnectionPoint.DisplayName, consumerWebPart.DisplayTitle})); } } else { Type transformerType = transformer.GetType(); if (!_webPartManager.AvailableTransformers.Contains(transformerType)) { string errorMessage; if (_webPartManager.Context != null && _webPartManager.Context.IsCustomErrorEnabled) { errorMessage = SR.GetString(SR.WebPartConnection_TransformerNotAvailable); } else { errorMessage = SR.GetString( SR.WebPartConnection_TransformerNotAvailableWithType, transformerType.FullName); } consumerWebPart.SetConnectErrorMessage(errorMessage); // } // Check matching interfaces on connection points and transformer attribute Type transformerConsumerType = WebPartTransformerAttribute.GetConsumerType(transformerType); Type transformerProviderType = WebPartTransformerAttribute.GetProviderType(transformerType); if (providerConnectionPoint.InterfaceType == transformerConsumerType && transformerProviderType == consumerConnectionPoint.InterfaceType) { // A transformer never provides any secondary interfaces if (consumerConnectionPoint.SupportsConnection(consumerControl, ConnectionInterfaceCollection.Empty)) { object dataObject = providerConnectionPoint.GetObject(providerControl); object transformedObject = transformer.Transform(dataObject); consumerConnectionPoint.SetObject(consumerControl, transformedObject); _isActive = true; } else { consumerWebPart.SetConnectErrorMessage(SR.GetString( SR.WebPartConnection_ConsumerRequiresSecondaryInterfaces, consumerConnectionPoint.DisplayName, consumerWebPart.DisplayTitle)); } } else if (providerConnectionPoint.InterfaceType != transformerConsumerType) { string errorMessage; if (_webPartManager.Context != null && _webPartManager.Context.IsCustomErrorEnabled) { errorMessage = SR.GetString( SR.WebPartConnection_IncompatibleProviderTransformer, providerConnectionPoint.DisplayName, providerWebPart.DisplayTitle); } else { errorMessage = SR.GetString( SR.WebPartConnection_IncompatibleProviderTransformerWithType, providerConnectionPoint.DisplayName, providerWebPart.DisplayTitle, transformerType.FullName); } consumerWebPart.SetConnectErrorMessage(errorMessage); } else { string errorMessage; if (_webPartManager.Context != null && _webPartManager.Context.IsCustomErrorEnabled) { errorMessage = SR.GetString( SR.WebPartConnection_IncompatibleConsumerTransformer, consumerConnectionPoint.DisplayName, consumerWebPart.DisplayTitle); } else { errorMessage = SR.GetString( SR.WebPartConnection_IncompatibleConsumerTransformerWithType, transformerType.FullName, consumerConnectionPoint.DisplayName, consumerWebPart.DisplayTitle); } consumerWebPart.SetConnectErrorMessage(errorMessage); } } } } internal bool ConflictsWith(WebPartConnection otherConnection) { return (ConflictsWithConsumer(otherConnection) || ConflictsWithProvider(otherConnection)); } internal bool ConflictsWithConsumer(WebPartConnection otherConnection) { return (!ConsumerConnectionPoint.AllowsMultipleConnections && Consumer == otherConnection.Consumer && ConsumerConnectionPoint == otherConnection.ConsumerConnectionPoint); } internal bool ConflictsWithProvider(WebPartConnection otherConnection) { return (!ProviderConnectionPoint.AllowsMultipleConnections && Provider == otherConnection.Provider && ProviderConnectionPoint == otherConnection.ProviderConnectionPoint); } internal void SetIsShared(bool isShared) { _isShared = isShared; } internal void SetIsStatic(bool isStatic) { _isStatic = isStatic; } internal void SetTransformer(WebPartTransformer transformer) { if (Transformers.Count == 0) { Transformers.Add(transformer); } else { Transformers[0] = transformer; } } internal void SetWebPartManager(WebPartManager webPartManager) { _webPartManager = webPartManager; } // Return the short typename, to improve the look of the collection editor in the designer public override string ToString () { return GetType().Name; } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListBox.cs
- FixedBufferAttribute.cs
- FileDialogCustomPlace.cs
- ListManagerBindingsCollection.cs
- ThreadStaticAttribute.cs
- XamlDesignerSerializationManager.cs
- WMIGenerator.cs
- Point.cs
- SoapDocumentServiceAttribute.cs
- WebPartConnectVerb.cs
- LineBreak.cs
- DefaultAssemblyResolver.cs
- TemplateControl.cs
- Select.cs
- SqlFactory.cs
- TextOnlyOutput.cs
- SqlBuffer.cs
- EdmFunctions.cs
- BasicCellRelation.cs
- InternalTypeHelper.cs
- DropSource.cs
- TransformPattern.cs
- DLinqTableProvider.cs
- BufferedGraphicsManager.cs
- PrintPageEvent.cs
- CodeEventReferenceExpression.cs
- DataGridCommandEventArgs.cs
- Quaternion.cs
- SiteMapProvider.cs
- VisualBrush.cs
- SystemIcmpV6Statistics.cs
- SqlMultiplexer.cs
- HistoryEventArgs.cs
- SafeReversePInvokeHandle.cs
- HostedImpersonationContext.cs
- StructuralCache.cs
- MaskedTextBoxDesigner.cs
- FileChangesMonitor.cs
- KeyboardDevice.cs
- MarshalDirectiveException.cs
- DatagridviewDisplayedBandsData.cs
- DataObjectCopyingEventArgs.cs
- GridViewEditEventArgs.cs
- Utilities.cs
- AlternationConverter.cs
- UnicodeEncoding.cs
- FontFaceLayoutInfo.cs
- XmlObjectSerializerWriteContext.cs
- InputDevice.cs
- InternalSafeNativeMethods.cs
- ExtentKey.cs
- HtmlTextArea.cs
- WebPartManagerInternals.cs
- CompositeDispatchFormatter.cs
- ScriptReferenceBase.cs
- NativeCompoundFileAPIs.cs
- TextElementEnumerator.cs
- IResourceProvider.cs
- IsolatedStorageException.cs
- GridView.cs
- CmsUtils.cs
- ZipIOExtraField.cs
- StaticFileHandler.cs
- ErrorHandler.cs
- StringUtil.cs
- DataTableTypeConverter.cs
- ParagraphVisual.cs
- ObjectDataSourceView.cs
- DocumentPageTextView.cs
- DrawTreeNodeEventArgs.cs
- GetPageCompletedEventArgs.cs
- ObjectItemAssemblyLoader.cs
- CaseInsensitiveComparer.cs
- ArraySubsetEnumerator.cs
- Funcletizer.cs
- OleDbMetaDataFactory.cs
- Exception.cs
- AppliedDeviceFiltersDialog.cs
- CryptoHelper.cs
- DataGridViewAccessibleObject.cs
- MaskDesignerDialog.cs
- ExpressionBuilder.cs
- PropertyMappingExceptionEventArgs.cs
- WebAdminConfigurationHelper.cs
- TypedTableGenerator.cs
- SetStoryboardSpeedRatio.cs
- InvalidOleVariantTypeException.cs
- ScriptingRoleServiceSection.cs
- MessageSecurityOverHttpElement.cs
- PropertyTabAttribute.cs
- UserInitiatedNavigationPermission.cs
- DefaultBinder.cs
- WebPartTransformerCollection.cs
- GradientBrush.cs
- AdornerDecorator.cs
- PartialCachingAttribute.cs
- CreateUserErrorEventArgs.cs
- RootBrowserWindow.cs
- SerializationObjectManager.cs
- DynamicDataManager.cs