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
0ee95e52
Commit
0ee95e52
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Log message changes only.
Refers to
#18
parent
edc66702
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ATxCommon/Serializables/ServiceConfig.cs
+6
-4
6 additions, 4 deletions
ATxCommon/Serializables/ServiceConfig.cs
ATxService/AutoTx.cs
+3
-5
3 additions, 5 deletions
ATxService/AutoTx.cs
with
9 additions
and
9 deletions
ATxCommon/Serializables/ServiceConfig.cs
+
6
−
4
View file @
0ee95e52
...
@@ -252,6 +252,7 @@ namespace ATxCommon.Serializables
...
@@ -252,6 +252,7 @@ namespace ATxCommon.Serializables
/// <param name="path">The path to the configuration files.</param>
/// <param name="path">The path to the configuration files.</param>
/// <returns>A ServiceConfig object with validated settings.</returns>
/// <returns>A ServiceConfig object with validated settings.</returns>
public
static
ServiceConfig
Deserialize
(
string
path
)
{
public
static
ServiceConfig
Deserialize
(
string
path
)
{
Log
.
Trace
(
"ServiceConfig.Deserialize({0})"
,
path
);
ServiceConfig
config
;
ServiceConfig
config
;
var
commonFile
=
Path
.
Combine
(
path
,
"config.common.xml"
);
var
commonFile
=
Path
.
Combine
(
path
,
"config.common.xml"
);
...
@@ -261,25 +262,25 @@ namespace ATxCommon.Serializables
...
@@ -261,25 +262,25 @@ namespace ATxCommon.Serializables
// behaviour of the .NET XmlSerializer on duplicates: only the first occurrence is
// 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
// 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:
// contents of the common config file to the host-specific and deserialize then:
Log
.
Debug
(
"Loading host specific configuration XML file: [{0}]"
,
specificFile
);
var
combined
=
XElement
.
Load
(
specificFile
);
var
combined
=
XElement
.
Load
(
specificFile
);
Log
.
Debug
(
"Loaded host specific configuration XML file: [{0}]"
,
specificFile
);
// the common configuration file is optional, so check if it exists at all:
// the common configuration file is optional, so check if it exists at all:
if
(
File
.
Exists
(
commonFile
))
{
if
(
File
.
Exists
(
commonFile
))
{
Log
.
Debug
(
"Loading common configuration XML file: [{0}]"
,
commonFile
);
var
common
=
XElement
.
Load
(
commonFile
);
var
common
=
XElement
.
Load
(
commonFile
);
Log
.
Debug
(
"Loaded common configuration XML file: [{0}]"
,
commonFile
);
combined
.
Add
(
common
.
Nodes
());
combined
.
Add
(
common
.
Nodes
());
Log
.
Trace
(
"Combined XML structure:\n\n{0}\n\n"
,
combined
);
Log
.
Trace
(
"Combined XML structure:\n\n{0}\n\n"
,
combined
);
}
}
using
(
var
reader
=
XmlReader
.
Create
(
new
StringReader
(
combined
.
ToString
())))
{
using
(
var
reader
=
XmlReader
.
Create
(
new
StringReader
(
combined
.
ToString
())))
{
Log
.
Debug
(
"Trying to parse combined XML."
);
Log
.
Debug
(
"Trying to parse combined XML.
..
"
);
var
serializer
=
new
XmlSerializer
(
typeof
(
ServiceConfig
));
var
serializer
=
new
XmlSerializer
(
typeof
(
ServiceConfig
));
config
=
(
ServiceConfig
)
serializer
.
Deserialize
(
reader
);
config
=
(
ServiceConfig
)
serializer
.
Deserialize
(
reader
);
}
}
ValidateConfiguration
(
config
);
ValidateConfiguration
(
config
);
Log
.
Debug
(
"Successfully parsed a
nd
valid
ated
configuration
XML."
);
Log
.
Debug
(
"Successfully parsed a valid configuration
from [{0}]."
,
path
);
return
config
;
return
config
;
}
}
...
@@ -287,6 +288,7 @@ namespace ATxCommon.Serializables
...
@@ -287,6 +288,7 @@ namespace ATxCommon.Serializables
/// Validate the configuration, throwing exceptions on invalid parameters.
/// Validate the configuration, throwing exceptions on invalid parameters.
/// </summary>
/// </summary>
private
static
void
ValidateConfiguration
(
ServiceConfig
c
)
{
private
static
void
ValidateConfiguration
(
ServiceConfig
c
)
{
Log
.
Debug
(
"Validating configuration..."
);
var
errmsg
=
""
;
var
errmsg
=
""
;
string
CheckEmpty
(
string
value
,
string
name
)
{
string
CheckEmpty
(
string
value
,
string
name
)
{
...
...
This diff is collapsed.
Click to expand it.
ATxService/AutoTx.cs
+
3
−
5
View file @
0ee95e52
...
@@ -207,17 +207,15 @@ namespace ATxService
...
@@ -207,17 +207,15 @@ namespace ATxService
"configuration.xml"
);
"configuration.xml"
);
try
{
try
{
_config
=
ServiceConfig
.
Deserialize
(
confPath
);
_config
=
ServiceConfig
.
Deserialize
(
confPath
);
Log
.
Debug
(
"Loaded config from [{0}]"
,
confPath
);
}
}
catch
(
ConfigurationErrorsException
ex
)
{
catch
(
ConfigurationErrorsException
ex
)
{
Log
.
Error
(
"ERROR validating configuration file [{0}]: {1}"
,
Log
.
Error
(
"Validating configuration failed: {0}"
,
ex
.
Message
);
confPath
,
ex
.
Message
);
throw
new
Exception
(
"Error validating configuration."
);
throw
new
Exception
(
"Error validating configuration."
);
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
Log
.
Error
(
"
l
oading configuration
XML
failed: {0}"
,
ex
.
Message
);
Log
.
Error
(
"
L
oading configuration failed: {0}"
,
ex
.
Message
);
// this should terminate the service process:
// this should terminate the service process:
throw
new
Exception
(
"Error loading config."
);
throw
new
Exception
(
"Error loading config
uration
."
);
}
}
}
}
...
...
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