Exemple #1
0
 public static void InitializeServices(Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleProvider)
 {
     if (oleProvider == null)
     {
         throw new ArgumentNullException("oleProvider");
     }
     if (!servicesInitialized)
     {
         try
         {
             serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(oleProvider);
             container       = new System.ComponentModel.Design.ServiceContainer(serviceProvider);
             componentHost   = new VsShellComponentModelHost(oleProvider);
             catalogProvider = new VsCatalogProvider(componentHost);
             globalCatalog   = catalogProvider.GetCatalog("Microsoft.VisualStudio.Default");
             if (globalCatalog == null)
             {
                 throw new InvalidOperationException("T4 Composition services initialization error: Failed to get default composition catalog.");
             }
             composition = VsCompositionContainer.Create(globalCatalog);
             composition.ComposeExportedValue <SVsServiceProvider>(new VsServiceProviderWrapper(container));
             localComponentModel = new LocalComponentModel(catalogProvider, composition);
             container.AddService(typeof(SComponentModel), localComponentModel);
             container.AddService(typeof(IComponentModel), localComponentModel);
             AppDomain.CurrentDomain.ProcessExit  += new EventHandler(Microsoft.VisualStudio.TextTemplating.VSHost.CompositionServices.CurrentDomain_Cleanup);
             AppDomain.CurrentDomain.DomainUnload += new EventHandler(Microsoft.VisualStudio.TextTemplating.VSHost.CompositionServices.CurrentDomain_Cleanup);
             servicesInitialized = true;
         }
         catch (Exception)
         {
             CleanupFields();
             throw;
         }
     }
 }
Exemple #2
0
 private static void CleanupFields()
 {
     if (container != null)
     {
         container.Dispose();
         container = null;
     }
     if (serviceProvider != null)
     {
         serviceProvider.Dispose();
         serviceProvider = null;
     }
     if (composition != null)
     {
         composition.Dispose();
         composition = null;
     }
     if (globalCatalog != null)
     {
         globalCatalog.Dispose();
         globalCatalog = null;
     }
     componentHost       = null;
     catalogProvider     = null;
     localComponentModel = null;
 }