示例#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
            }
示例#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;
         }
     }
 }
示例#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;
         }
     }
 }
示例#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
            }
示例#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;
         }
     }
 }
示例#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;
 }