Share via


IPreferencesService.GetPreferencesStore Method

Definition

Returns the preference store instance that is associated with the specified identifier.

Overloads

GetPreferencesStore(Guid)

Returns the preference store instance that is associated with the specified identifier, or creates a new empty store if a store does not already exist.

GetPreferencesStore(Guid, PreferencesStore)

Returns the preference store instance, if one exists, that is associated with the specified identifier.

GetPreferencesStore(Guid)

Returns the preference store instance that is associated with the specified identifier, or creates a new empty store if a store does not already exist.

public:
 Microsoft::Web::Management::Client::PreferencesStore ^ GetPreferencesStore(Guid storeIdentifier);
public Microsoft.Web.Management.Client.PreferencesStore GetPreferencesStore (Guid storeIdentifier);
abstract member GetPreferencesStore : Guid -> Microsoft.Web.Management.Client.PreferencesStore
Public Function GetPreferencesStore (storeIdentifier As Guid) As PreferencesStore

Parameters

storeIdentifier
Guid

The preference store identifier.

Returns

The preference store instance that is associated with the specified identifier.

Examples

The following example saves and loads the preference store.

class SH {
    public static int iCnt;
    public static string Count { get { return "Count"; } }
    public static string Entry { get { return "Entry"; } }
private static readonly Guid PreferencesKey = 
    new Guid("{1abb6907-6dff-1638-8323-deadbeef1638}");
/// <summary>
/// Load the list of features using the PreferencesServices
/// </summary>
private void LoadPreferences() {
    IPreferencesService preferences = (IPreferencesService)
        _serviceProvider.GetService(typeof(IPreferencesService));
    PreferencesStore store =
        preferences.GetPreferencesStore(PreferencesKey);
    if (store.IsEmpty) {
        return;
    }

    for (int i = 0; i < _features.Length; i++) {
        MRUList<MRUPageInfo> current = _features[i];
        string val = SH.Count + i.ToString();
        int count = (int)store.GetValue(val, 0);
        if (count <= 0) {
            continue;
        }

        for (int j = count - 1; j >= 0; j--) {
            val = SH.Entry + i.ToString() + "-" + j.ToString();
            string modulePageTypeName = store.GetValue(val, null);
            current.Add(new MRUPageInfo(modulePageTypeName));
        }
    }
} 
/// <summary>
/// Store the list of features in the preference store using 
/// the PreferencesServices.
/// </summary>
internal void SavePreferences() {
    if (_serviceProvider != null) {
        IPreferencesService preferences = (IPreferencesService)
            _serviceProvider.GetService(typeof(IPreferencesService));
        PreferencesStore store =
            preferences.GetPreferencesStore(PreferencesKey);

        for (int i = 0; i < _features.Length; i++) {
            MRUList<MRUPageInfo> current = _features[i];
            string val = SH.Count + i.ToString();
            store.SetValue(val, current.Count, 0);
            int j = 0;
            foreach (MRUPageInfo info in current) {
                if (info == null) {
                    continue;
                }
                val = SH.Entry + i.ToString() + "-" + j.ToString();
                store.SetValue(val, info.Type, null);
                j++;
            }
        }
        preferences.Save();
    }

    _serviceProvider = null;
} 

Remarks

If a store does not already exist, this overload creates a new empty store.

Applies to

GetPreferencesStore(Guid, PreferencesStore)

Returns the preference store instance, if one exists, that is associated with the specified identifier.

public:
 bool GetPreferencesStore(Guid storeIdentifier, [Runtime::InteropServices::Out] Microsoft::Web::Management::Client::PreferencesStore ^ % store);
public bool GetPreferencesStore (Guid storeIdentifier, out Microsoft.Web.Management.Client.PreferencesStore store);
abstract member GetPreferencesStore : Guid *  -> bool
Public Function GetPreferencesStore (storeIdentifier As Guid, ByRef store As PreferencesStore) As Boolean

Parameters

storeIdentifier
Guid

The preference store identifier.

store
PreferencesStore

The preference store if one exists.

Returns

true if the preference store exists; otherwise, false.

Examples

The following example saves and loads the preference store.

class SH {
    public static int iCnt;
    public static string Count { get { return "Count"; } }
    public static string Entry { get { return "Entry"; } }
private static readonly Guid PreferencesKey = 
    new Guid("{1abb6907-6dff-1638-8323-deadbeef1638}");
private void LoadPreferences2() {
    IPreferencesService preferences = (IPreferencesService)
        _serviceProvider.GetService(typeof(IPreferencesService));
    PreferencesStore store;
    bool bExists = preferences.GetPreferencesStore(PreferencesKey, out store);
    if (!bExists) {
        return;
    }

    for (int i = 0; i < _features.Length; i++) {
        MRUList<MRUPageInfo> current = _features[i];
        string val = SH.Count + i.ToString();
        int count = (int)store.GetValue(val, 0);
        if (count <= 0) {
            continue;
        }

        for (int j = count - 1; j >= 0; j--) {
            val = SH.Entry + i.ToString() + "-" + j.ToString();
            string modulePageTypeName = store.GetValue(val, null);
            current.Add(new MRUPageInfo(modulePageTypeName));
        }
    }
}  
/// <summary>
/// Store the list of features in the preference store using 
/// the PreferencesServices.
/// </summary>
internal void SavePreferences() {
    if (_serviceProvider != null) {
        IPreferencesService preferences = (IPreferencesService)
            _serviceProvider.GetService(typeof(IPreferencesService));
        PreferencesStore store =
            preferences.GetPreferencesStore(PreferencesKey);

        for (int i = 0; i < _features.Length; i++) {
            MRUList<MRUPageInfo> current = _features[i];
            string val = SH.Count + i.ToString();
            store.SetValue(val, current.Count, 0);
            int j = 0;
            foreach (MRUPageInfo info in current) {
                if (info == null) {
                    continue;
                }
                val = SH.Entry + i.ToString() + "-" + j.ToString();
                store.SetValue(val, info.Type, null);
                j++;
            }
        }
        preferences.Save();
    }

    _serviceProvider = null;
} 

Remarks

If the preference store does not exist, this overload does not create a new one.

Applies to