Skip to content
Snippets Groups Projects
Commit d1e733ee authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Reduce number of global variables.

parent 6d28bb5e
Branches
Tags
No related merge requests found
...@@ -14,6 +14,9 @@ using NLog.Config; ...@@ -14,6 +14,9 @@ using NLog.Config;
using NLog.Targets; using NLog.Targets;
using RoboSharp; using RoboSharp;
// NOTE on naming conventions: variables containing "Path" are strings, variables containing
// "Dir" are DirectoryInfo objects!
namespace ATxService namespace ATxService
{ {
public partial class AutoTx : ServiceBase public partial class AutoTx : ServiceBase
...@@ -24,11 +27,6 @@ namespace ATxService ...@@ -24,11 +27,6 @@ namespace ATxService
private const string LogFormatDefault = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] ${message}"; private const string LogFormatDefault = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] ${message}";
// private const string LogFormatDefault = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] (${logger}) ${message}" // private const string LogFormatDefault = @"${date:format=yyyy-MM-dd HH\:mm\:ss} [${level}] (${logger}) ${message}"
// naming convention: variables containing "Path" are strings, variables
// containing "Dir" are DirectoryInfo objects
private string _pathToConfig;
private string _pathToStatus;
private readonly List<string> _transferredFiles = new List<string>(); private readonly List<string> _transferredFiles = new List<string>();
private RoboCommand _roboCommand; private RoboCommand _roboCommand;
...@@ -192,9 +190,6 @@ namespace ATxService ...@@ -192,9 +190,6 @@ namespace ATxService
private void LoadSettings() { private void LoadSettings() {
try { try {
_transferState = TxState.Stopped; _transferState = TxState.Stopped;
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
_pathToConfig = Path.Combine(baseDir, "configuration.xml");
_pathToStatus = Path.Combine(baseDir, "status.xml");
LoadConfigXml(); LoadConfigXml();
LoadStatusXml(); LoadStatusXml();
...@@ -214,13 +209,15 @@ namespace ATxService ...@@ -214,13 +209,15 @@ namespace ATxService
/// Load the configuration xml file. /// Load the configuration xml file.
/// </summary> /// </summary>
private void LoadConfigXml() { private void LoadConfigXml() {
var confPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"configuration.xml");
try { try {
_config = ServiceConfig.Deserialize(_pathToConfig); _config = ServiceConfig.Deserialize(confPath);
Log.Debug("Loaded config from [{0}]", _pathToConfig); Log.Debug("Loaded config from [{0}]", confPath);
} }
catch (ConfigurationErrorsException ex) { catch (ConfigurationErrorsException ex) {
Log.Error("ERROR validating configuration file [{0}]: {1}", Log.Error("ERROR validating configuration file [{0}]: {1}",
_pathToConfig, ex.Message); confPath, ex.Message);
throw new Exception("Error validating configuration."); throw new Exception("Error validating configuration.");
} }
catch (Exception ex) { catch (Exception ex) {
...@@ -234,14 +231,16 @@ namespace ATxService ...@@ -234,14 +231,16 @@ namespace ATxService
/// Load the status xml file. /// Load the status xml file.
/// </summary> /// </summary>
private void LoadStatusXml() { private void LoadStatusXml() {
try { var statusPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
Log.Debug("Trying to load status from [{0}]", _pathToStatus); "status.xml");
_status = ServiceStatus.Deserialize(_pathToStatus, _config); try {
Log.Debug("Loaded status from [{0}]", _pathToStatus); Log.Debug("Trying to load status from [{0}]", statusPath);
_status = ServiceStatus.Deserialize(statusPath, _config);
Log.Debug("Loaded status from [{0}]", statusPath);
} }
catch (Exception ex) { catch (Exception ex) {
Log.Error("loading status XML from [{0}] failed: {1} {2}", Log.Error("loading status XML from [{0}] failed: {1} {2}",
_pathToStatus, ex.Message, ex.StackTrace); statusPath, ex.Message, ex.StackTrace);
// this should terminate the service process: // this should terminate the service process:
throw new Exception("Error loading status."); throw new Exception("Error loading status.");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment