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

            if (source is IConnectionPointContainer) {
                _connectionPointContainer = (IConnectionPointContainer)source;

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

                if (_connectionPoint == null) {
                    ex = new NotSupportedException();
                } else if (sink == null || !eventInterface.IsInstanceOfType(sink)) {
                    ex = new InvalidCastException();
                } else {
                    try {
                        _connectionPoint.Advise(sink, out _cookie);
                    } catch {
                        _cookie = 0;
                        _connectionPoint = null;
                        ex = new Exception();
                    }
                }
            } else {
                ex = new InvalidCastException();
            }

            if (throwException && (_connectionPoint == null || _cookie == 0)) {
                Dispose();

                if (ex == null) {
                    throw new ArgumentException("Exception null, but cookie was zero or the connection point was null");
                } else {
                    throw ex;
                }
            }

#if DEBUG
            //_callStack = Environment.StackTrace;
            //this._eventInterface = eventInterface;
#endif
        }
Example #2
0
        public void OnRegisterView(IVsTextView pView)
        {
            IVsTextLines buffer;

            ErrorHandler.ThrowOnFailure(pView.GetBuffer(out buffer));
            if (buffer == null)
            {
                return;
            }

            int documentViewCount;

            documentViewCounts.TryGetValue(buffer, out documentViewCount);
            documentViewCounts[buffer] = documentViewCount + 1;

            if (documentViewCount != 0)
            {
                return;
            }

            IConnectionPoint connectionPointBufferDataEvents;
            IConnectionPoint connectionPointTextLinesEvents;
            uint             cookie;

            IConnectionPointContainer container = (IConnectionPointContainer)buffer;

            Guid textBufferDataEventsGuid = typeof(IVsTextBufferDataEvents).GUID;

            container.FindConnectionPoint(ref textBufferDataEventsGuid, out connectionPointBufferDataEvents);
            TextBufferDataEventSink textBufferDataEventSink = new TextBufferDataEventSink();

            connectionPointBufferDataEvents.Advise(textBufferDataEventSink, out cookie);
            textBufferDataEventSink.TextLines       = buffer;
            textBufferDataEventSink.ConnectionPoint = connectionPointBufferDataEvents;
            textBufferDataEventSink.Cookie          = cookie;

            Guid eventsGuid = typeof(IVsTextLinesEvents).GUID;

            container.FindConnectionPoint(ref eventsGuid, out connectionPointTextLinesEvents);
            TextLinesEventSink textLinesEventSink = new TextLinesEventSink();

            connectionPointTextLinesEvents.Advise(textLinesEventSink, out cookie);
            textLinesEventSink.TextLines       = buffer;
            textLinesEventSink.ConnectionPoint = connectionPointTextLinesEvents;
            textLinesEventSink.Cookie          = cookie;

            if (AtlassianPanel.Instance != null && AtlassianPanel.Instance.Jira != null)
            {
                selectedServerListeners[pView] = new SelectedServerListener(pView);
            }
        }
        public PrintDocumentPackageStatusProvider(IPrintDocumentPackageTarget docPackageTarget)
        {
            _jobId = 0;
            _jobIdAcquiredEvent = null;

            IConnectionPointContainer connectionPointContainer = docPackageTarget as IConnectionPointContainer;

            if (connectionPointContainer != null)
            {
                IConnectionPoint connectionPoint = null;
                Guid             riid            = typeof(IPrintDocumentPackageStatusEvent).GUID;
                connectionPointContainer.FindConnectionPoint(ref riid, out connectionPoint);

                if (connectionPoint != null)
                {
                    _connectionPoint = connectionPoint;
                    int cookie = -1;
                    connectionPoint.Advise(this, out cookie);

                    if (cookie != -1)
                    {
                        _cookie             = cookie;
                        _jobIdAcquiredEvent = new ManualResetEvent(false);
                    }
                }
            }
        }
        public SafeConnectionPointCookie(IConnectionPointContainer target, object sink, Guid eventId)
        {
            Class6.yDnXvgqzyB5jw();
            base(true);
            int num;

            Verify.IsNotNull <IConnectionPointContainer>(target, "target");
            Verify.IsNotNull <object>(sink, "sink");
            Verify.IsNotDefault <Guid>(eventId, "eventId");
            this.handle = IntPtr.Zero;
            IConnectionPoint connectionPoint = null;

            try
            {
                target.FindConnectionPoint(ref eventId, out connectionPoint);
                connectionPoint.Advise(sink, out num);
                if (num == 0)
                {
                    throw new InvalidOperationException("IConnectionPoint::Advise returned an invalid cookie.");
                }
                this.handle     = new IntPtr(num);
                this._cp        = connectionPoint;
                connectionPoint = null;
            }
            finally
            {
                Utility.SafeRelease <IConnectionPoint>(ref connectionPoint);
            }
        }
        public TextBufferInitializationTracker(
            string documentName,
            IVsHierarchy hierarchy,
            VSConstants.VSITEMID itemid,
            IVsTextLines textLines,
            Guid languageServiceId,
            List <TextBufferInitializationTracker> trackers)
        {
            VsAppShell.Current.CompositionService.SatisfyImportsOnce(this);

            _documentName        = documentName;
            _hierarchy           = hierarchy;
            _itemid              = itemid;
            _textLines           = textLines;
            _languageServiceGuid = languageServiceId;
            _trackers            = trackers;

            IConnectionPointContainer cpc = textLines as IConnectionPointContainer;
            Guid g = typeof(IVsTextBufferDataEvents).GUID;

            cpc.FindConnectionPoint(g, out cp);
            cp.Advise(this, out cookie);

            _trackers.Add(this);
        }
Example #6
0
        protected override void Initialize()
        {
            base.Initialize();

            //绑定textView事件
            IVsMonitorSelection monitorSelection = (IVsMonitorSelection)GetService(typeof(SVsShellMonitorSelection));

            ErrorHandler.ThrowOnFailure(monitorSelection.AdviseSelectionEvents(textViewEvent, out selectionEventCookie));

            //绑定RunningDocTable事件
            IVsRunningDocumentTable DocTables = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable));

            DocTables.AdviseRunningDocTableEvents(docTableEvent, out runningDocEventCookie);

            // And we can query for the text manager service as we're surely running in
            // interactive mode. So this is the right time to register for text manager events.
            IConnectionPointContainer textManager = (IConnectionPointContainer)GetService(typeof(SVsTextManager));
            Guid interfaceGuid = typeof(IVsTextManagerEvents).GUID;

            textManager.FindConnectionPoint(ref interfaceGuid, out tmConnectionPoint);
            tmConnectionPoint.Advise(TextManagerEventSink, out tmConnectionCookie);

            //todo:通过win32形式检测键盘输入
            hookVs.InitHook();
        }
Example #7
0
        private void HookEvents(object source, Guid eventGuid)
        {
            IConnectionPointContainer connectionPointContainer = null;
            IConnectionPoint          connectionPoint          = null;
            int cookie = 0;

            connectionPointContainer = source as IConnectionPointContainer;
            if (connectionPointContainer != null)
            {
                connectionPointContainer.FindConnectionPoint(eventGuid, out connectionPoint);
                if (connectionPoint != null)
                {
                    connectionPoint.Advise(this, out cookie);
                    if (cookie != 0)
                    {
                        _connectionPoints.Add(connectionPoint, cookie);
                    }
                    else
                    {
                        throw new System.Exception("Advisory connection between the connection point and the caller's sink object failed.");
                    }
                }
                else
                {
                    throw new System.Exception(String.Format("Connection point '{0}' not found.", eventGuid));
                }
            }
            else
            {
                throw new System.Exception("Source does not implement IConnectionPointContainer.");
            }
        }
Example #8
0
        public void SetupConnection(OL.Application application, ActivationPG activatePG)
        {
            if (m_Cookie != 0)
            {
                return;
            }

            m_ActivePG = activatePG;

            // GUID of the DIID_ApplicationEvents dispinterface.
            Guid guid = new Guid("{0006300E-0000-0000-C000-000000000046}");

            // QI for IConnectionPointContainer.
            IConnectionPointContainer oConnectionPointContainer = (IConnectionPointContainer)application;

            try
            {
                // Find the connection point and then advise.
                m_ActivePG.MailGo.Track.Debug("Advise START");
                oConnectionPointContainer.FindConnectionPoint(ref guid, out m_oConnectionPoint);
                m_ActivePG.MailGo.Track.Debug("Advise CONTINUE");
                m_oConnectionPoint.Advise(this, out m_Cookie);

                m_ActivePG.MailGo.Track.Debug("Advise FINISH");
            }
            catch (Exception ex)
            {
                m_ActivePG.MailGo.Track.Debug("ERROR");
                m_ActivePG.MailGo.Track.Error(ex);
            }
        }
        /// <summary>
        /// Establishes a connection between a connection point object and the client's sink.
        /// </summary>
        /// <param name="source">An event source that implements IConnectionPointContainer.</param>
        public void Connect(object source)
        {
            bool lockTaken = false;
            IConnectionPointContainer container = null;

            try
            {
                Monitor.Enter(this, ref lockTaken);

                // If previous call was made, disconnect existing connection.
                if (container != null)
                {
                    Disconnect();
                }

                // QueryInterface for IConnectionPointContainer.
                container = (IConnectionPointContainer)source;

                // Find the connection point by the GUID of type T.
                container.FindConnectionPoint(typeof(T).GUID, out _connectionPoint);

                if (_connectionPoint != null)
                {
                    // Establish the sink connection.
                    _connectionPoint.Advise(this, out _cookie);
                }
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(this);
                }
            }
        }
Example #10
0
        public SafeConnectionPointCookie(IConnectionPointContainer target, object sink, Guid eventId) : base(true)
        {
            Standard.Verify.IsNotNull <IConnectionPointContainer>(target, "target");
            Standard.Verify.IsNotNull <object>(sink, "sink");
            Standard.Verify.IsNotDefault <Guid>(eventId, "eventId");
            base.handle = IntPtr.Zero;
            IConnectionPoint ppCP = null;

            try
            {
                int num;
                target.FindConnectionPoint(ref eventId, out ppCP);
                ppCP.Advise(sink, out num);
                if (num == 0)
                {
                    throw new InvalidOperationException("IConnectionPoint::Advise returned an invalid cookie.");
                }
                base.handle = new IntPtr(num);
                this._cp    = ppCP;
                ppCP        = null;
            }
            finally
            {
                Standard.Utility.SafeRelease <IConnectionPoint>(ref ppCP);
            }
        }
Example #11
0
        public static void UnadviseAll(object sink)
        {
            List <string> removeKeys = new List <string>();
            int           j          = sink.GetHashCode();

            foreach (KeyValuePair <string, Advisory> advisory in cookieJar)
            {
                if (advisory.Value.SinkHash == j)
                {
                    int cookie = advisory.Value.Cookie;

                    IConnectionPointContainer container = (IConnectionPointContainer)advisory.Value.Source;
                    IConnectionPoint          cp;
                    Guid guid = advisory.Value.Guid;

                    container.FindConnectionPoint(ref guid, out cp);
                    cp.Unadvise(cookie);

                    removeKeys.Add(advisory.Key);
                }
            }

            foreach (string key in removeKeys)
            {
                cookieJar.Remove(key);
            }
        }
Example #12
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 IConnectionPointContainer)
                {
                    cpc = (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)*/);
                    }
                    throw ex;
                }

#if DEBUG
                callStack           = Environment.StackTrace;
                this.eventInterface = eventInterface;
#endif
            }
        public NameSpaceWrapper(object obj)
        {
            Utility.LogNameSpaceEvent(LogType.Diagnostic, (string.Format("{0}{1}", new StackTrace().GetFrame(0).GetMethod().Name, System.Environment.NewLine)));

            this._myObject             = obj;
            _pConnectionPointContainer = _myObject as IConnectionPointContainer;
            if (_pConnectionPointContainer != null)
            {
                _pConnectionPoint = null;
                _pConnectionPointContainer.FindConnectionPoint(_sourceIntfGuid, out _pConnectionPoint);
                if (_pConnectionPoint != null)
                {
                    _pConnectionPoint.Advise(this, out _cookie);

                    nameSpace           = _myObject as Outlook.NameSpace;
                    inboxMAPIFolder     = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);    // inboxMAPIFolder is released within the wrapper
                    outboxMAPIFolder    = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);   // outboxMAPIFolder is released within the wrapper
                    sentItemsMAPIFolder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail); // sentItemsMAPIFolder is released within the wrapper
                    if (ControlPanel.TrackInboxEnabled)
                    {
                        new FolderWrapper(inboxMAPIFolder);
                    }
                    if (ControlPanel.TrackOutboxEnabled)
                    {
                        new FolderWrapper(outboxMAPIFolder);
                    }
                    if (ControlPanel.TrackSentItemsEnabled)
                    {
                        new FolderWrapper(sentItemsMAPIFolder);
                    }
                }
            }
        }
Example #14
0
        public static void Advise <T>(object source, T sink)
        {
            if (source == null || sink == null)
            {
                throw new ArgumentNullException("source", "AdviseForEvents<T>: Source and sink cannot be null");
            }

            IntPtr i   = Marshal.GetIUnknownForObject(source);
            int    j   = sink.GetHashCode();
            int    k   = typeof(T).GetHashCode();
            string key = GetKey(i, j, k);

            if (cookieJar.ContainsKey(key))
            {
                return;                   // already advise the source of the sink.
            }

            IConnectionPoint cp;
            int cookie;
            IConnectionPointContainer container = (IConnectionPointContainer)source;
            Guid guid = typeof(T).GUID;

            container.FindConnectionPoint(ref guid, out cp);
            cp.Advise(sink, out cookie);

            cookieJar.Add(key, new Advisory(source, guid, j, cookie));
        }
Example #15
0
        int IVsCodeWindowEvents.OnNewView(IVsTextView pView)
        {
            if (pView == null)
            {
                throw new ArgumentNullException(nameof(pView));
            }

            IConnectionPointContainer connectionPointContainer = pView as IConnectionPointContainer;

            if (connectionPointContainer != null)
            {
                Guid             textViewEventsGuid = typeof(IVsTextViewEvents).GUID;
                IConnectionPoint connectionPoint;
                connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                if (connectionPoint != null)
                {
                    uint cookie;
                    connectionPoint.Advise(this, out cookie);
                    if (cookie != 0)
                    {
                        _textViewEventsCookies.Add(pView, cookie);
                    }
                }
            }

            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Determines if a connection between a connection point object and the client's sink is established.
        /// </summary>
        /// <param name="container">An object that implements the IConnectionPointContainer inferface.</param>
        public bool IsSinkAdvised <TInterface>(object container) where TInterface : class
        {
            bool lockTaken = false;

            try
            {
                Monitor.Enter(this, ref lockTaken);

                IConnectionPointContainer cpc = null;
                IConnectionPoint          cp  = null;
                int cookie = 0;

                cpc = (IConnectionPointContainer)container;
                cpc.FindConnectionPoint(typeof(TInterface).GUID, out cp);

                if (cp != null)
                {
                    if (_connectionPointDictionary.ContainsKey(cp))
                    {
                        cookie = _connectionPointDictionary[cp];
                        return(true);
                    }
                }
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(this);
                }
            }

            return(false);
        }
Example #17
0
        int IVsCodeWindowEvents.OnCloseView(IVsTextView pView)
        {
            if (pView == null)
            {
                throw new ArgumentNullException(nameof(pView));
            }

            uint cookie;

            if (_textViewEventsCookies.TryGetValue(pView, out cookie))
            {
                _textViewEventsCookies.Remove(pView);

                IConnectionPointContainer connectionPointContainer = pView as IConnectionPointContainer;
                if (connectionPointContainer != null)
                {
                    Guid             textViewEventsGuid = typeof(IVsTextViewEvents).GUID;
                    IConnectionPoint connectionPoint;
                    connectionPointContainer.FindConnectionPoint(ref textViewEventsGuid, out connectionPoint);
                    connectionPoint?.Unadvise(cookie);
                }
            }

            return(VSConstants.S_OK);
        }
Example #18
0
        public static void Unadvise <T>(object source, T sink)
        {
            if (source == null || sink == null)
            {
                throw new ArgumentNullException("source", "UnadviseForEvents<T>: Source and sink cannot be null");
            }

            IntPtr i   = Marshal.GetIUnknownForObject(source);
            int    j   = sink.GetHashCode();
            int    k   = typeof(T).GetHashCode();
            string key = GetKey(i, j, k);

            // avoid exception, check to see if cookieJar
            // has key value before referencing item using
            // index syntax
            if (cookieJar.ContainsKey(key))
            {
                int cookie = cookieJar[key].Cookie;

                IConnectionPointContainer container = (IConnectionPointContainer)source;
                IConnectionPoint          cp;
                Guid guid = typeof(T).GUID;

                container.FindConnectionPoint(ref guid, out cp);
                cp.Unadvise(cookie);

                cookieJar.Remove(key);
            }
        }
Example #19
0
        public bool AddGroup(object Form_Main) //返回值false为失败,true为成功
        {
            Int32    dwRequestedUpdateRate = 2000;
            Int32    hClientGroup          = 1;
            Int32    pRevUpdaterate;
            float    deadband = 0;
            int      TimeBias = 0;
            GCHandle hTimeBias, hDeadband;

            hTimeBias = GCHandle.Alloc(TimeBias, GCHandleType.Pinned);
            hDeadband = GCHandle.Alloc(deadband, GCHandleType.Pinned);
            Guid iidRequiredInterface = typeof(IOPCItemMgt).GUID;

            if (!isConnected)
            {
                if (!Connect())
                {
                    return(false);            //如果还没有没有建立连接,先建立连接
                }
            }
            try
            {   //ServerObj.AddGroup的返回值类型为void
                ServerObj.AddGroup("OPCGroup", 0,
                                   dwRequestedUpdateRate, hClientGroup,
                                   hTimeBias.AddrOfPinnedObject(), hDeadband.AddrOfPinnedObject(),
                                   LOCALE_ID, out pSvrGroupHandle,
                                   out pRevUpdaterate, ref iidRequiredInterface, out GroupObj);
                IOPCAsyncIO2Obj = (IOPCAsyncIO2)GroupObj;//为组异步读写定义句柄
                //Query interface for Async calls on group object

                IOPCGroupStateMgtObj = (IOPCGroupStateMgt)GroupObj;

                pIConnectionPointContainer = (IConnectionPointContainer)GroupObj;
                //定义特定组的异步调用连接
                Guid iid = typeof(IOPCDataCallback).GUID;
                // Establish Callback for all async operations
                pIConnectionPointContainer.FindConnectionPoint(ref iid, out pIConnectionPoint);
                // Creates a connection between the OPC servers's connection point and this client's sink (the callback object)
                pIConnectionPoint.Advise(Form_Main, out dwCookie);
                isAddGroup = true;
            }
            catch (System.Exception error)
            {
                isAddGroup = false;
                MessageBox.Show(string.Format("创建组对象时出错:-{0}", error.Message), "建组出错",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (hDeadband.IsAllocated)
                {
                    hDeadband.Free();
                }
                if (hTimeBias.IsAllocated)
                {
                    hTimeBias.Free();
                }
            }
            return(isAddGroup);
        }
        /// <summary>
        /// Establishes a connection between a connection point object and the client's sink.
        /// </summary>
        /// <typeparam name="TInterface">Interface type of the outgoing interface whose connection point object is being requested.</typeparam>
        /// <param name="container">An object that implements the IConnectionPointContainer inferface.</param>
        public void AdviseSink <TInterface>(object container) where TInterface : class
        {
            bool lockTaken = false;

            try
            {
                Monitor.Enter(this, ref lockTaken);

                // Prevent multiple event Advise() calls on same sink.
                if (IsSinkAdvised <TInterface>(container))
                {
                    return;
                }

                IConnectionPointContainer cpc = null;
                IConnectionPoint          cp  = null;
                int cookie = 0;

                cpc = (IConnectionPointContainer)container;
                cpc.FindConnectionPoint(typeof(TInterface).GUID, out cp);

                if (cp != null)
                {
                    cp.Advise(_sink, out cookie);
                    _connectionPointDictionary.Add(cp, cookie);
                }
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(this);
                }
            }
        }
        public void AdviseforNetworklistManager()
        {
            IConnectionPointContainer arg_23_0 = (IConnectionPointContainer)this.m_nlm;
            Guid gUID = typeof(INetworkListManagerEvents).GUID;

            arg_23_0.FindConnectionPoint(ref gUID, out this.m_icp);
            this.m_icp.Advise(this, out this.m_cookie);
        }
        public void AdviseforNetworklistManager()
        {
            IConnectionPointContainer icpc = (IConnectionPointContainer)m_nlm;
            Guid tempGuid = typeof(INetworkListManagerEvents).GUID;

            icpc.FindConnectionPoint(ref tempGuid, out m_icp);
            m_icp.Advise(this, out m_cookie);
        }
Example #23
0
        private void ConnectToNetworkListManagerEvents()
        {
            IConnectionPointContainer icpc = (IConnectionPointContainer)m_networkListManager;
            Guid typeGuid = typeof(INetworkListManagerEvents).GUID;

            icpc.FindConnectionPoint(ref typeGuid, out m_connectionPoint);
            m_connectionPoint.Advise(this, out m_cookie);
        }
        public ConnectionGroup(string opcServer, string opcHost, List <OPCBaseChannel> channels)
        {
            Type t;

            if (opcHost.ToLowerInvariant() == "localhost")
            {
                t = Type.GetTypeFromProgID(opcServer);
            }
            else
            {
                t = Type.GetTypeFromProgID(opcServer, opcHost);
            }

            server = (IOPCServer)Activator.CreateInstance(t);
            int    groupClientId = 1;
            int    groupId;
            int    updateRate = 0;
            object group_obj;
            Guid   tmp_guid = typeof(IOPCItemMgt).GUID;

            server.AddGroup("fscdg", 1, updateRate, groupClientId, new IntPtr(), new IntPtr(), 0, out groupId, out updateRate, ref tmp_guid, out group_obj);
            group = (IOPCItemMgt)group_obj;
            IntPtr addResult = new IntPtr();
            IntPtr addErrors = new IntPtr();


            OPCITEMDEF[] items = new OPCITEMDEF[2];
            for (int i = 0; i < channels.Count; i++)
            {
                items[0].bActive  = 1;
                items[0].szItemID = channels[i].OpcChannel;
                items[0].hClient  = channels[i].GetHashCode();
                group.AddItems(1, items, out addResult, out addErrors);
            }


            for (int i = 0; i < channels.Count; i++)
            {
                IntPtr        pos = new IntPtr(addResult.ToInt32() + Marshal.SizeOf(typeof(OPCITEMRESULT)) * i);
                OPCITEMRESULT res = (OPCITEMRESULT)Marshal.PtrToStructure(pos, typeof(OPCITEMRESULT));

                bool readOnly = (res.dwAccessRights & OPC_WRITEABLE) != OPC_WRITEABLE;
                channels[i].Connect(this, res.hServer, readOnly);
            }
            Marshal.FreeCoTaskMem(addResult);
            Marshal.FreeCoTaskMem(addErrors);
            addResult = IntPtr.Zero;
            addErrors = IntPtr.Zero;

            IConnectionPointContainer cpc = (IConnectionPointContainer)group_obj;
            IConnectionPoint          cp;
            Guid dataCallbackGuid = typeof(IOPCDataCallback).GUID;

            cpc.FindConnectionPoint(ref dataCallbackGuid, out cp);

            callback = new OPCDataCallback(channels);
            cp.Advise(callback, out callbackCookie);
        }
Example #25
0
        /// <summary>
        /// Creates a connection point to of the given interface type
        /// which will call on a managed code sink that implements that interface.
        /// </summary>
        public ConnectionPointCookie(object source, object sink, Type eventInterface, bool throwException)
        {
            Exception ex = null;

            if (source is IConnectionPointContainer)
            {
                _connectionPointContainer = (IConnectionPointContainer)source;

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

                if (_connectionPoint == null)
                {
                    ex = new NotSupportedException();
                }
                else if (sink == null || !eventInterface.IsInstanceOfType(sink))
                {
                    ex = new InvalidCastException();
                }
                else
                {
                    try {
                        _connectionPoint.Advise(sink, out _cookie);
                    } catch {
                        _cookie          = 0;
                        _connectionPoint = null;
                        ex = new Exception();
                    }
                }
            }
            else
            {
                ex = new InvalidCastException();
            }

            if (throwException && (_connectionPoint == null || _cookie == 0))
            {
                Dispose();

                if (ex == null)
                {
                    throw new ArgumentException("Exception null, but cookie was zero or the connection point was null");
                }
                else
                {
                    throw ex;
                }
            }

#if DEBUG
            //_callStack = Environment.StackTrace;
            //this._eventInterface = eventInterface;
#endif
        }
        /// <summary>
        /// Creates a connection point to of the given interface type,
        /// which will call on a managed code sink that implements that interface.
        /// </summary>
        /// <param name='source'>
        /// The object that exposes the events. This object must implement IConnectionPointContainer or an InvalidCastException will be thrown.
        /// </param>
        /// <param name='sink'>
        /// The object to sink the events. This object must implement the interface eventInterface, or an InvalidCastException is thrown.
        /// </param>
        /// <param name='iid'>
        /// The GUID of the event interface to sink. The sink object must support this interface and the source object must expose it through it's ConnectionPointContainer.
        /// </param>
        /// <param name='throwException'>
        /// If true, exceptions described will be thrown, otherwise object will silently fail to connect.
        /// </param>
        public ConnectionPointCookie(object source, object sink, Guid iid, bool throwException)
        {
            Exception ex = null;

            if (source is IConnectionPointContainer)
            {
                IConnectionPointContainer cpc = (IConnectionPointContainer)source;
                IEnumConnectionPoints     checkPoints;
                cpc.EnumConnectionPoints(out checkPoints);
                try
                {
                    Guid tmp = iid;
                    cpc.FindConnectionPoint(ref tmp, out connectionPoint);
                }
                catch (Exception)
                {
                    connectionPoint = null;
                }

                if (connectionPoint == null)
                {
                    ex = new ArgumentException("The source object does not expose the " + iid + " event interface");
                }
//                else if (!Type.GetTypeFromCLSID(iid).IsInstanceOfType(sink) && !(iid.Equals(typeof(Interop.IPropertyNotifySink).GUID)))
//                {
//                    ex = new InvalidCastException("The sink object does not implement the eventInterface");
//                }
                else
                {
                    try
                    {
                        connectionPoint.Advise(sink, out cookie);
                    }
                    catch (Exception)
                    {
                        cookie          = 0;
                        connectionPoint = null;
                        ex = new Exception("IConnectionPoint::Advise failed for event interface '" + iid + "'");
                    }
                }
            }
            else
            {
                ex = new InvalidCastException("The source object does not expost IConnectionPointContainer");
            }

            if (throwException && (connectionPoint == null || cookie == 0))
            {
                if (ex == null)
                {
                    throw new ArgumentException("Could not create connection point for event interface '" + iid + "'");
                }
                else
                {
                    throw ex;
                }
            }
        }
        // Token: 0x06006214 RID: 25108 RVA: 0x0014D790 File Offset: 0x0014B990
        private void Advise(object rcw)
        {
            IConnectionPointContainer connectionPointContainer = (IConnectionPointContainer)rcw;
            IConnectionPoint          connectionPoint;

            connectionPointContainer.FindConnectionPoint(ref this._iidSourceItf, out connectionPoint);
            connectionPoint.Advise(this, out this._cookie);
            this._connectionPoint = connectionPoint;
        }
Example #28
0
        public XingSessionCtrl()
        {
            m_session = new XASession();
            m_icpc    = (IConnectionPointContainer)m_session;
            Guid IID_SessionEvents = typeof(_IXASessionEvents).GUID;

            m_icpc.FindConnectionPoint(ref IID_SessionEvents, out m_icp);
            m_icp.Advise(this, out m_dwCookie);
        }
Example #29
0
        // Public Methods (2) 

        /// <summary>
        /// Begins advising the linked <see cref="Org.Edgerunner.Dynamics.Nav.CSide.Client"/> of new events from the source.
        /// </summary>
        /// <param name="source">The source.</param>
        public void Advise(ref IObjectDesigner source)
        {
            //   Late bind connection point subscription
            //   Subscribe for connection point event
            IConnectionPointContainer container = source as IConnectionPointContainer;

            container.FindConnectionPoint(ref _IID, out _ConnectionPoint);
            _ConnectionPoint.Advise(this, out _Cookie);
        }
        public ManipulationEvents(IConnectionPointContainer connectionPointContainer, IManipulationEvents callBack)
        {
            _callBack = callBack;

            Guid manipulationEventsId = new Guid(IIDGuid.IManipulationEvents);

            connectionPointContainer.FindConnectionPoint(ref manipulationEventsId, out _connectionPoint);
            _connectionPoint.Advise(this, out _cookie);
        }
Example #31
0
    public Foo()
    {
        nlm = new NetworkListManager();
        IConnectionPointContainer icpc = (IConnectionPointContainer)nlm;
        Guid tempGuid = typeof(INetworkListManagerEvents).GUID;

        icpc.FindConnectionPoint(ref tempGuid, out icp);
        icp.Advise(this, out cookie);
    }
Example #32
0
        public NetworkWatcher()
        {
            _buffer = new Timer(BufferCallback);

            _manager = new NetworkListManager();

            // init current connections
            _connections = GetCurrentConnections();

            // prep for networkevents
            _container = (IConnectionPointContainer)_manager;
            _container.FindConnectionPoint(ref IID_INetworkEvents, out _connectionPoint);

            // wire up sink object
            _sink.Added += NetworkAdded;
            _sink.ConnectivityChanged += NetworkConnectivityChanged;
            _sink.Deleted += NetworkDeleted;
            _sink.PropertyChanged += NetworkPropertyChanged;

            // enable raising events
            _connectionPoint.Advise(_sink, out _cookie);
        }
Example #33
0
        /// <summary>
        /// try to find connection point by FindConnectionPoint
        /// </summary>
        /// <param name="connectionPointContainer"></param>
        /// <param name="point"></param>
        /// <param name="sinkIds"></param>
        /// <returns></returns>
        private static string FindConnectionPoint(IConnectionPointContainer connectionPointContainer, ref IConnectionPoint point, params string[] sinkIds)
        {
            try
            {
                for (int i = sinkIds.Length; i > 0; i--)
                {
                    Guid refGuid = new Guid(sinkIds[i - 1]);
                    IConnectionPoint refPoint = null;
                    connectionPointContainer.FindConnectionPoint(ref refGuid, out refPoint);
                    if (null != refPoint)
                    {
                        point = refPoint;
                        return sinkIds[i - 1];
                    }
                }

                return null;
            }
            catch (Exception throwedException)
            {
                DebugConsole.WriteException(throwedException);
                return null;
            }
        }
 //------------------------------------------------------------
 public HTMLDocument2Events2Sink(int procId, IHTMLDocument2 doc, DocumentCompleteEventHandler h)
 {
     this.procId = procId;
     this.doc = doc;
     docCompletedHandler = h;
     handler = new Handler(this);
     connPointContainer = (IConnectionPointContainer)doc;
     connPointContainer.FindConnectionPoint(ref IID_HTMLDocumentEvents2, out connPoint);
     connPoint.Advise(handler, out cookie);
 }
    /// <summary>
    /// Start the IR Server plugin.
    /// </summary>
    public override void Start()
    {
      LoadSettings();
      X10Inter = new X10Interface();
      if (X10Inter == null)
        throw new InvalidOperationException("Failed to start X10 interface");

      // Bind the interface using a connection point
      icpc = (IConnectionPointContainer)X10Inter;
      Guid IID_InterfaceEvents = typeof(_DIX10InterfaceEvents).GUID;
      icpc.FindConnectionPoint(ref IID_InterfaceEvents, out icp);
      icp.Advise(this, out cookie);
    }
Example #36
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 IConnectionPointContainer)
                {
                    cpc = (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)*/);
                    }
                    throw ex;
                }

#if DEBUG
                callStack = Environment.StackTrace;
                this.eventInterface = eventInterface;
#endif
            }
Example #37
0
File: EPG.cs Project: dgis/CodeTV
 public void RegisterEvent(IConnectionPointContainer bdaTIFConnectionPointContainer)
 {
     //http://msdn.microsoft.com/en-us/library/ms779696
     try
     {
         Guid IID_IGuideDataEvent = typeof(IGuideDataEvent).GUID;
         bdaTIFConnectionPointContainer.FindConnectionPoint(ref IID_IGuideDataEvent, out this.guideDataEventConnectionPoint);
         if (this.guideDataEventConnectionPoint != null)
         {
             guideDataEventConnectionPoint.Advise(this, out this.guideDataEventCookie);
         }
     }
     catch (Exception ex)
     {
         // CONNECT_E_CANNOTCONNECT = 0x80040200
         Trace.WriteLineIf(trace.TraceError, ex.ToString());
     }
 }
Example #38
0
    public void Init()
    {
      using (Settings xmlreader = new MPSettings())
      {
        _controlEnabled = xmlreader.GetValueAsBool("remote", "X10", false);
        _x10Medion = xmlreader.GetValueAsBool("remote", "X10Medion", false);
        _x10Ati = xmlreader.GetValueAsBool("remote", "X10ATI", false);
        _x10Firefly = xmlreader.GetValueAsBool("remote", "X10Firefly", false);
        _logVerbose = xmlreader.GetValueAsBool("remote", "X10VerboseLog", false);
        _x10UseChannelControl = xmlreader.GetValueAsBool("remote", "X10UseChannelControl", false);
        _x10Channel = xmlreader.GetValueAsInt("remote", "X10Channel", 0);
      }

      //Setup the X10 Remote
      try
      {
        if (X10Inter == null)
        {
          try
          {
            X10Inter = new X10Interface();
          }
          catch (COMException)
          {
            Log.Info("X10 debug: Could not get interface");
            _remotefound = false;
            return;
          }
          _remotefound = true;

          //Bind the interface using a connection point

          icpc = (IConnectionPointContainer)X10Inter;
          Guid IID_InterfaceEvents = typeof (_DIX10InterfaceEvents).GUID;
          icpc.FindConnectionPoint(ref IID_InterfaceEvents, out icp);
          icp.Advise(this, out cookie);
        }
      }
      catch (COMException cex)
      {
        Log.Info("X10 Debug: Com error - " + cex.ToString());
      }

      if (_inputHandler == null)
      {
        if (_controlEnabled)
        {
          if (_x10Medion)
          {
            _inputHandler = new InputHandler("Medion X10");
          }
          else if (_x10Ati)
          {
            _inputHandler = new InputHandler("ATI X10");
          }
          else if (_x10Firefly)
          {
            _inputHandler = new InputHandler("Firefly X10");
          }
          else
          {
            _inputHandler = new InputHandler("Other X10");
          }
        }
        else
        {
          return;
        }

        if (!_inputHandler.IsLoaded)
        {
          _controlEnabled = false;
          Log.Info("X10: Error loading default mapping file - please reinstall MediaPortal");
          return;
        }

        if (_logVerbose)
        {
          if (_x10Medion)
          {
            Log.Info("X10Remote: Start Medion");
          }
          else if (_x10Ati)
          {
            Log.Info("X10Remote: Start ATI");
          }
          else if (_x10Firefly)
          {
            Log.Info("X10Remote: Start Firefly");
          }
          else
          {
            Log.Info("X10Remote: Start Other");
          }
        }
      }
    }
        public SafeConnectionPointCookie(IConnectionPointContainer target, object sink, Guid eventId)
            : base(true)
        {
            Verify.IsNotNull(target, "target");
            Verify.IsNotNull(sink, "sink");
            Verify.IsNotDefault(eventId, "eventId");

            handle = IntPtr.Zero;

            IConnectionPoint cp = null;
            try
            {
                int dwCookie;
                target.FindConnectionPoint(ref eventId, out cp);
                cp.Advise(sink, out dwCookie);
                if (dwCookie == 0)
                {
                    throw new InvalidOperationException("IConnectionPoint::Advise returned an invalid cookie.");
                }
                handle = new IntPtr(dwCookie);
                _cp = cp;
                cp = null;
            }
            finally
            {
                Utility.SafeRelease(ref cp);
            }
        }
        public ManipulationEvents(IConnectionPointContainer connectionPointContainer, IManipulationEvents callBack)
        {
            _callBack = callBack;

            Guid manipulationEventsId = new Guid(IIDGuid.IManipulationEvents);
            connectionPointContainer.FindConnectionPoint(ref manipulationEventsId, out _connectionPoint);
            _connectionPoint.Advise(this, out _cookie);
        }