ShellSettingsManager.cs :  » Development » StyleCop » Microsoft » VisualStudio » Shell » Settings » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » StyleCop 
StyleCop » Microsoft » VisualStudio » Shell » Settings » ShellSettingsManager.cs
//------------------------------------------------------------------------------
// <copyright file="SettingsManager.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

namespace Microsoft.VisualStudio.Shell.Settings{
    using System;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.Shell.Interop;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using Microsoft.VisualStudio.Settings;

    /// <summary>
    /// This is the gateway class to reach for the settings stored inside the Visual Studio. It provides two basic
    /// functionality. It allows to search for properties and collections inside the scopes. It hands the 
    /// <see cref="SettingsScope"/> and <see cref="WritableSettingsStore"/> classes for further manipulation of the 
    /// collections and properties within the scopes. This class implements the <see cref="IDisposable"/> pattern 
    /// hence it needs to be disposed after it is no longer necessary.
    /// </summary>
    [CLSCompliant(false)] // Methods of this class have enumeration return values
    public sealed class ShellSettingsManager : SettingsManager
    {        
        /// <summary>
        /// Constructor for the SettingsManager class. It requires Service Provider to reach IVsSettingsManager
        /// which is the interop COM interface of the service that provides the Settings related functionalities.
        /// </summary>
        /// <param name="serviceProvider">Service provider of the VS.</param>
        public ShellSettingsManager(IServiceProvider serviceProvider)
        {
            HelperMethods.CheckNullArgument(serviceProvider, "serviceProvider");

            this.settingsManager = serviceProvider.GetService(typeof(SVsSettingsManager)) as IVsSettingsManager;
            if (this.settingsManager == null)
            {
                throw new NotSupportedException(typeof(SVsSettingsManager).FullName);
            }
        }

        /// <summary>
        /// Outputs the scopes that contain the given collection. If more than one scope contains the collection,
        /// the corresponding bit flags of those scopes are set.
        /// </summary>
        /// <param name="collectionPath">Path of the collection to be searched.</param>
        /// <returns>Enclosing scopes.</returns>
        public override EnclosingScopes GetCollectionScopes(string collectionPath)
        {
            HelperMethods.CheckNullArgument(collectionPath, "collectionPath");

            uint scopes;
            int hr = this.settingsManager.GetCollectionScopes(collectionPath, out scopes);
            Marshal.ThrowExceptionForHR(hr);

            return (EnclosingScopes)scopes;
        }

        /// <summary>
        /// Outputs the scopes that contain the given property. If more than one scope contains the property,
        /// the corresponding bit flags of those scopes are set.
        /// </summary>
        /// <param name="collectionPath">Path of the collection of the property.</param>
        /// <param name="propertyName">Name of the property to be searched.</param>
        /// <returns>Enclosing scopes.</returns>
        public override EnclosingScopes GetPropertyScopes(string collectionPath, string propertyName)
        {
            HelperMethods.CheckNullArgument(collectionPath, "collectionPath");
            HelperMethods.CheckNullArgument(propertyName, "propertyName");

            uint scopes;
            int hr = this.settingsManager.GetPropertyScopes(collectionPath, propertyName, out scopes);
            Marshal.ThrowExceptionForHR(hr);            

            return (EnclosingScopes)scopes;
        }

        /// <summary>
        /// Provides the <see cref="SettingsStore"/> class for the requested scope which can be used for read-only 
        /// operations.
        /// </summary>
        /// <param name="scope">Requested scope.</param>
        /// <returns><see cref="SettingsStore"/> instance that can be used for accessing the scope.</returns>
        public override SettingsStore GetReadOnlySettingsStore(SettingsScope scope)
        {
            IVsSettingsStore settingsStore;
            int hr = this.settingsManager.GetReadOnlySettingsStore((uint)scope, out settingsStore);
            Marshal.ThrowExceptionForHR(hr);            

            return new ShellSettingsStore(settingsStore);
        }

        /// <summary>
        /// Provides the <see cref="WritableSettingsStore"/> class for the requested scope which can be used both for
        /// reading and writing.
        /// </summary>
        /// <param name="scope">Requested scope.</param>
        /// <exception cref="ArgumentException">If the given scope is not a writable one.</exception>
        /// <returns><see cref="WritableSettingsStore"/> instance that can be used for accessing the scope.</returns>
        public override WritableSettingsStore GetWritableSettingsStore(SettingsScope scope)
        {
            IVsWritableSettingsStore writableSettingsStore;
            int hr = this.settingsManager.GetWritableSettingsStore((uint)scope, out writableSettingsStore);
            Marshal.ThrowExceptionForHR(hr);
            
            return new ShellWritableSettingsStore(writableSettingsStore);
        }

        /// <summary>
        /// Returns the folder that Visual Studio uses for storing various cache, backup, template, etc. files
        /// </summary>
        /// <param name="folder">Requested folder.</param>        
        /// <returns>Full path of the requested folder.</returns>
        public override string GetApplicationDataFolder(ApplicationDataFolder folder)
        {
            string folderPath;
            int hr = this.settingsManager.GetApplicationDataFolder((uint)folder, out folderPath);
            Marshal.ThrowExceptionForHR(hr);

            return folderPath;
        }

        /// <summary>
        /// Returns the list of folders that Visual Studio uses for installing/discovering machine-wide extensions.
        /// </summary>
        /// <returns>List of extensions root paths.</returns>
        public override IEnumerable<string> GetCommonExtensionsSearchPaths()
        {
            uint arraySize;
            int hr = this.settingsManager.GetCommonExtensionsSearchPaths(0, null, out arraySize);
            Marshal.ThrowExceptionForHR(hr);

            string[] searchPaths = new string[arraySize];
            hr = this.settingsManager.GetCommonExtensionsSearchPaths((uint)searchPaths.Length, searchPaths, out arraySize);
            Marshal.ThrowExceptionForHR(hr);
            return searchPaths;
        }

        // Thunked interop COM interface.
        private IVsSettingsManager settingsManager;
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.