OpenTAP 9.24
API Reference
Public Member Functions | Static Public Member Functions | Static Public Attributes | Properties | Events | List of all members
OpenTap.ComponentSettings< T > Class Template Reference

It is recommended to inherit from this class when implementing component settings. This class uses a recurrent template pattern to exhibit a kind of "static reflection". More...

Inheritance diagram for OpenTap.ComponentSettings< T >:
OpenTap.ValidatingObject OpenTap.IComponentSettings OpenTap.IValidatingObject OpenTap.ITapPlugin

Public Member Functions

void Save ()
 Saves the settings held by this class to an XML file in the ComponentSettings.SetSettingsProfile(string, string).
 
void Invalidate ()
 Invalidates the cache of this type of component setting.
 
void Reload ()
 Forces the reload of this type of component setting from the XML file the next time the setting is used.
 
virtual void Initialize ()
 Called if a new ComponentSettings is instantiated and there are no corresponding settings XML.
 
- Public Member Functions inherited from OpenTap.ValidatingObject
void OnPropertyChanged (string propertyName)
 Triggers the PropertyChanged event. More...
 

Static Public Member Functions

static string GetSettingsDirectory (string groupName, bool isProfile=true)
 The directory where the settings are loaded from / saved to. More...
 
static void EnsureSettingsDirectoryExists (string groupName, bool isProfile=true)
 Ensures that the Settings directory exists and that the specified groupName sub directory exists. This might throw an exception if the settings directory was configured to something invalid. Like 'AUX', 'NUL', .... More...
 
static void SetSettingsProfile (string groupName, string profileName)
 Sets the directory in which settings groups are loaded from / saved to. More...
 
static void SaveAllCurrentSettings ()
 Saves all ComponentSettings objects that have been loaded.
 
static string GetSaveFilePath (Type type)
 Gets the current file location where a ComponentSettings type is saved. More...
 
static ComponentSettings GetCurrent (Type settingsType)
 Gets current settings for a specified component. This is either an instance of the settings class previously loaded, or a new instance loaded from the associated file. More...
 
static void SetCurrent (Stream xmlFileStream)
 Sets current settings for a component setting based on a stream of the file contents of a ComponentSettings XML file. More...
 
static void SetCurrent (Stream xmlFileStream, out IEnumerable< XmlError > errors)
 Sets current settings for a component setting based on a stream of the file contents of a ComponentSettings XML file. More...
 
static ComponentSettings GetCurrent (ITypeData settingsType)
 Gets current settings for a specified component. This is either an instance of the settings class previously loaded, or a new instance loaded from the associated file. More...
 
static ComponentSettings GetCurrentFromCache (Type settingsType)
 Gets current settings for a specified component from cache. More...
 

Static Public Attributes

static bool PersistSettingGroups = true
 Gets or sets if settings groups should be persisted between processes.
 

Properties

static T Current [get]
 Get the currently loaded ComponentSettings instance for this class.
 
string? GroupName [get]
 Settings group of this settings class.
 
static string SettingsDirectoryRoot [getset]
 Where settings files are located. Usually this is at "[Executable location]\Settings", but it can be set to different locations. Setting this will invalidate loaded settings.
 
- Properties inherited from OpenTap.ValidatingObject
ValidationRuleCollection Rules [get]
 All the validation rules. Add new rules to this in order to get runtime value validation.
 
string Error [get]
 Gets the error messages for each invalid rule and joins them with a newline.
 
- Properties inherited from OpenTap.IValidatingObject
ValidationRuleCollection Rules [get]
 A collection of all the currently defined validation rules. Add new rules here in order to get runtime value validation.
 

Events

EventHandler CacheInvalidated
 Invokes when the cache for this settings item is invalidated for this item. The way to handle it is usually to fetch the new instance using ComponentSettings.GetCurrent(sender.GetType()).
 
- Events inherited from OpenTap.ValidatingObject
PropertyChangedEventHandler PropertyChanged
 Standard PropertyChanged event object.
 

Additional Inherited Members

- Protected Member Functions inherited from OpenTap.ValidatingObject
virtual string GetError (string propertyName=null)
 Return the error for a given property
 
void ThrowOnValidationError (bool ignoreDisabledProperties)
 Checks all validation rules on this object (Rules) and throws an AggregateException on errors. More...
 

Detailed Description

It is recommended to inherit from this class when implementing component settings. This class uses a recurrent template pattern to exhibit a kind of "static reflection".

An abstract class to implement general settings for a component. This class provides methods to load and save the settings to/from an XML file using TapSerializer.

It is also possible implement a component setting by inherriting from the non-generic ComponentSettings or IComponentSettings it is just not recommended.

Template Parameters
TThe inheriting class.

It is recommended to inherit from ComponentSettings<T> when possible.

Type Constraints
T :ComponentSettings 

Member Function Documentation

◆ EnsureSettingsDirectoryExists()

static void OpenTap.ComponentSettings< T >.EnsureSettingsDirectoryExists ( string  groupName,
bool  isProfile = true 
)
static

Ensures that the Settings directory exists and that the specified groupName sub directory exists. This might throw an exception if the settings directory was configured to something invalid. Like 'AUX', 'NUL', ....

Parameters
groupNameName of the settings group.
isProfileDetermines if the settings group uses profiles.

◆ GetCurrent() [1/2]

static ComponentSettings OpenTap.ComponentSettings< T >.GetCurrent ( ITypeData  settingsType)
inlinestatic

Gets current settings for a specified component. This is either an instance of the settings class previously loaded, or a new instance loaded from the associated file.

Parameters
settingsTypeThe type of the component settings requested (this type must be a descendant of ComponentSettings).
Returns
Returns the loaded components settings. Null if it was not able to load the settings type.

◆ GetCurrent() [2/2]

static ComponentSettings OpenTap.ComponentSettings< T >.GetCurrent ( Type  settingsType)
static

Gets current settings for a specified component. This is either an instance of the settings class previously loaded, or a new instance loaded from the associated file.

Parameters
settingsTypeThe type of the component settings requested (this type must be a descendant of ComponentSettings).
Returns
Returns the loaded components settings. Null if it was not able to load the settings type.

◆ GetCurrentFromCache()

static ComponentSettings OpenTap.ComponentSettings< T >.GetCurrentFromCache ( Type  settingsType)
static

Gets current settings for a specified component from cache.

Parameters
settingsTypeThe type of the component settings requested (this type must be a descendant of ComponentSettings).
Returns
Returns the loaded components settings. Null if it was not able to load the settings type or if it was not cached.

◆ GetSaveFilePath()

static string OpenTap.ComponentSettings< T >.GetSaveFilePath ( Type  type)
static

Gets the current file location where a ComponentSettings type is saved.

Parameters
typeMust be a ComponentSettings sub-class.
Returns

◆ GetSettingsDirectory()

static string OpenTap.ComponentSettings< T >.GetSettingsDirectory ( string  groupName,
bool  isProfile = true 
)
static

The directory where the settings are loaded from / saved to.

Parameters
groupNameName of the settings group.
isProfileIf the settings group uses profiles, we load the default profile.

◆ SetCurrent() [1/2]

static void OpenTap.ComponentSettings< T >.SetCurrent ( Stream  xmlFileStream)
static

Sets current settings for a component setting based on a stream of the file contents of a ComponentSettings XML file.

Exceptions
InvalidDataExceptionIf the input stream is not valid XML
Parameters
xmlFileStreamThe component settings stream to be set
Returns

◆ SetCurrent() [2/2]

static void OpenTap.ComponentSettings< T >.SetCurrent ( Stream  xmlFileStream,
out IEnumerable< XmlError errors 
)
static

Sets current settings for a component setting based on a stream of the file contents of a ComponentSettings XML file.

Parameters
xmlFileStreamThe component settings stream to be set
errorsAny XML errors that occurred during deserialization
Returns

◆ SetSettingsProfile()

static void OpenTap.ComponentSettings< T >.SetSettingsProfile ( string  groupName,
string  profileName 
)
static

Sets the directory in which settings groups are loaded from / saved to.

Parameters
groupNameName of the settings group.
profileNameName of the selected settings profile.

OpenTAP 9.24 API built Tue Apr 30 2024 13:44:41