/// <summary> /// Reads the tracer settings from the registry. /// </summary> /// <param name="context">The <see cref="PackageContext"/> to use for the registry access.</param> private static void ReadRegistrySettings(PackageContext context) { level = context.Settings.TraceLevel; }
/// <summary> /// Cleans up managed and native resources. /// </summary> /// <param name="disposing">Indicates whether this is being called from the finalizer or from <see cref="Dispose()"/>.</param> protected virtual void Dispose(bool disposing) { if (disposing) { // Unregister our project types. if (this.projectCookie != 0) { IVsRegisterProjectTypes regProjTypes = (IVsRegisterProjectTypes)this.GetService(typeof(IVsRegisterProjectTypes)); if (regProjTypes != null) { int hr = regProjTypes.UnregisterProjectType(this.projectCookie); this.projectCookie = 0; Tracer.Assert(NativeMethods.Succeeded(hr), "Cannot unregister the project type {0}.", this.projectCookie); } } // Revoke all proffered services that we contain. if (this.services != null) { IProfferService ps = (IProfferService)this.GetService(typeof(IProfferService)); Hashtable services = this.services; this.services = null; foreach (object service in this.services.Values) { if (service is ProfferedService) { ProfferedService proffered = (ProfferedService)service; if (proffered.Cookie != 0 && ps != null) { // Unregister the proffered service from the system. int hr = ps.RevokeService(proffered.Cookie); Tracer.Assert(NativeMethods.Succeeded(hr), "Failed to unregister service {0}.", service.GetType().FullName); } } // Dispose the service if possible. if (service is IDisposable) { ((IDisposable)service).Dispose(); } } } if (this.context != null) { this.context.Dispose(); this.context = null; } } }
/// <summary> /// Initializes the VSPackage with a back pointer to the environment. This is the entry point /// for the Visual Studio package. /// </summary> /// <param name="sp"> /// Pointer to the <see cref="IOleServiceProvider"/> interface through which the /// VSPackage can query for services. /// </param> /// <returns>An HRESULT indicating the result of the call.</returns> int IVsPackage.SetSite(IOleServiceProvider sp) { if (this.Closed) { Tracer.Fail("We shouldn't have been called if we're being unloaded."); return NativeMethods.E_UNEXPECTED; } try { if (sp != null) { // If SetSite has been called more than once, it's an error. if (this.Context != null) { string message = this.Context.NativeResources.GetString(ResId.IDS_E_SITEALREADYSET, this.GetType().FullName); Tracer.Fail(message); throw new InvalidOperationException(message); } // Initialize the ServiceProvider and ourself. ServiceProvider contextServiceProvider = new ServiceProvider(sp); this.context = this.CreatePackageContext(contextServiceProvider); Tracer.Initialize(this.context); this.Initialize(); } else if (this.Context != null && this.Context.ServiceProvider != null) { this.Dispose(true); } } catch (Exception e) { Tracer.Fail("Unexpected exception: {0}\n{1}", e.Message, e); throw; } return NativeMethods.S_OK; }
public static void Initialize(PackageContext context) { if (initializationException == null) { ReadRegistrySettings(context); } else { string title = context.NativeResources.GetString(ResourceId.IDS_E_TRACELOG_CREATION_TITLE, LogPath); string message = context.NativeResources.GetString(ResourceId.IDS_E_TRACELOG_CREATION, initializationException.Message); context.ShowErrorMessageBox(title, message); } }