public virtual void DisconnectWebParts(WebPartConnection connection)
 {
     this.Personalization.EnsureEnabled(true);
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     WebPart provider = connection.Provider;
     ProviderConnectionPoint providerConnectionPoint = connection.ProviderConnectionPoint;
     WebPart consumer = connection.Consumer;
     ConsumerConnectionPoint consumerConnectionPoint = connection.ConsumerConnectionPoint;
     WebPartConnectionsCancelEventArgs e = new WebPartConnectionsCancelEventArgs(provider, providerConnectionPoint, consumer, consumerConnectionPoint, connection);
     this.OnWebPartsDisconnecting(e);
     if (!this._allowEventCancellation || !e.Cancel)
     {
         WebPartConnectionsEventArgs args2 = new WebPartConnectionsEventArgs(provider, providerConnectionPoint, consumer, consumerConnectionPoint);
         if (this.StaticConnections.Contains(connection))
         {
             if (this.StaticConnections.IsReadOnly)
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_DisconnectTooLate"));
             }
             if (this.Internals.ConnectionDeleted(connection))
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_AlreadyDisconnected"));
             }
             this.Internals.DeleteConnection(connection);
             this._hasDataChanged = true;
             this.OnWebPartsDisconnected(args2);
         }
         else
         {
             if (!this.DynamicConnections.Contains(connection))
             {
                 throw new ArgumentException(System.Web.SR.GetString("WebPartManager_UnknownConnection"), "connection");
             }
             if (this.DynamicConnections.IsReadOnly)
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_DisconnectTooLate"));
             }
             if (this.ShouldRemoveConnection(connection))
             {
                 this.DynamicConnections.Remove(connection);
             }
             else
             {
                 if (this.Internals.ConnectionDeleted(connection))
                 {
                     throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_AlreadyDisconnected"));
                 }
                 this.Internals.DeleteConnection(connection);
             }
             this._hasDataChanged = true;
             this.OnWebPartsDisconnected(args2);
         }
     }
 }
 protected virtual void OnWebPartsDisconnecting(WebPartConnectionsCancelEventArgs e)
 {
     WebPartConnectionsCancelEventHandler handler = (WebPartConnectionsCancelEventHandler) base.Events[WebPartsDisconnectingEvent];
     if (handler != null)
     {
         handler(this, e);
     }
 }
 public virtual WebPartConnection ConnectWebParts(WebPart provider, ProviderConnectionPoint providerConnectionPoint, WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint, WebPartTransformer transformer)
 {
     this.CanConnectWebPartsCore(provider, providerConnectionPoint, consumer, consumerConnectionPoint, transformer, true);
     if (this.DynamicConnections.IsReadOnly)
     {
         throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_ConnectTooLate"));
     }
     WebPartConnectionsCancelEventArgs e = new WebPartConnectionsCancelEventArgs(provider, providerConnectionPoint, consumer, consumerConnectionPoint);
     this.OnWebPartsConnecting(e);
     if (this._allowEventCancellation && e.Cancel)
     {
         return null;
     }
     Control control = provider.ToControl();
     Control control2 = consumer.ToControl();
     WebPartConnection connection = new WebPartConnection {
         ID = this.CreateDynamicConnectionID(),
         ProviderID = control.ID,
         ConsumerID = control2.ID,
         ProviderConnectionPointID = providerConnectionPoint.ID,
         ConsumerConnectionPointID = consumerConnectionPoint.ID
     };
     if (transformer != null)
     {
         this.Internals.SetTransformer(connection, transformer);
     }
     this.Internals.SetIsShared(connection, this.Personalization.Scope == PersonalizationScope.Shared);
     this.Internals.SetIsStatic(connection, false);
     this.DynamicConnections.Add(connection);
     this._hasDataChanged = true;
     this.OnWebPartsConnected(new WebPartConnectionsEventArgs(provider, providerConnectionPoint, consumer, consumerConnectionPoint, connection));
     return connection;
 }
 protected virtual new void OnWebPartsDisconnecting(WebPartConnectionsCancelEventArgs e)
 {
 }
        public virtual void DisconnectWebParts(WebPartConnection connection) {
            Personalization.EnsureEnabled(/* ensureModifiable */ true);

            if (connection == null) {
                throw new ArgumentNullException("connection");
            }

            Debug.Assert(!(StaticConnections.Contains(connection) && DynamicConnections.Contains(connection)));

            WebPart provider = connection.Provider;
            ProviderConnectionPoint providerConnectionPoint = connection.ProviderConnectionPoint;
            WebPart consumer = connection.Consumer;
            ConsumerConnectionPoint consumerConnectionPoint = connection.ConsumerConnectionPoint;

            WebPartConnectionsCancelEventArgs ce = new WebPartConnectionsCancelEventArgs(
                provider, providerConnectionPoint, consumer, consumerConnectionPoint, connection);
            OnWebPartsDisconnecting(ce);
            if (_allowEventCancellation && ce.Cancel) {
                return;
            }

            WebPartConnectionsEventArgs eventArgs = new WebPartConnectionsEventArgs(
                provider, providerConnectionPoint, consumer, consumerConnectionPoint);

            if (StaticConnections.Contains(connection)) {
                if (StaticConnections.IsReadOnly) {
                    throw new InvalidOperationException(SR.GetString(SR.WebPartManager_DisconnectTooLate));
                }
                if (Internals.ConnectionDeleted(connection)) {
                    throw new InvalidOperationException(SR.GetString(SR.WebPartManager_AlreadyDisconnected));
                }
                Internals.DeleteConnection(connection);
                _hasDataChanged = true;
                OnWebPartsDisconnected(eventArgs);
            }
            else if (DynamicConnections.Contains(connection)) {
                if (DynamicConnections.IsReadOnly) {
                    throw new InvalidOperationException(SR.GetString(SR.WebPartManager_DisconnectTooLate));
                }

                if (ShouldRemoveConnection(connection)) {
                    // Unshared dynamic connection should never be disabled
                    Debug.Assert(!Internals.ConnectionDeleted(connection));
                    DynamicConnections.Remove(connection);
                }
                else {
                    if (Internals.ConnectionDeleted(connection)) {
                        throw new InvalidOperationException(SR.GetString(SR.WebPartManager_AlreadyDisconnected));
                    }
                    Internals.DeleteConnection(connection);
                }
                _hasDataChanged = true;
                OnWebPartsDisconnected(eventArgs);
            }
            else {
                throw new ArgumentException(SR.GetString(SR.WebPartManager_UnknownConnection), "connection");
            }
        }
        public virtual WebPartConnection ConnectWebParts(WebPart provider, ProviderConnectionPoint providerConnectionPoint,
                                                         WebPart consumer, ConsumerConnectionPoint consumerConnectionPoint,
                                                         WebPartTransformer transformer) {
            CanConnectWebPartsCore(provider, providerConnectionPoint, consumer, consumerConnectionPoint,
                                   transformer, /*throwOnError*/ true);

            if (DynamicConnections.IsReadOnly) {
                throw new InvalidOperationException(SR.GetString(SR.WebPartManager_ConnectTooLate));
            }

            WebPartConnectionsCancelEventArgs ce = new WebPartConnectionsCancelEventArgs(
                provider, providerConnectionPoint, consumer, consumerConnectionPoint);
            OnWebPartsConnecting(ce);
            if (_allowEventCancellation && ce.Cancel) {
                return null;
            }

            Control providerControl = provider.ToControl();
            Control consumerControl = consumer.ToControl();

            WebPartConnection connection = new WebPartConnection();
            connection.ID = CreateDynamicConnectionID();
            connection.ProviderID = providerControl.ID;
            connection.ConsumerID = consumerControl.ID;
            connection.ProviderConnectionPointID = providerConnectionPoint.ID;
            connection.ConsumerConnectionPointID = consumerConnectionPoint.ID;

            if (transformer != null) {
                Internals.SetTransformer(connection, transformer);
            }

            Internals.SetIsShared(connection, Personalization.Scope == PersonalizationScope.Shared);
            Internals.SetIsStatic(connection, false);

            DynamicConnections.Add(connection);
            _hasDataChanged = true;

            OnWebPartsConnected(new WebPartConnectionsEventArgs(provider, providerConnectionPoint,
                                                                consumer, consumerConnectionPoint, connection));

            return connection;
        }
 protected virtual new void OnWebPartsDisconnecting(WebPartConnectionsCancelEventArgs e)
 {
 }