예제 #1
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);
        }
예제 #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);
        }