Esempio n. 1
0
        public virtual void Close()
        {
            if (this.site != null)
            {
                if (this.editorFactory != null)
                {
                    Guid editorGuid        = this.editorFactory.GetType().GUID;
                    IVsRegisterEditors vre = (IVsRegisterEditors)site.QueryService(VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
                    vre.UnregisterEditor(this.editorFactoryCookie);
                    this.editorFactory.Close();
                    this.editorFactory = null;
                }
                if (this.projectFactory != null)
                {
                    IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
                    if (rpt != null)
                    {
                        rpt.UnregisterProjectType(this.projectFactoryCookie);
                    }
                    this.projectFactoryCookie = 0;
                    this.projectFactory.Close();
                    this.projectFactory = null;
                }
            }
            foreach (ILanguageService svc in this.languageServices.Values)
            {
                svc.Done();
            }
            this.languageServices.Clear();

            if (this.componentID != 0)
            {
                this.componentManager.FRevokeComponent(this.componentID);
                this.componentID = 0;
            }
            this.componentManager = null;

            if (site != null)
            {
                site.Dispose();
            }
            this.site = null;
            GC.Collect();
        }
Esempio n. 2
0
        public virtual void SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site)
        {
            this.site          = new ServiceProvider(site);
            this.editorFactory = CreateEditorFactory();
            if (this.editorFactory != null)
            {
                this.editorFactory.SetSite(site);
                Guid editorGuid        = this.editorFactory.GetType().GUID;
                IVsRegisterEditors vre = (IVsRegisterEditors)this.site.QueryService(VsConstants.SID_SVsRegisterEditors, typeof(IVsRegisterEditors));
                vre.RegisterEditor(ref editorGuid, editorFactory, out this.editorFactoryCookie);
            }

            this.projectFactory = CreateProjectFactory();
            if (this.projectFactory != null)
            {
                this.projectFactory.SetSite(site);
                IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.QueryService(VsConstants.SID_IVsRegisterProjectTypes, typeof(IVsRegisterProjectTypes));
                if (rpt != null)
                {
                    Guid projectType = this.projectFactory.GetType().GUID;
                    rpt.RegisterProjectType(ref projectType, this.projectFactory, out this.projectFactoryCookie);
                }
            }

            uint lcid = VsShell.GetProviderLocale(this.site);

            languageServices = new Hashtable();
            string          thisPackage = "{" + this.GetType().GUID.ToString() + "}";
            ServiceProvider thisSite    = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider) this);

            ILocalRegistry3 localRegistry = (ILocalRegistry3)this.site.QueryService(VsConstants.SID_SLocalRegistry, typeof(ILocalRegistry3));
            string          root          = null;

            if (localRegistry != null)
            {
                localRegistry.GetLocalRegistryRoot(out root);
            }
            using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)) {
                if (rootKey != null)
                {
                    using (RegistryKey languages = rootKey.OpenSubKey("Languages\\Language Services")) {
                        if (languages != null)
                        {
                            foreach (string languageName in languages.GetSubKeyNames())
                            {
                                using (RegistryKey langKey = languages.OpenSubKey(languageName)) {
                                    object pkg = langKey.GetValue("Package");
                                    if (pkg is string && string.Compare((string)pkg, thisPackage, false) == 0)
                                    {
                                        object guid = langKey.GetValue(null);
                                        if (guid is string)
                                        {
                                            Guid langGuid = new Guid((string)guid);
                                            if (!this.languageServices.Contains(langGuid.ToString()))
                                            {
                                                ILanguageService svc = CreateLanguageService(ref langGuid);
                                                if (svc != null)
                                                {
                                                    svc.Init(thisSite, ref langGuid, lcid, GetFileExtensions(rootKey, (string)guid));
                                                    this.languageServices.Add(langGuid.ToString(), svc);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //register with ComponentManager for Idle processing
            this.componentManager = (IOleComponentManager)this.site.QueryService(VsConstants.SID_SOleComponentManager, typeof(IOleComponentManager));
            if (componentID == 0)
            {
                OLECRINFO[] crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)OLECRF.olecrfNeedIdleTime |
                                   (uint)OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal |
                                     (uint)OLECADVF.olecadvfRedrawOff |
                                     (uint)OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 1000;
                this.componentManager.FRegisterComponent(this, crinfo, out componentID);
            }
        }
Esempio n. 3
0
    public virtual int Close()  {
      if (this.site != null){
        if (this.editorFactory != null){
          Guid editorGuid = this.editorFactory.GetType().GUID;
          IVsRegisterEditors vre = (IVsRegisterEditors)site.GetService(typeof(SVsRegisterEditors));
          vre.UnregisterEditor(this.editorFactoryCookie);
          this.editorFactory.Close();
          this.editorFactory = null;
        }
        if (this.projectFactory != null){
          IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.GetService(typeof(IVsRegisterProjectTypes));
          if (rpt != null){
            rpt.UnregisterProjectType(this.projectFactoryCookie);          
          }
          this.projectFactoryCookie = 0;
          this.projectFactory.Close();
          this.projectFactory = null;
        }

      }
      foreach (ILanguageService svc in this.languageServices.Values){
        svc.Done();
      }
      this.languageServices.Clear();
      
      if (this.componentID != 0){
        this.componentManager.FRevokeComponent(this.componentID);
        this.componentID = 0;
      }
      this.componentManager = null;

      if (site != null) site.Dispose();
      this.site = null;
      GC.Collect();
      return 0;
    }
Esempio n. 4
0
    public virtual int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider site){

      this.site = new ServiceProvider(site);
      this.editorFactory = CreateEditorFactory();
      if (this.editorFactory != null){
        this.editorFactory.SetSite(site);
        Guid editorGuid = this.editorFactory.GetType().GUID;
        IVsRegisterEditors vre = (IVsRegisterEditors)this.site.GetService(typeof(SVsRegisterEditors));
        vre.RegisterEditor(ref editorGuid, editorFactory, out this.editorFactoryCookie);
      }

      this.projectFactory = CreateProjectFactory();
      if (this.projectFactory != null){
        this.projectFactory.SetSite(site);
        IVsRegisterProjectTypes rpt = (IVsRegisterProjectTypes)this.site.GetService(typeof(IVsRegisterProjectTypes));
        if (rpt != null){
          Guid projectType = this.projectFactory.GetType().GUID;
          rpt.RegisterProjectType(ref projectType, this.projectFactory, out this.projectFactoryCookie);          
        }
      }

      uint lcid = VsShell.GetProviderLocale(this.site);
      
      languageServices = new Hashtable();
      string thisPackage = "{"+this.GetType().GUID.ToString() + "}";
      ServiceProvider thisSite = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)this);

      ILocalRegistry3 localRegistry = (ILocalRegistry3)this.site.GetService(typeof(SLocalRegistry));
      string root = null;        
      if (localRegistry != null){
        localRegistry.GetLocalRegistryRoot(out root);
      }      
      using (RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(root)){
        if (rootKey != null){
          using (RegistryKey languages = rootKey.OpenSubKey("Languages\\Language Services")){
            if (languages != null){
              foreach (string languageName in languages.GetSubKeyNames()){
                using (RegistryKey langKey = languages.OpenSubKey(languageName)){
                  if (langKey != null){
                    object pkg = langKey.GetValue("Package");
                    if (pkg is string && string.Compare((string)pkg, thisPackage, true) == 0){
                      object guid = langKey.GetValue(null);
                      if (guid is string){
                        Guid langGuid = new Guid((string)guid);
                        if (!this.languageServices.Contains(langGuid.ToString())){
                          ILanguageService svc = this.CreateLanguageService(ref langGuid);
                          if (svc != null){
                            svc.Init(thisSite, ref langGuid, lcid, this.GetFileExtensions(rootKey, (string)guid));
                            this.languageServices.Add(langGuid.ToString(), svc);
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }

      //register with ComponentManager for Idle processing
      //this.componentManager = (IOleComponentManager)this.site.GetService(typeof(SOleComponentManager));
      this.componentManager = (IOleComponentManager)this.site.QueryService(typeof(SOleComponentManager).GUID, typeof(IOleComponentManager));
      if (componentID == 0){
        OLECRINFO[]   crinfo = new OLECRINFO[1];
        crinfo[0].cbSize   = (uint)Marshal.SizeOf(typeof(OLECRINFO));
        crinfo[0].grfcrf   = (uint)OLECRF.olecrfNeedIdleTime |
                              (uint)OLECRF.olecrfNeedPeriodicIdleTime; 
        crinfo[0].grfcadvf = (uint)OLECADVF.olecadvfModal |
                              (uint)OLECADVF.olecadvfRedrawOff |
                              (uint)OLECADVF.olecadvfWarningsOff;
        crinfo[0].uIdleTimeInterval = 1000;
        this.componentManager.FRegisterComponent(this, crinfo, out componentID);
      }
      return 0;
    }