DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Private Member Functions | List of all members
Deveel.Data.Configuration.PropertiesConfigFormatter Class Reference
Inheritance diagram for Deveel.Data.Configuration.PropertiesConfigFormatter:
Deveel.Data.Configuration.IConfigFormatter

Public Member Functions

void LoadInto (IConfiguration config, Stream inputStream)
 Loads a stored configuration from the given stream into the configuration argument. More...
 
void SaveFrom (IConfiguration config, ConfigurationLevel level, Stream outputStream)
 Stores the given level of configurations into the output stream provided, in the format handled by this interface. More...
 

Private Member Functions

void SetValue (IConfiguration config, string propKey, string value)
 
object ConvertValueTo (string value, Type valueType)
 

Detailed Description

Definition at line 26 of file PropertiesConfigFormatter.cs.

Member Function Documentation

object Deveel.Data.Configuration.PropertiesConfigFormatter.ConvertValueTo ( string  value,
Type  valueType 
)
inlineprivate

Definition at line 31 of file PropertiesConfigFormatter.cs.

31  {
32  return Convert.ChangeType(value, valueType, CultureInfo.InvariantCulture);
33  }
void Deveel.Data.Configuration.PropertiesConfigFormatter.LoadInto ( IConfiguration  config,
Stream  inputStream 
)
inline

Loads a stored configuration from the given stream into the configuration argument.

Parameters
configThe configuration object inside of which to load the configurations from the the given stream.
inputStreamThe stream from where to read the configurations formatted into the object provided as argument.
Exceptions
ArgumentExceptionIf the provided inputStream cannot be read.
ArgumentNullExceptionIf either config or inputStream are null.

Implements Deveel.Data.Configuration.IConfigFormatter.

Definition at line 35 of file PropertiesConfigFormatter.cs.

35  {
36  if (inputStream == null)
37  throw new ArgumentNullException("inputStream");
38 
39  try {
40  var properties = new Properties();
41  properties.Load(inputStream);
42 
43  foreach (var entry in properties) {
44  var propKey = (string) entry.Key;
45  SetValue(config, propKey, (string) entry.Value);
46  }
47  } catch (DatabaseConfigurationException) {
48  throw;
49  } catch (Exception ex) {
50  throw new DatabaseConfigurationException("Could not load properties from the given stream.", ex);
51  }
52  }
void SetValue(IConfiguration config, string propKey, string value)
void Deveel.Data.Configuration.PropertiesConfigFormatter.SaveFrom ( IConfiguration  config,
ConfigurationLevel  level,
Stream  outputStream 
)
inline

Stores the given level of configurations into the output stream provided, in the format handled by this interface.

Parameters
configThe source of the configurations to store.
levelThe level of the configurations to load from the source and store.
outputStreamThe destination stream where the formatter saves the configurations retrieved from the source.
See also
ConfigurationLevel
Exceptions
ArgumentExceptionIf the provided outputStream cannot be written.
ArgumentNullExceptionIf either config or outputStream are null.

Implements Deveel.Data.Configuration.IConfigFormatter.

Definition at line 54 of file PropertiesConfigFormatter.cs.

54  {
55  try {
56  var keys = config.GetKeys(level);
57  var properties = new Properties();
58 
59  foreach (var configKey in keys) {
60  var configValue = config.GetValue(configKey);
61  if (configValue != null) {
62  var stringValue = Convert.ToString(configValue, CultureInfo.InvariantCulture);
63  properties.SetProperty(configKey, stringValue);
64  }
65  }
66 
67  properties.Store(outputStream, String.Empty);
68  } catch (DatabaseConfigurationException) {
69  throw;
70  } catch (Exception ex) {
71  throw new DatabaseConfigurationException("Could not save the configurations to the given stream.", ex);
72  }
73  }
A long string in the system.
void Deveel.Data.Configuration.PropertiesConfigFormatter.SetValue ( IConfiguration  config,
string  propKey,
string  value 
)
inlineprivate

Definition at line 27 of file PropertiesConfigFormatter.cs.

27  {
28  config.SetValue(propKey, value);
29  }

The documentation for this class was generated from the following file: