/// <include file='doc\DesignerPackage.uex' path='docs/doc[@for="DesignerPackage.SetSite"]/*' />
        /// <devdoc>
        ///     Overrides SetSite to create our editor factory.
        /// </devdoc>
        public override void SetSite(object site)
        {
            base.SetSite(site);

            // Now initialize our editor factory
            //
            editorFactory = new DesignerEditorFactory(site);

            // Initialize this thread's culture info with that of the shell's LCID
            //
            IUIHostLocale loc = (IUIHostLocale)GetService(typeof(IUIHostLocale));

            Debug.Assert(loc != null, "Unable to get IUIHostLocale, defaulting CLR designer to current thread LCID");
            if (loc != null)
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(loc.GetUILocale());
            }

            SystemEvents.DisplaySettingsChanged += new EventHandler(this.OnSystemSettingChanged);
            SystemEvents.InstalledFontsChanged  += new EventHandler(this.OnSystemSettingChanged);
            SystemEvents.UserPreferenceChanged  += new UserPreferenceChangedEventHandler(this.OnUserPreferenceChanged);

            // Initialize the ShellLicenseManagerService so it can listen to solution events.
            //
            GetService(typeof(ILicenseManagerService));
            Debug.Assert(licenseManagerService != null, "No license manager service available");

            // Wake up the toolbox service so it registers as a data provider
            //
            GetService(typeof(IToolboxService));
        }
        /// <include file='doc\DesignerPackage.uex' path='docs/doc[@for="DesignerPackage.Close"]/*' />
        /// <devdoc>
        ///     Overrides Close to clean up our editor factory.
        /// </devdoc>
        public override void Close()
        {
            SystemEvents.DisplaySettingsChanged -= new EventHandler(this.OnSystemSettingChanged);
            SystemEvents.InstalledFontsChanged  -= new EventHandler(this.OnSystemSettingChanged);
            SystemEvents.UserPreferenceChanged  -= new UserPreferenceChangedEventHandler(this.OnUserPreferenceChanged);

            if (editorFactory != null)
            {
                try {
                    editorFactory.Dispose();
                }
                catch (Exception e) {
                    Debug.Fail(e.ToString());
                }
                editorFactory = null;
            }

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

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

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

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

            #if PERFEVENTS
            if (performanceEvent != IntPtr.Zero)
            {
                NativeMethods.CloseHandle(performanceEvent);
                performanceEvent = IntPtr.Zero;
            }
            #endif

            base.Close();
        }