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
d16183e6
Commit
d16183e6
authored
6 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Consolidate startup directory checks into InitializeDirectories
parent
00133894
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ATxService/AutoTx.cs
+13
-45
13 additions, 45 deletions
ATxService/AutoTx.cs
with
13 additions
and
45 deletions
ATxService/AutoTx.cs
+
13
−
45
View file @
d16183e6
...
...
@@ -115,10 +115,9 @@ namespace ATxService
Log
.
Info
(
"Attempting to start {0} service..."
,
ServiceName
);
CreateEventLog
();
LoadSettings
();
CreateIncomingDirectories
();
InitializePerformanceMonitors
();
InitializeDirectories
();
StartupSummary
();
if
(
_config
.
DebugRoboSharp
)
{
...
...
@@ -263,9 +262,6 @@ namespace ATxService
Log
.
Error
(
"LoadSettings() failed: {0}\n{1}"
,
ex
.
Message
,
ex
.
StackTrace
);
throw
new
Exception
(
"Error in LoadSettings."
);
}
// NOTE: this is explicitly called *outside* the try-catch block so an Exception
// thrown by the checker will not be silenced but cause the startup to fail:
CheckConfiguration
();
}
/// <summary>
...
...
@@ -308,20 +304,6 @@ namespace ATxService
// this should terminate the service process:
throw
new
Exception
(
"Error loading status."
);
}
}
/// <summary>
/// Check if loaded configuration is valid, print a summary to the log.
/// </summary>
private
void
CheckConfiguration
()
{
var
configInvalid
=
false
;
if
(
FsUtils
.
CheckSpoolingDirectories
(
_config
.
IncomingPath
,
_config
.
ManagedPath
)
==
false
)
{
Log
.
Error
(
"ERROR checking spooling directories (incoming / managed)!"
);
configInvalid
=
true
;
}
// terminate the service process if necessary:
if
(
configInvalid
)
throw
new
Exception
(
"Invalid config, check log file!"
);
// now check the clean-shutdown status and send a notification if it was not true,
// then set it to false while the service is running until it is properly
...
...
@@ -644,7 +626,8 @@ namespace ATxService
_status
.
SerializeHeartbeat
();
if
(
TimeUtils
.
SecondsSince
(
_lastUserDirCheck
)
>=
120
)
CreateIncomingDirectories
();
_lastUserDirCheck
=
FsUtils
.
CreateIncomingDirectories
(
_config
.
DestinationDirectory
,
_config
.
TmpTransferDir
,
_config
.
IncomingPath
);
// tasks depending on the service state:
if
(
_status
.
ServiceSuspended
)
{
...
...
@@ -952,34 +935,19 @@ namespace ATxService
}
/// <summary>
/// Helper to create directories for all users that have one in the local
/// user directory (C:\Users) AND in the DestinationDirectory.
/// Wrapper to check or create the spooling directories and the incoming dirs for all users.
/// </summary>
private
void
CreateIncomingDirectories
()
{
var
localUserDirs
=
new
DirectoryInfo
(
@"C:\Users"
)
.
GetDirectories
()
.
Select
(
d
=>
d
.
Name
)
.
ToArray
();
var
remoteUserDirs
=
new
DirectoryInfo
(
_config
.
DestinationDirectory
)
.
GetDirectories
()
.
Select
(
d
=>
d
.
Name
)
.
ToArray
();
foreach
(
var
userDir
in
localUserDirs
)
{
// don't create an incoming directory for the same name as the
// temporary transfer location:
if
(
_config
.
TmpTransferDir
==
userDir
)
continue
;
// don't create a directory if it doesn't exist on the target:
if
(!
remoteUserDirs
.
Contains
(
userDir
))
continue
;
FsUtils
.
CreateNewDirectory
(
Path
.
Combine
(
_config
.
IncomingPath
,
userDir
),
false
);
private
void
InitializeDirectories
()
{
if
(
FsUtils
.
CheckSpoolingDirectories
(
_config
.
IncomingPath
,
_config
.
ManagedPath
)
==
false
)
{
const
string
msg
=
"ERROR checking spooling directories (incoming / managed)!"
;
Log
.
Error
(
msg
);
throw
new
Exception
(
msg
);
}
_lastUserDirCheck
=
DateTime
.
Now
;
}
_lastUserDirCheck
=
FsUtils
.
CreateIncomingDirectories
(
_config
.
DestinationDirectory
,
_config
.
TmpTransferDir
,
_config
.
IncomingPath
);
}
#
endregion
}
...
...
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