Esempio n. 1
0
        //==========================================================================================
        // Constructors
        //==========================================================================================
        /// <summary>
        /// Initializes a new instance of the <see cref="Hierarchy"/> class.
        /// </summary>
        public Hierarchy()
        {
            // Listen to the Tracer's WritingSummary event so that we can write our summary information.
            Tracer.WritingSummarySection += new EventHandler(WriteSummary);

            this.serviceProvider = Package.Instance.Context.ServiceProvider;
        }
Esempio n. 2
0
        //==========================================================================================
        // Constructors
        //==========================================================================================
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageContext"/> class.
        /// </summary>
        /// <param name="serviceProvider">
        /// The <see cref="ServiceProvider"/> instance to use for getting services from the environment.
        /// </param>
        public PackageContext(ServiceProvider serviceProvider)
        {
            Tracer.VerifyNonNullArgument(serviceProvider, "serviceProvider");
            this.serviceProvider = serviceProvider;

            // Get an IUIHostLocale instance and Visual Studio's locale
            IUIHostLocale hostLocale = this.GetService(typeof(SUIHostLocale)) as IUIHostLocale;
            Tracer.Assert(hostLocale != null, "Cannot get Visual Studio's locale. Defaulting to current thread's locale.");
            int lcid = Thread.CurrentThread.CurrentUICulture.LCID;
            if (hostLocale != null)
            {
                uint lcidUnsigned;
                int hr = hostLocale.GetUILocale(out lcidUnsigned);
                if (NativeMethods.Succeeded(hr))
                {
                    lcid = (int)lcidUnsigned;
                }
                else
                {
                    Tracer.Fail("Cannot get Visual Studio's locale. Defaulting to current thread's locale.");
                }
            }

            // Initialize our helpers
            this.managedResources = this.CreateManagedResourceManager();
            this.nativeResources = new NativeResourceManager(lcid);
            this.settings = this.CreatePackageSettings(this.ServiceProvider);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageSettings"/> class.
        /// </summary>
        /// <param name="serviceProvider">The <see cref="ServiceProvider"/> to use.</param>
        /// <param name="machineSettingsRegistryKey">
        /// Relative registry path to machine-level settings. The path is relative to the Visual Studio registry root.
        /// </param>
        protected PackageSettings(ServiceProvider serviceProvider, string machineSettingsRegistryKey)
        {
            Tracer.VerifyNonNullArgument(serviceProvider, "serviceProvider");

            // Read in the Visual Studio registry root.
            IVsShell vsShell = serviceProvider.GetVsShell(classType, Tracer.ConstructorMethodName);
            object rootPathObj;
            int hr = vsShell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out rootPathObj);
            this.visualStudioRegistryRoot = (string)rootPathObj;
            this.machineRootPath = this.RegistryPathCombine(this.visualStudioRegistryRoot, machineSettingsRegistryKey);

            // Initialize all of the machine settings.
            this.traceLevel = new MachineSettingEnum(this.MachineRootPath, KeyNames.TraceLevel, Tracer.Level.Critical, typeof(Tracer.Level));
        }
Esempio n. 4
0
        int IVsUIHierarchy.SetSite(IOleServiceProvider psp)
        {
            try
            {
                Tracer.VerifyNonNullArgument(psp, "psp");

                // We don't want to create another service provider if the argument is a pointer
                // to the one currently stored in the PackageContext (we already initialized our
                // pointer to the PackageContext's service provider in the constructor).
                if (!Object.ReferenceEquals(psp, this.serviceProvider))
                {
                    this.serviceProvider = new ServiceProvider(psp);
                }
            }
            catch (Exception e)
            {
                Tracer.Fail("Unexpected exception: {0}\n{1}", e.Message, e);
                throw;
            }

            return NativeMethods.S_OK;
        }
 //==========================================================================================
 // Constructors
 //==========================================================================================
 /// <summary>
 /// Initializes a new instance of the <see cref="RunningDocumentTable"/> class.
 /// </summary>
 /// <param name="serviceProvider">The <see cref="ServiceProvider"/> to use for getting services from the environment.</param>
 public RunningDocumentTable(ServiceProvider serviceProvider)
 {
     Tracer.VerifyNonNullArgument(serviceProvider, "serviceProvider");
     this.serviceProvider = serviceProvider;
 }
Esempio n. 6
0
 /// <summary>
 /// Cleans up managed and native resources.
 /// </summary>
 /// <param name="disposing">Indicates whether this is being called from the finalizer.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.serviceProvider != null)
         {
             this.serviceProvider.Dispose();
             this.serviceProvider = null;
         }
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Gives subclasses a chance to create a new strongly-typed <see cref="PackageSettings"/> instance.
 /// </summary>
 /// <param name="serviceProvider">The <see cref="ServiceProvider"/> to use.</param>
 /// <returns>A new <see cref="PackageSettings"/> instance.</returns>
 protected virtual PackageSettings CreatePackageSettings(ServiceProvider serviceProvider)
 {
     return new PackageSettings(serviceProvider);
 }
 /// <summary>
 /// Creates a new strongly-typed instance of the <see cref="WixPackageSettings"/> class.
 /// </summary>
 /// <param name="serviceProvider">The <see cref="ServiceProvider"/> to use.</param>
 /// <returns>A new <see cref="WixPackageSettings"/> instance.</returns>
 protected override PackageSettings CreatePackageSettings(ServiceProvider serviceProvider)
 {
     return new WixPackageSettings(serviceProvider);
 }
Esempio n. 9
0
 //==========================================================================================
 // Constructors
 //==========================================================================================
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageSettings"/> class.
 /// </summary>
 /// <param name="serviceProvider">The <see cref="ServiceProvider"/> to use.</param>
 public PackageSettings(ServiceProvider serviceProvider)
     : this(serviceProvider, MachineSettingsRegKey)
 {
 }
Esempio n. 10
0
 //==========================================================================================
 // Constructors
 //==========================================================================================
 /// <summary>
 /// Initializes a new instance of the <see cref="WixPackageContext"/> class.
 /// </summary>
 /// <param name="serviceProvider">
 /// The <see cref="ServiceProvider"/> instance to use for getting services from the environment.
 /// </param>
 public WixPackageContext(ServiceProvider serviceProvider)
     : base(serviceProvider)
 {
 }
 //==========================================================================================
 // Constructors
 //==========================================================================================
 /// <summary>
 /// Initializes a new instance of the <see cref="WixPackageSettings"/> class.
 /// </summary>
 /// <param name="serviceProvider">The <see cref="ServiceProvider"/> to use.</param>
 public WixPackageSettings(ServiceProvider serviceProvider)
     : base(serviceProvider, MachineSettingsRegKey)
 {
     // Initialize all of the machine settings.
     this.toolsDirectory = new MachineSettingString(this.MachineRootPath, KeyNames.ToolsDirectory, System.String.Empty);
 }
Esempio n. 12
0
 //==========================================================================================
 // Methods
 //==========================================================================================
 /// <summary>
 /// Creates a new type-specific <see cref="WixPackageContext"/> object.
 /// </summary>
 /// <param name="serviceProvider">The <see cref="ServiceProvider"/> instance to use for getting services from the environment.</param>
 /// <returns>A new <see cref="WixPackageContext"/> object.</returns>
 protected override PackageContext CreatePackageContext(ServiceProvider serviceProvider)
 {
     return new WixPackageContext(serviceProvider);
 }
Esempio n. 13
0
 /// <summary>
 /// Provides a way for subclasses to create a new type-specific <see cref="PackageContext"/> object.
 /// </summary>
 /// <param name="serviceProvider">The <see cref="ServiceProvider"/> instance to use for getting services from the environment.</param>
 /// <returns>A new <see cref="PackageContext"/> object.</returns>
 protected virtual PackageContext CreatePackageContext(ServiceProvider serviceProvider)
 {
     return new PackageContext(serviceProvider);
 }
Esempio n. 14
0
        /// <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;
        }