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
0149e094
Commit
0149e094
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Add SetSuspended to simplify handling of status changes
parent
5ed8b177
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ATxCommon/Serializables/ServiceStatus.cs
+27
-6
27 additions, 6 deletions
ATxCommon/Serializables/ServiceStatus.cs
ATxService/AutoTx.cs
+3
-17
3 additions, 17 deletions
ATxService/AutoTx.cs
ATxTray/AutoTxTray.cs
+3
-3
3 additions, 3 deletions
ATxTray/AutoTxTray.cs
with
33 additions
and
26 deletions
ATxCommon/Serializables/ServiceStatus.cs
+
27
−
6
View file @
0149e094
...
...
@@ -20,7 +20,7 @@ namespace ATxCommon.Serializables
private
DateTime
_lastAdminNotification
;
private
DateTime
_lastGraceNotification
;
private
string
_
limitReas
on
;
private
string
_
statusDescripti
on
;
private
string
_currentTransferSrc
;
private
string
_currentTargetTmp
;
...
...
@@ -151,13 +151,13 @@ namespace ATxCommon.Serializables
/// <summary>
/// String indicating why the service is currently suspended (empty if not suspended).
/// </summary>
public
string
LimitReas
on
{
get
=>
_
limitReas
on
;
public
string
StatusDescripti
on
{
get
=>
_
statusDescripti
on
;
set
{
if
(
_
limitReas
on
==
value
)
return
;
if
(
_
statusDescripti
on
==
value
)
return
;
_
limitReas
on
=
value
;
Log
.
Trace
(
"
LimitReas
on was updated ({0})."
,
value
);
_
statusDescripti
on
=
value
;
Log
.
Trace
(
"
StatusDescripti
on was updated ({0})."
,
value
);
Serialize
();
}
}
...
...
@@ -286,6 +286,27 @@ namespace ATxCommon.Serializables
Environment
.
MachineName
,
_currentTargetTmp
);
}
/// <summary>
/// Helper to set the service state, logging a message if the state has changed.
/// </summary>
/// <param name="suspended">The target state for <see cref="ServiceSuspended"/>.</param>
/// <param name="description">The description to use for the log message as well as for
/// setting <see cref="StatusDescription"/>.</param>
public
void
SetSuspended
(
bool
suspended
,
string
description
)
{
if
(
description
==
_statusDescription
&&
suspended
==
_serviceSuspended
)
return
;
_serviceSuspended
=
suspended
;
_statusDescription
=
description
;
Serialize
();
if
(
suspended
)
{
Log
.
Info
(
"Service suspended. Reason(s): [{0}]"
,
description
);
}
else
{
Log
.
Info
(
"Service resuming operation ({0})."
,
description
);
}
}
#
region
validate
and
report
...
...
This diff is collapsed.
Click to expand it.
ATxService/AutoTx.cs
+
3
−
17
View file @
0149e094
...
...
@@ -574,32 +574,18 @@ namespace ATxService
// all parameters within valid ranges, so set the state to "Running":
if
(
suspendReasons
.
Count
==
0
)
{
if
(
_status
.
ServiceSuspended
)
{
_status
.
ServiceSuspended
=
false
;
_status
.
LimitReason
=
""
;
// reset to force a message on next service suspend
Log
.
Info
(
"Service resuming operation (all parameters in valid ranges)."
);
}
_status
.
SetSuspended
(
false
,
"all parameters in valid ranges"
);
return
;
}
// set state to "Running" if no-one is logged on:
if
(
SystemChecks
.
NoUserIsLoggedOn
())
{
if
(
_status
.
ServiceSuspended
)
{
_status
.
ServiceSuspended
=
false
;
_status
.
LimitReason
=
""
;
// reset to force a message on next service suspend
Log
.
Info
(
"Service resuming operation (no user logged on)."
);
}
_status
.
SetSuspended
(
false
,
"no user is currently logged on"
);
return
;
}
// by reaching this point we know the service should be suspended:
_status
.
ServiceSuspended
=
true
;
var
limitReason
=
string
.
Join
(
", "
,
suspendReasons
);
if
(
limitReason
==
_status
.
LimitReason
)
return
;
Log
.
Info
(
"Service suspended. Reason(s): [{0}]"
,
limitReason
);
_status
.
LimitReason
=
limitReason
;
_status
.
SetSuspended
(
true
,
string
.
Join
(
", "
,
suspendReasons
));
}
/// <summary>
...
...
This diff is collapsed.
Click to expand it.
ATxTray/AutoTxTray.cs
+
3
−
3
View file @
0149e094
...
...
@@ -459,18 +459,18 @@ namespace ATxTray
private
void
UpdateServiceSuspendedState
()
{
// first update the suspend reason as this can possibly change even if the service
// never leaves the suspended state and we should still display the correct reason:
if
(
_serviceSuspendReason
==
_status
.
LimitReas
on
&&
if
(
_serviceSuspendReason
==
_status
.
StatusDescripti
on
&&
_serviceSuspended
==
_status
.
ServiceSuspended
)
return
;
_serviceSuspended
=
_status
.
ServiceSuspended
;
_serviceSuspendReason
=
_status
.
LimitReas
on
;
_serviceSuspendReason
=
_status
.
StatusDescripti
on
;
if
(
_serviceSuspended
)
{
_miSvcSuspended
.
Text
=
@"Service suspended, reason: "
+
_serviceSuspendReason
;
_miSvcSuspended
.
BackColor
=
Color
.
LightSalmon
;
/*
_notifyIcon.ShowBalloonTip(500, "AutoTx Monitor",
"Service suspended: " + _status.
LimitReas
on, ToolTipIcon.Warning);
"Service suspended: " + _status.
StatusDescripti
on, ToolTipIcon.Warning);
*/
}
else
{
_miSvcSuspended
.
Text
=
@"No limits apply, service active."
;
...
...
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