Example #1
0
            /// <devdoc>
            /// Creates a connection point to of the given interface type.
            /// which will call on a managed code sink that implements that interface.
            /// </devdoc>
            public ConnectionPointCookie(object source, object sink, Type eventInterface, bool throwException)
            {
                Exception ex = null;

                ThreadHelper.ThrowIfNotOnUIThread();
                if (source is Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer)
                {
                    this.cpc = (Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer)source;

                    try {
                        Guid tmp = eventInterface.GUID;
                        cpc.FindConnectionPoint(ref tmp, out connectionPoint);
                    }
                    catch {
                        connectionPoint = null;
                    }

                    if (connectionPoint == null)
                    {
                        ex = new ArgumentException(/* SR.GetString(SR.ConnectionPoint_SourceIF, eventInterface.Name)*/);
                    }
                    else if (sink == null || !eventInterface.IsInstanceOfType(sink))
                    {
                        ex = new InvalidCastException(/* SR.GetString(SR.ConnectionPoint_SinkIF)*/);
                    }
                    else
                    {
                        try {
                            connectionPoint.Advise(sink, out cookie);
                        }
                        catch {
                            cookie          = 0;
                            connectionPoint = null;
                            ex = new Exception(/*SR.GetString(SR.ConnectionPoint_AdviseFailed, eventInterface.Name)*/);
                        }
                    }
                }
                else
                {
                    ex = new InvalidCastException(/*SR.ConnectionPoint_SourceNotICP)*/);
                }


                if (throwException && (connectionPoint == null || cookie == 0))
                {
                    if (ex == null)
                    {
                        throw new ArgumentException(/*SR.GetString(SR.ConnectionPoint_CouldNotCreate, eventInterface.Name)*/);
                    }
                    else
                    {
                        throw ex;
                    }
                }

                #if DEBUG
                callStack           = Environment.StackTrace;
                this.eventInterface = eventInterface;
                #endif
            }
Example #2
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         try {
             if (connectionPoint != null && cookie != 0)
             {
                 connectionPoint.Unadvise(cookie);
             }
         }
         finally {
             this.cookie          = 0;
             this.connectionPoint = null;
             this.cpc             = null;
         }
     }
 }
Example #3
0
 private void Dispose(bool disposing)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (disposing)
     {
         try {
             if (connectionPoint != null && cookie != 0)
             {
                 connectionPoint.Unadvise(cookie);
             }
         }
         finally {
             this.cookie          = 0;
             this.connectionPoint = null;
             this.cpc             = null;
         }
     }
 }
Example #4
0
            /// <devdoc>
            /// Creates a connection point to of the given interface type.
            /// which will call on a managed code sink that implements that interface.
            /// </devdoc>
            public ConnectionPointCookie(object source, object sink, Type eventInterface, bool throwException){
                Exception ex = null;
                if (source is Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer) {
                    this.cpc = (Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer)source;

                    try {
                        Guid tmp = eventInterface.GUID;
                        cpc.FindConnectionPoint(ref tmp, out connectionPoint);
                    }
                    catch {
                        connectionPoint = null;
                    }

                    if (connectionPoint == null) {
                        ex = new ArgumentException(/* SR.GetString(SR.ConnectionPoint_SourceIF, eventInterface.Name)*/);
                    }
                    else if (sink == null || !eventInterface.IsInstanceOfType(sink)) {
                        ex = new InvalidCastException(/* SR.GetString(SR.ConnectionPoint_SinkIF)*/);
                    }
                    else {
                        try {
                            connectionPoint.Advise(sink, out cookie);
                        }
                        catch {
                            cookie = 0;
                            connectionPoint = null;
                            ex = new Exception(/*SR.GetString(SR.ConnectionPoint_AdviseFailed, eventInterface.Name)*/);
                        }
                    }
                }
                else {
                    ex = new InvalidCastException(/*SR.ConnectionPoint_SourceNotICP)*/);
                }


                if (throwException && (connectionPoint == null || cookie == 0)) {
                    if (ex == null) {
                        throw new ArgumentException(/*SR.GetString(SR.ConnectionPoint_CouldNotCreate, eventInterface.Name)*/);
                    }
                    else {
                        throw ex;
                    }
                }

                #if DEBUG
                callStack = Environment.StackTrace;
                this.eventInterface = eventInterface;
                #endif
            }
Example #5
0
 private void Dispose(bool disposing) {
     if (disposing) {
         try {
             if (connectionPoint != null && cookie != 0) {
                 connectionPoint.Unadvise(cookie);
             }
         }
         finally {
             this.cookie = 0;
             this.connectionPoint = null;
             this.cpc = null;
         }
     }
 }
Example #6
0
 public ConnectionPointCookie(object source, object sink, System.Type eventInterface, bool throwException)
 {
     Exception exception1 = null;
     if (source is Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer)
     {
         this.cpc = (Microsoft.VisualStudio.OLE.Interop.IConnectionPointContainer) source;
         try
         {
             Guid guid1 = eventInterface.GUID;
             this.cpc.FindConnectionPoint(ref guid1, out this.connectionPoint);
         }
         catch
         {
             this.connectionPoint = null;
         }
         if (this.connectionPoint == null)
         {
             exception1 = new ArgumentException();
             goto Label_009A;
         }
         if ((sink == null) || !eventInterface.IsInstanceOfType(sink))
         {
             exception1 = new InvalidCastException();
             goto Label_009A;
         }
         try
         {
             this.connectionPoint.Advise(sink, out this.cookie);
             goto Label_009A;
         }
         catch
         {
             this.cookie = 0;
             this.connectionPoint = null;
             exception1 = new Exception();
             goto Label_009A;
         }
     }
     exception1 = new InvalidCastException();
     Label_009A:
     if (!throwException || ((this.connectionPoint != null) && (this.cookie != 0)))
     {
         return;
     }
     if (exception1 == null)
     {
         throw new ArgumentException();
     }
     throw exception1;
 }
Example #7
0
            /// <include file='doc\NativeMethods.uex' path='docs/doc[@for="ConnectionPointCookie.Disconnect1"]/*' />
            /// <devdoc>
            /// Disconnect the current connection point.  If the object is not connected,
            /// this method will do nothing.
            /// </devdoc>
            public void Disconnect(bool release) {
                if (connectionPoint != null && cookie != 0) {
                    connectionPoint.Unadvise(cookie);
                    cookie = 0;

                    if (release) {
                        Marshal.ReleaseComObject(connectionPoint);
                    }

                    connectionPoint = null;
                }
            }