Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto-tx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vamp
auto-tx
Commits
4520c8dc
Commit
4520c8dc
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Shift all methods including constructor below parameters.
Again, no functional changes in this commit! Refers to
#29
parent
ec404abf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxCommon/Serializables/ServiceConfig.cs
+55
-52
55 additions, 52 deletions
ATxCommon/Serializables/ServiceConfig.cs
with
55 additions
and
52 deletions
ATxCommon/Serializables/ServiceConfig.cs
+
55
−
52
View file @
4520c8dc
...
...
@@ -17,58 +17,6 @@ namespace ATxCommon.Serializables
{
private
static
readonly
Logger
Log
=
LogManager
.
GetCurrentClassLogger
();
public
ServiceConfig
()
{
Log
.
Trace
(
"ServiceConfig() constructor, setting defaults."
);
// set values for the optional XML elements:
SmtpPort
=
25
;
GraceNotificationDelta
=
720
;
EnforceInheritedACLs
=
true
;
}
/// <summary>
/// Dummy method raising an exception (this class must not be serialized).
/// </summary>
public
static
void
Serialize
(
string
file
,
ServiceConfig
c
)
{
// the config is never meant to be written by us, therefore:
throw
new
SettingsPropertyIsReadOnlyException
(
"The config file must not be written by the service!"
);
}
/// <summary>
/// Load the host specific and the common XML configuration files, combine them and
/// deserialize them into a ServiceConfig object. The host specific configuration file's
/// name is defined as the hostname with an ".xml" suffix.
/// </summary>
/// <param name="path">The path to the configuration files.</param>
/// <returns>A ServiceConfig object with validated settings.</returns>
public
static
ServiceConfig
Deserialize
(
string
path
)
{
ServiceConfig
config
;
var
commonFile
=
Path
.
Combine
(
path
,
"config.common.xml"
);
var
specificFile
=
Path
.
Combine
(
path
,
Environment
.
MachineName
+
".xml"
);
// for parsing the configuration from two separate files we are using the default
// behaviour of the .NET XmlSerializer on duplicates: only the first occurrence is
// used, all other ones are silentley being discarded - this way we simply append the
// contents of the common config file to the host-specific and deserialize then:
var
common
=
XElement
.
Load
(
commonFile
);
Log
.
Debug
(
"Loaded common configuration XML file: [{0}]"
,
commonFile
);
var
combined
=
XElement
.
Load
(
specificFile
);
Log
.
Debug
(
"Loaded host specific configuration XML file: [{0}]"
,
specificFile
);
combined
.
Add
(
common
.
Nodes
());
Log
.
Trace
(
"Combined XML structure:\n\n{0}\n\n"
,
combined
);
using
(
var
reader
=
XmlReader
.
Create
(
new
StringReader
(
combined
.
ToString
())))
{
Log
.
Debug
(
"Trying to parse combined XML."
);
var
serializer
=
new
XmlSerializer
(
typeof
(
ServiceConfig
));
config
=
(
ServiceConfig
)
serializer
.
Deserialize
(
reader
);
}
ValidateConfiguration
(
config
);
Log
.
Debug
(
"Successfully parsed and validated configuration XML."
);
return
config
;
}
#
region
required
configuration
parameters
...
...
@@ -276,6 +224,61 @@ namespace ATxCommon.Serializables
#
endregion
/// <summary>
/// Constructor setting default values for optional parameters.
/// </summary>
public
ServiceConfig
()
{
Log
.
Trace
(
"ServiceConfig() constructor, setting defaults."
);
// set values for the optional XML elements:
SmtpPort
=
25
;
GraceNotificationDelta
=
720
;
EnforceInheritedACLs
=
true
;
}
/// <summary>
/// Dummy method raising an exception (this class must not be serialized).
/// </summary>
public
static
void
Serialize
(
string
file
,
ServiceConfig
c
)
{
// the config is never meant to be written by us, therefore:
throw
new
SettingsPropertyIsReadOnlyException
(
"The config file must not be written by the service!"
);
}
/// <summary>
/// Load the host specific and the common XML configuration files, combine them and
/// deserialize them into a ServiceConfig object. The host specific configuration file's
/// name is defined as the hostname with an ".xml" suffix.
/// </summary>
/// <param name="path">The path to the configuration files.</param>
/// <returns>A ServiceConfig object with validated settings.</returns>
public
static
ServiceConfig
Deserialize
(
string
path
)
{
ServiceConfig
config
;
var
commonFile
=
Path
.
Combine
(
path
,
"config.common.xml"
);
var
specificFile
=
Path
.
Combine
(
path
,
Environment
.
MachineName
+
".xml"
);
// for parsing the configuration from two separate files we are using the default
// behaviour of the .NET XmlSerializer on duplicates: only the first occurrence is
// used, all other ones are silentley being discarded - this way we simply append the
// contents of the common config file to the host-specific and deserialize then:
var
common
=
XElement
.
Load
(
commonFile
);
Log
.
Debug
(
"Loaded common configuration XML file: [{0}]"
,
commonFile
);
var
combined
=
XElement
.
Load
(
specificFile
);
Log
.
Debug
(
"Loaded host specific configuration XML file: [{0}]"
,
specificFile
);
combined
.
Add
(
common
.
Nodes
());
Log
.
Trace
(
"Combined XML structure:\n\n{0}\n\n"
,
combined
);
using
(
var
reader
=
XmlReader
.
Create
(
new
StringReader
(
combined
.
ToString
())))
{
Log
.
Debug
(
"Trying to parse combined XML."
);
var
serializer
=
new
XmlSerializer
(
typeof
(
ServiceConfig
));
config
=
(
ServiceConfig
)
serializer
.
Deserialize
(
reader
);
}
ValidateConfiguration
(
config
);
Log
.
Debug
(
"Successfully parsed and validated configuration XML."
);
return
config
;
}
/// <summary>
/// Validate the configuration, throwing exceptions on invalid parameters.
/// </summary>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment