Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / fx / src / xsp / System / Web / UI / WebParts / WebPartConnection.cs / 2 / 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; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DynamicRenderer.cs
- SystemIcmpV6Statistics.cs
- CodeDirectoryCompiler.cs
- StringValueSerializer.cs
- StringAttributeCollection.cs
- XmlMemberMapping.cs
- HatchBrush.cs
- DropDownList.cs
- InheritanceUI.cs
- NavigatingCancelEventArgs.cs
- SplitContainer.cs
- GeneralTransform2DTo3DTo2D.cs
- MachineKey.cs
- FrameworkElement.cs
- QueryCacheKey.cs
- UrlPath.cs
- EventPropertyMap.cs
- SpStreamWrapper.cs
- SafeNativeMethods.cs
- PropertyGeneratedEventArgs.cs
- QueryResults.cs
- BackgroundWorker.cs
- SqlStream.cs
- DataGridCell.cs
- IODescriptionAttribute.cs
- FlagsAttribute.cs
- SafeTokenHandle.cs
- XmlElement.cs
- EventLogEntryCollection.cs
- UserValidatedEventArgs.cs
- SafeWaitHandle.cs
- ConnectionPoint.cs
- IntegerValidatorAttribute.cs
- EmptyEnumerator.cs
- LassoSelectionBehavior.cs
- SingleSelectRootGridEntry.cs
- StrokeSerializer.cs
- SqlUserDefinedTypeAttribute.cs
- invalidudtexception.cs
- WebConfigurationManager.cs
- ProvideValueServiceProvider.cs
- ZipIOCentralDirectoryFileHeader.cs
- SerializableAttribute.cs
- DataGridSortCommandEventArgs.cs
- InertiaTranslationBehavior.cs
- HttpListenerContext.cs
- StoreContentChangedEventArgs.cs
- VariableDesigner.xaml.cs
- DropTarget.cs
- ConstructorBuilder.cs
- SchemaDeclBase.cs
- TdsParserSessionPool.cs
- FusionWrap.cs
- BitmapEffectGeneralTransform.cs
- SequenceRangeCollection.cs
- SystemIcons.cs
- PtsHelper.cs
- XPathPatternBuilder.cs
- InputLanguageProfileNotifySink.cs
- commandenforcer.cs
- CqlIdentifiers.cs
- RegexTree.cs
- SHA256.cs
- ListenerElementsCollection.cs
- cache.cs
- StorageComplexPropertyMapping.cs
- UdpDiscoveryEndpointProvider.cs
- RadioButtonPopupAdapter.cs
- AppDomainAttributes.cs
- ConditionCollection.cs
- Atom10FormatterFactory.cs
- UInt64Converter.cs
- RowParagraph.cs
- SortExpressionBuilder.cs
- DataTransferEventArgs.cs
- Label.cs
- GetCertificateRequest.cs
- PropertyGridEditorPart.cs
- PeerTransportSecurityElement.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- QueryExpr.cs
- SafeTokenHandle.cs
- arc.cs
- X509CertificateInitiatorServiceCredential.cs
- NameValuePair.cs
- Point.cs
- StoryFragments.cs
- GeneralTransform2DTo3D.cs
- TextShapeableCharacters.cs
- X500Name.cs
- RootBrowserWindow.cs
- SiteMapSection.cs
- SelectorAutomationPeer.cs
- HatchBrush.cs
- PriorityQueue.cs
- DeviceContext2.cs
- Selection.cs
- Matrix3DValueSerializer.cs
- BitmapFrame.cs
- TraceFilter.cs