-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Specialized; | ||
using System.Configuration; | ||
using System.Reflection; | ||
|
||
namespace Bluegrams.Application | ||
{ | ||
/// <summary> | ||
/// A shared base class for portable settings providers. | ||
/// </summary> | ||
public abstract class PortableSettingsProviderBase : SettingsProvider, IApplicationSettingsProvider | ||
{ | ||
/// <summary> | ||
/// Specifies if all settings should be roaming. | ||
/// </summary> | ||
public static bool AllRoaming { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Specifies the directory of the settings file. | ||
/// </summary> | ||
public static string SettingsDirectory { get; set; } = AppDomain.CurrentDomain.BaseDirectory; | ||
|
||
public override string ApplicationName { get { return Assembly.GetExecutingAssembly().GetName().Name; } set { } } | ||
|
||
protected static void ApplyProvider(PortableSettingsProviderBase provider, params ApplicationSettingsBase[] settingsList) | ||
{ | ||
foreach (var settings in settingsList) | ||
{ | ||
settings.Providers.Clear(); | ||
settings.Providers.Add(provider); | ||
foreach (SettingsProperty prop in settings.Properties) | ||
prop.Provider = provider; | ||
settings.Reload(); | ||
} | ||
} | ||
|
||
public override void Initialize(string name, NameValueCollection config) | ||
{ | ||
if (String.IsNullOrEmpty(name)) name = Name; | ||
base.Initialize(name, config); | ||
} | ||
|
||
public virtual SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public abstract void Reset(SettingsContext context); | ||
|
||
public virtual void Upgrade(SettingsContext context, SettingsPropertyCollection properties) | ||
{ /* don't do anything here*/ } | ||
|
||
/// <summary> | ||
/// Iterates through a property's attributes to determine whether it is user-scoped or application-scoped. | ||
/// </summary> | ||
protected bool IsUserScoped(SettingsProperty prop) | ||
{ | ||
foreach (DictionaryEntry d in prop.Attributes) | ||
{ | ||
Attribute a = (Attribute)d.Value; | ||
if (a.GetType() == typeof(UserScopedSettingAttribute)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Iterates through a property's attributes to determine whether it is set to roam. | ||
/// </summary> | ||
protected bool IsRoaming(SettingsProperty prop) | ||
{ | ||
if (AllRoaming) | ||
return true; | ||
foreach (DictionaryEntry d in prop.Attributes) | ||
{ | ||
Attribute a = (Attribute)d.Value; | ||
if (a.GetType() == typeof(SettingsManageabilityAttribute)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |