Beispiel #1
0
        /// <summary>
        /// Cleans up the COM object references.
        /// </summary>
        /// <param name="disposing">
        /// <see langword="true"/> if this was called from the
        /// <see cref="IDisposable"/> interface.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                _owner             = null;
                _unmappedEventKeys = null;

                if (null != _events)
                {
                    _events.Dispose();
                    _events = null;
                }
            }

            if (null != _connectionPoint)
            {
                if (0 != _connectionCookie)
                {
                    try
                    {
                        _connectionPoint.Unadvise(_connectionCookie);
                        _connectionCookie = 0;
                    }
                    catch { }
                }

                while (Marshal.ReleaseComObject(_connectionPoint) > 0)
                {
                    ;
                }
                _connectionPoint = null;
            }
        }
Beispiel #2
0
        public int OnLoadCompleted(int fReload)
        {
            // Set language service ID as early as possible, since it may change content type of the buffer,
            // e.g. in a weird scenario when someone does "Open With X Editor" on an Y file. Calling this
            // will change content type to the one language service specifies instead of the default one for
            // the file extension, and will ensure that correct editor factory is used.
            _textLines.SetLanguageServiceID(ref _languageServiceGuid);
            var adapterService = _services.GetService <IVsEditorAdaptersFactoryService>();
            var diskBuffer     = adapterService.GetDocumentBuffer(_textLines);

            Debug.Assert(diskBuffer != null);

            try {
                var editorInstance = diskBuffer.GetService <IEditorViewModel>();
                if (editorInstance == null)
                {
                    var locator         = _services.GetService <IContentTypeServiceLocator>();
                    var instancefactory = locator.GetService <IEditorViewModelFactory>(diskBuffer.ContentType.TypeName);

                    Debug.Assert(instancefactory != null, "No editor factory found for the provided text buffer");
                    editorInstance = instancefactory.CreateEditorViewModel(diskBuffer);
                }

                Debug.Assert(editorInstance != null);
                adapterService.SetDataBuffer(_textLines, editorInstance.ViewBuffer.As <ITextBuffer>());
            } finally {
                cp.Unadvise(cookie);
                cookie     = 0;
                _textLines = null;
                _trackers.Remove(this);
            }
            return(VSConstants.S_OK);
        }
Beispiel #3
0
        private void CleanUp()
        {
            if (_sink != null)
            {
                _sink.ProjectActivated -= _sink_ProjectActivated;
                _sink.ProjectRemoved   -= _sink_ProjectRemoved;
                _sink.ProjectAdded     -= _sink_ProjectAdded;
            }

            if (_projectsEventsConnectionPoint != null)
            {
                _projectsEventsConnectionPoint.Unadvise(_projectsEventsCookie);
            }

            if (_ctxMenu != null)
            {
                _ctxMenu.Dispose();
            }

            if (_menu != null)
            {
                _menu.Dispose();
            }

            if (_app != null)
            {
                _app.Dispose();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
                if (cookieTextLineEvents != 0)
                {
                    textLinesEventsConnectionPoint.Unadvise(cookieTextLineEvents);
                }
                if (cookieTextViewEvents != 0)
                {
                    textViewEventsConnectionPoint.Unadvise(cookieTextViewEvents);
                }

                if (viewAdapter != null)
                {
                    ((IVsWindowPane)viewAdapter).ClosePane();
                }
            }
            base.Dispose(disposing);
        }
        protected override void Dispose(bool disposing)
        {
            // Remove solution event notifications.
            IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution));

            try
            {
                solution.UnadviseSolutionEvents(solutionEventCookie);
            }
            catch
            {
            }

            // Remove text manager event notifications.
            if (tmConnectionPoint != null)
            {
                tmConnectionPoint.Unadvise(tmConnectionCookie);
                tmConnectionPoint = null;
            }

            // Remove running document table (RDT) event notifications.
            // Ignore any errors that might occur since we're shutting down.
            IVsRunningDocumentTable rdt = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable));

            try
            {
                rdt.UnadviseRunningDocTableEvents(rdtEventCookie);
            }
            catch (Exception)
            {
            }

            // Forward call to the base class.
            base.Dispose(disposing);
        }
Beispiel #6
0
        private void InternalRemove(bool force)
        {
            if (!(callbackConnectionPoint == null))
            {
                if (callbackCookie != 0)
                {
                    callbackConnectionPoint.Unadvise(callbackCookie);
                    callbackCookie = 0;
                }
                int rc = Marshal.ReleaseComObject(callbackConnectionPoint);
                callbackConnectionPoint = null;
            }

            if (!(opcGroupObject == null))
            {
                int rc = Marshal.ReleaseComObject(opcGroupObject);
                opcGroupObject = null;
            }

            if (!(parentServer == null))
            {
                if (!statePublic)
                {
                    parentServer.RemoveGroup(stateHandleServer, force);
                }
                parentServer = null;
            }

            stateHandleServer = 0;
        }
Beispiel #7
0
        /// <summary>
        /// Release event binding
        /// </summary>
        private void RemoveEventBinding(bool removeFromList)
        {
            if (_connectionCookie != 0)
            {
                try
                {
                    _connectionPoint.Unadvise(_connectionCookie);
                    Marshal.ReleaseComObject(_connectionPoint);
                }
                catch (System.Runtime.InteropServices.COMException throwedException)
                {
                    _eventClass.Console.WriteException(throwedException);
                    ; // RPC server is disconnected or dead
                }
                catch (Exception throwedException)
                {
                    _eventClass.Console.WriteException(throwedException);
                    throw new NetOfficeCOMException("An error occured while release event binding.", throwedException);
                }

                _connectionPoint  = null;
                _connectionCookie = 0;

                if (removeFromList)
                {
                    _pointList.Remove(this);
                }
            }
        }
Beispiel #8
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_isDisposed)
            {
                if (disposing)
                {
                    if (_cookie != -1 && _pConnectionPoint != null)
                    {
                        _pConnectionPoint.Unadvise(_cookie);
                        _pConnectionPoint = null;
                        _cookie           = -1;
                    }
                }

                if (_pConnectionPointContainer != null)
                {
                    // there's an implicit QueryInterface cast when calling
                    //_pConnectionPointContainer = _myObject as IConnectionPointContainer;
                    int refCount = Marshal.ReleaseComObject(_pConnectionPointContainer);
                    System.Diagnostics.Trace.WriteLine(string.Format("Reference count for _pConnectionPointContainer is {0}", refCount));
                    _pConnectionPointContainer = null;
                }

                if (_myObject != null)
                {
                    // when we're disposing of instance we should also dispose of the source object
                    int refCount = Marshal.ReleaseComObject(_myObject);
                    System.Diagnostics.Trace.WriteLine(string.Format("Reference count for _myObject is {0}", refCount));
                    _myObject = null;
                }

                _isDisposed = true;
            }
        }
        public void DoTests()
        {
            Config();

            try
            {
                int hr = m_pService.Fire(Guid.NewGuid()); // Can be any guid
                DsError.ThrowExceptionForHR(hr);

                // Wait for it
                System.Threading.Thread.Sleep(1000);

                // See if it fired
                Debug.Assert(m_Fired, "Didn't Fire");
            }
            finally
            {
                if (m_pService != null)
                {
                    IConnectionPoint icp = m_pService as IConnectionPoint;
                    icp.Unadvise(m_Cookie);
                    Marshal.ReleaseComObject(m_pService);
                }
                if (m_ifg != null)
                {
                    Marshal.ReleaseComObject(m_ifg);
                }
            }
        }
        protected override void Dispose(bool disposing)
        {
            IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution));

            try {
                solution.UnadviseSolutionEvents(solutionEventCookie);
            }
// ReSharper disable EmptyGeneralCatchClause
            catch {}
// ReSharper restore EmptyGeneralCatchClause
            base.Dispose(disposing);

            // Remove text manager event notifications.
            if (tmConnectionPoint != null)
            {
                tmConnectionPoint.Unadvise(tmConnectionCookie);
                tmConnectionPoint = null;
            }

            // Remove running document table (RDT) event notifications.
            // Ignore any errors that might occur since we're shutting down.
            IVsRunningDocumentTable rdt = (IVsRunningDocumentTable)GetService(typeof(SVsRunningDocumentTable));

            if (rdt != null)
            {
                try {
                    rdt.UnadviseRunningDocTableEvents(rdtEventCookie);
                } catch (Exception) {}
            }
        }
Beispiel #11
0
 protected virtual void Dispose(bool disposing)
 {
     Debug.WriteLine("NAVClient.Dispose(" + disposing.ToString() + ") " + this.myId);
     if (disposing) //managed resources release
     {
         if (watchers != null)
         {
             foreach (FileSystemWatcher watcher in watchers)
             {
                 watcher.Dispose();
             }
             watchers = null;
         }
     }
     try
     {
         if ((cookie != 0) && (CP != null))
         {
             CP.Unadvise(cookie);
             cookie = 0;
         }
         if (timerCheckWindows != null)
         {
             timerCheckWindows.Dispose();
             timerCheckWindows = null;
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("Release:" + e.Message);
     }
 }
Beispiel #12
0
        public void Dispose()
        {
            if (_sink != null)
            {
                _sink.ProjectAdded     -= _sink_ProjectAdded;
                _sink.ProjectRemoved   -= _sink_ProjectRemoved;
                _sink.ProjectActivated -= _sink_ProjectActivated;
                _sink.ProjectRenamed   -= _sink_ProjectRenamed;
                _sink = null;
            }

            if (_projectsEventsConnectionPoint != null)
            {
                _projectsEventsConnectionPoint.Unadvise(_projectsEventsCookie);
            }

            foreach (var item in _componentsEventsSinks)
            {
                item.Value.ComponentActivated -= ComponentsSink_ComponentActivated;
                item.Value.ComponentAdded     -= ComponentsSink_ComponentAdded;
                item.Value.ComponentReloaded  -= ComponentsSink_ComponentReloaded;
                item.Value.ComponentRemoved   -= ComponentsSink_ComponentRemoved;
                item.Value.ComponentRenamed   -= ComponentsSink_ComponentRenamed;
                item.Value.ComponentSelected  -= ComponentsSink_ComponentSelected;
            }

            foreach (var item in _componentsEventsConnectionPoints)
            {
                item.Value.Item1.Unadvise(item.Value.Item2);
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            Utility.LogInspectorEvent(LogType.Diagnostic, (string.Format("{0}{1}", new StackTrace().GetFrame(0).GetMethod().Name, System.Environment.NewLine)));
            if (!_isDisposed)
            {
                if (disposing)
                {
                    if (_cookie != -1 && _pConnectionPoint != null)
                    {
                        _pConnectionPoint.Unadvise(_cookie);
                        _pConnectionPoint = null;
                        _cookie           = -1;
                    }
                }

                if (_pConnectionPointContainer != null)
                {
                    // there's an implicit QueryInterface cast when calling
                    //_pConnectionPointContainer = _myObject as IConnectionPointContainer;
                    int refCount = Marshal.ReleaseComObject(_pConnectionPointContainer);
                    Utility.LogInspectorEvent(LogType.Diagnostic, (string.Format("Reference count for _pConnectionPointContainer  in {0} is {1}{2}", this.GetType().Name, refCount, System.Environment.NewLine)));
                    _pConnectionPointContainer = null;
                }

                if (_myObject != null)
                {
                    // when we're disposing of instance we should also dispose of the source object
                    int refCount = Marshal.ReleaseComObject(_myObject);
                    Utility.LogInspectorEvent(LogType.Diagnostic, (string.Format("Reference count for _myObject  in {0} is {1}{2}", this.GetType().Name, refCount, System.Environment.NewLine)));
                    _myObject = null;
                }

                _isDisposed = true;
            }
        }
Beispiel #14
0
 public void Dispose()
 {
     if (_connectionPoint != null)
     {
         _connectionPoint.Unadvise(_cookie);
     }
 }
Beispiel #15
0
        public void Disconnect()
        {
            if (m_ShutdownPoint != null)
            {
                if (m_ShutdownCookie != 0)
                {
                    m_ShutdownPoint.Unadvise(m_ShutdownCookie);
                    m_ShutdownCookie = 0;
                }
                Marshal.ReleaseComObject(m_ShutdownPoint);
                m_ShutdownPoint = null;
            }

            m_PointContainer = null;
            m_IfBrowse       = null;
            m_IfItmProps     = null;
            m_IfCommon       = null;
            m_IfServer       = null;

            if (m_OPCServerObj != null)
            {
                Marshal.ReleaseComObject(m_OPCServerObj);
                m_OPCServerObj = null;
            }
        }
Beispiel #16
0
        public int OnLoadCompleted(int fReload)
        {
            _connectionPoint.Unadvise(_cookie);
            _action();

            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Terminates an advisory connection previously established between a connection point object and a client's sink.
        /// </summary>
        /// <typeparam name="TInterface">Interface type of the interface whose connection point object is being requested to be removed.</typeparam>
        /// <param name="container">An object that implements the IConnectionPointContainer inferface.</param>
        public void UnadviseSink <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];
                        cp.Unadvise(cookie);
                        _connectionPointDictionary.Remove(cp);
                    }
                }
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(this);
                }
            }
        }
Beispiel #18
0
 public void Dispose()
 {
     try
     {
         if (_opcServer != null)
         {
             foreach (var grp in _groups)
             {
                 _opcServer.RemoveGroup(grp.Key, true);
                 grp.Value.Dispose();
             }
             _groups.Clear();
         }
         if (_shutDownPoint != null)
         {
             if (_shutDownCookie != 0)
             {
                 _shutDownPoint.Unadvise(_shutDownCookie);
             }
             Marshal.ReleaseComObject(_shutDownPoint);
         }
         if (_opcServerObj != null)
         {
             Marshal.ReleaseComObject(_opcServerObj);
         }
     }
     catch (Exception e)
     {
         ShutdownRequest(e.Message);
     }
     _opcServerObj   = null;
     _opcServer      = null;
     _shutDownPoint  = null;
     _shutDownCookie = 0;
 }
Beispiel #19
0
 public bool StopMonitoringConnection()
 {
     try
     {
         if (!_isMonitoring)
         {
             return(true);
         }
         _connectionPoint.Unadvise(_cookie);
         _isMonitoring = false;
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
            public int OnLoadCompleted(int fReload) {
                _cp.Unadvise(_cookie);

                Guid langSvcGuid = typeof(NodejsLanguageInfo).GUID;
                _textLines.SetLanguageServiceID(ref langSvcGuid);
                
                return VSConstants.S_OK;
            }
Beispiel #21
0
 public void Dispose()
 {
     if (_connectionCookie > 0)
     {
         _connectionPoint.Unadvise(_connectionCookie);
         _connectionCookie = 0;
     }
 }
 /// <summary>
 /// Release the connection point to the OUT Endpoint if one has been established.
 /// </summary>
 public void ReleaseConnectionPoint()
 {
     if (m_piConnectionPoint != null)
     {
         m_piConnectionPoint.Unadvise(m_dwConnectionCookie);
         m_dwConnectionCookie = 0;
     }
 }
Beispiel #23
0
 /// <summary>
 /// Decrements the reference count and closes the connection if no more references.
 /// </summary>
 public int Unadvise()
 {
     if (--refs_ == 0)
     {
         server_.Unadvise(cookie_);
     }
     return(refs_);
 }
            public int OnLoadCompleted(int fReload)
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                _connectionPoint.Unadvise(_cookie);
                _textLines.SetLanguageServiceID(ref _languageServiceId);

                return(VSConstants.S_OK);
            }
Beispiel #25
0
 public void Dispose()
 {
     if (m_AdviseCookie != 0)
     {
         m_ConnectionPoint.Unadvise(m_AdviseCookie);
         m_AdviseCookie = 0;
     }
 }
Beispiel #26
0
 /// <summary>
 /// Decrements the reference count and closes the connection if no more references.
 /// </summary>
 public int Unadvise()
 {
     if (--m_refs == 0)
     {
         m_server.Unadvise(m_cookie);
     }
     return(m_refs);
 }
Beispiel #27
0
        /*------------------------------------------------------
        *  Disconnect OPC Server
        *
        *  (ret)   True    OK
        *                  False   NG
        *  ------------------------------------------------------*/
        public bool Disconnect()
        {
            if (m_OPCServer == null)
            {
                return(true);
            }

            int ret;

            try
            {
                Unadvise();
                if (m_OPCGroup != null)
                {
                    ret        = Marshal.ReleaseComObject(m_OPCGroup);
                    m_OPCGroup = null;
                }
                if (m_OPCGroup2 != null)
                {
                    ret         = Marshal.ReleaseComObject(m_OPCGroup2);
                    m_OPCGroup2 = null;
                }
                if (m_OPCConnPoint != null)
                {
                    ret            = Marshal.ReleaseComObject(m_OPCConnPoint);
                    m_OPCConnPoint = null;
                }

                // 2011/11/14 シャットダウンイベントを受けれるようにする	(
                if (m_iShutdownConnectionCookie != 0)
                {
                    m_OpcShutdownConnectionPoint.Unadvise(m_iShutdownConnectionCookie);
                }
                m_iShutdownConnectionCookie = 0;
                if (m_OpcShutdownConnectionPoint != null)
                {
                    Marshal.ReleaseComObject(m_OpcShutdownConnectionPoint);
                    m_OpcShutdownConnectionPoint = null;
                }
                // 2011/11/14 シャットダウンイベントを受けれるようにする	)

                if (m_iServerGroup != 0)                        // 06/10/19 Fixed the timing of 'RemoveGroup'.
                {                                               //
                    m_OPCServer.RemoveGroup(m_iServerGroup, 0); //
                    m_iServerGroup = 0;                         //
                }                                               //
                ret         = Marshal.ReleaseComObject(m_OPCServer);
                m_OPCServer = null;
                m_bConnect  = false;
                return(true);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString(), "Disconnect");
                m_bConnect = false;
                return(false);
            }
        }
Beispiel #28
0
 /// <summary>
 /// Stop the IR Server plugin.
 /// </summary>
 public override void Stop()
 {
     if (X10Inter != null)
     {
         icp.Unadvise(cookie);
         icpc     = null;
         X10Inter = null;
     }
 }
 public void Dispose()
 {
     if (cookie != -1)
     {
         connPoint.Unadvise(cookie);
     }
     cookie  = -1;
     handler = null;
 }
Beispiel #30
0
 public void RemoveConnection()
 {
     if (m_Cookie != 0)
     {
         m_oConnectionPoint.Unadvise(m_Cookie);
         m_oConnectionPoint = null;
         m_Cookie           = 0;
     }
 }