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
76438d96
Commit
76438d96
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Improve variables and methods names.
parent
25965456
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
ATxTray/AutoTxTray.cs
+50
-45
50 additions, 45 deletions
ATxTray/AutoTxTray.cs
with
50 additions
and
45 deletions
ATxTray/AutoTxTray.cs
+
50
−
45
View file @
76438d96
...
...
@@ -32,14 +32,17 @@ namespace ATxTray
private
static
bool
_statusChanged
=
false
;
private
static
bool
_statusFileChanged
=
true
;
private
static
bool
_s
vcRunning
=
false
;
private
static
bool
_s
vc
Suspended
=
true
;
private
static
string
_s
vc
SuspendReason
;
private
static
bool
_s
erviceProcessAlive
=
false
;
private
static
bool
_s
ervice
Suspended
=
true
;
private
static
string
_s
ervice
SuspendReason
;
private
static
bool
_txInProgress
=
false
;
private
static
long
_txSize
;
private
static
int
_txProgressPct
;
#
region
tray
icon
and
context
menu
variables
private
readonly
NotifyIcon
_notifyIcon
=
new
NotifyIcon
();
private
readonly
Icon
_tiDefault
=
Properties
.
Resources
.
IconDefault
;
private
readonly
Icon
_tiStopped
=
Properties
.
Resources
.
IconStopped
;
...
...
@@ -56,6 +59,9 @@ namespace ATxTray
private
readonly
ToolStripProgressBar
_miTxProgressBar
=
new
ToolStripProgressBar
();
#
endregion
private
static
TaskDialog
_confirmDialog
;
private
static
DirectoryInfo
_selectedDir
;
...
...
@@ -74,7 +80,7 @@ namespace ATxTray
_notifyIcon
.
Icon
=
_tiStopped
;
_notifyIcon
.
Visible
=
true
;
_notifyIcon
.
DoubleClick
+=
Start
NewTransfer
;
_notifyIcon
.
DoubleClick
+=
PickDirectoryFor
NewTransfer
;
// this doesn't work properly, the menu will not close etc. so we disable it for now:
// _notifyIcon.Click += ShowContextMenu;
...
...
@@ -82,7 +88,7 @@ namespace ATxTray
Log
.
Trace
(
"Trying to read service config and status files..."
);
try
{
_config
=
ServiceConfig
.
Deserialize
(
Path
.
Combine
(
baseDir
,
"configuration.xml"
));
ReadStatus
();
UpdateStatusInformation
();
SetupContextMenu
();
}
catch
(
Exception
ex
)
{
...
...
@@ -108,7 +114,7 @@ namespace ATxTray
NotifyFilter
=
NotifyFilters
.
LastWrite
,
Filter
=
"status.xml"
,
};
fsw
.
Changed
+=
StatusUpdated
;
fsw
.
Changed
+=
Status
File
Updated
;
fsw
.
EnableRaisingEvents
=
true
;
Log
.
Info
(
"{0} initialization completed."
,
AppTitle
);
...
...
@@ -153,7 +159,7 @@ namespace ATxTray
_miTxProgress
.
Click
+=
ShowContextMenu
;
_miTxEnqueue
.
Text
=
@"+++ Add new directory for transfer. +++"
;
_miTxEnqueue
.
Click
+=
Start
NewTransfer
;
_miTxEnqueue
.
Click
+=
PickDirectoryFor
NewTransfer
;
_miTxProgressBar
.
ToolTipText
=
@"Current Transfer Progress"
;
_miTxProgressBar
.
Value
=
0
;
...
...
@@ -210,35 +216,35 @@ namespace ATxTray
return
;
}
UpdateS
vcRunning
();
ReadStatus
();
// update the status no matter if the service process is running
UpdateS
erviceProcessState
();
UpdateStatusInformation
();
// update the status no matter if the service process is running
var
s
ervice
Running
=
"stopped"
;
var
h
eart
B
eat
=
"?"
;
var
s
vcProcess
Running
=
"stopped"
;
var
statusH
eart
b
eat
=
"?"
;
var
txProgress
=
"No"
;
if
(
_s
vcRunning
)
{
s
ervice
Running
=
"OK"
;
if
(
_s
erviceProcessAlive
)
{
s
vcProcess
Running
=
"OK"
;
if
((
DateTime
.
Now
-
_status
.
LastStatusUpdate
).
TotalSeconds
<=
60
)
h
eart
B
eat
=
"OK"
;
statusH
eart
b
eat
=
"OK"
;
if
(
_txInProgress
)
txProgress
=
$"
{
_txProgressPct
}
%"
;
}
UpdateHoverText
(
$"AutoTx [svc=
{
s
ervice
Running
}
] [hb=
{
h
eart
B
eat
}
] [tx=
{
txProgress
}
]"
);
UpdateHoverText
(
$"AutoTx [svc=
{
s
vcProcess
Running
}
] [hb=
{
statusH
eart
b
eat
}
] [tx=
{
txProgress
}
]"
);
if
(!
_statusChanged
)
return
;
UpdateS
vc
Suspended
();
UpdateS
ervice
Suspended
State
();
UpdateTxProgressBar
();
UpdateTxInProgress
();
UpdateTxInProgress
State
();
UpdateTrayIcon
();
_statusChanged
=
false
;
}
private
static
void
StatusUpdated
(
object
sender
,
FileSystemEventArgs
e
)
{
private
static
void
Status
File
Updated
(
object
sender
,
FileSystemEventArgs
e
)
{
_statusFileChanged
=
true
;
}
...
...
@@ -248,7 +254,7 @@ namespace ATxTray
_notifyIcon
.
ContextMenuStrip
.
Show
();
}
private
static
void
Start
NewTransfer
(
object
sender
,
EventArgs
e
)
{
private
static
void
PickDirectoryFor
NewTransfer
(
object
sender
,
EventArgs
e
)
{
if
(!
Directory
.
Exists
(
_submitPath
))
{
Log
.
Error
(
"Current user has no incoming directory: [{0}]"
,
_submitPath
);
MessageBox
.
Show
(
$@"User '
{
Environment
.
UserName
}
' is not allowed to start transfers!"
,
...
...
@@ -276,10 +282,10 @@ namespace ATxTray
return
;
}
ReviewNewTx
Dialog
();
NewTxConfirmation
Dialog
();
}
private
static
void
ReviewNewTx
Dialog
()
{
private
static
void
NewTxConfirmation
Dialog
()
{
var
folderName
=
_selectedDir
.
Name
;
var
locationPath
=
_selectedDir
.
Parent
?.
FullName
;
var
size
=
Conv
.
BytesToString
(
FsUtils
.
GetDirectorySize
(
_selectedDir
.
FullName
));
...
...
@@ -322,7 +328,7 @@ namespace ATxTray
@"Press [OK] to confirm selection."
,
caption
,
MessageBoxButtons
.
OKCancel
,
MessageBoxIcon
.
Question
);
if
(
res
==
DialogResult
.
OK
)
SubmitDirFor
Transfer
();
SubmitDirFor
NewTx
();
}
}
...
...
@@ -333,16 +339,16 @@ namespace ATxTray
private
static
void
ConfirmAcceptClick
(
object
sender
,
EventArgs
e
)
{
_confirmDialog
.
Close
();
SubmitDirFor
Transfer
();
SubmitDirFor
NewTx
();
}
private
static
void
ConfirmChangeClick
(
object
sender
,
EventArgs
e
)
{
_confirmDialog
.
Close
();
Log
.
Debug
(
"User wants to change directory choice."
);
Start
NewTransfer
(
sender
,
e
);
PickDirectoryFor
NewTransfer
(
sender
,
e
);
}
private
static
void
SubmitDirFor
Transfer
()
{
private
static
void
SubmitDirFor
NewTx
()
{
Log
.
Debug
(
$"User accepted directory choice [
{
_selectedDir
.
FullName
}
]."
);
var
tgtPath
=
Path
.
Combine
(
_submitPath
,
_selectedDir
.
Name
);
try
{
...
...
@@ -361,7 +367,7 @@ namespace ATxTray
/// <summary>
/// Read (or re-read) the service status file if it has changed since last time.
/// </summary>
private
static
void
ReadStatus
()
{
private
static
void
UpdateStatusInformation
()
{
if
(!
_statusFileChanged
)
return
;
...
...
@@ -375,18 +381,18 @@ namespace ATxTray
/// Check if a process with the expeced name of the service is currently running.
/// </summary>
/// <returns>True if such a process exists, false otherwise.</returns>
private
static
bool
ServiceProcess
Running
()
{
private
static
bool
Is
ServiceProcess
Alive
()
{
var
plist
=
Process
.
GetProcessesByName
(
"AutoTx"
);
return
plist
.
Length
>
0
;
}
private
void
UpdateS
vcRunning
()
{
var
curSvcRunStat
e
=
ServiceProcess
Running
();
if
(
_s
vcRunning
==
curSvcRunStat
e
)
private
void
UpdateS
erviceProcessState
()
{
var
isServiceProcessAliv
e
=
Is
ServiceProcess
Alive
();
if
(
_s
erviceProcessAlive
==
isServiceProcessAliv
e
)
return
;
_s
vcRunning
=
curSvcRunStat
e
;
if
(
_s
vcRunning
)
{
_s
erviceProcessAlive
=
isServiceProcessAliv
e
;
if
(
_s
erviceProcessAlive
)
{
_miSvcRunning
.
Text
=
@"Service running."
;
_miSvcRunning
.
BackColor
=
Color
.
LightGreen
;
_miTitle
.
BackColor
=
Color
.
LightGreen
;
...
...
@@ -407,17 +413,17 @@ namespace ATxTray
}
}
private
void
UpdateS
vc
Suspended
()
{
private
void
UpdateS
ervice
Suspended
State
()
{
// 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
(
_s
vc
SuspendReason
==
_status
.
LimitReason
&&
_s
vc
Suspended
==
_status
.
ServiceSuspended
)
if
(
_s
ervice
SuspendReason
==
_status
.
LimitReason
&&
_s
ervice
Suspended
==
_status
.
ServiceSuspended
)
return
;
_s
vc
Suspended
=
_status
.
ServiceSuspended
;
_s
vc
SuspendReason
=
_status
.
LimitReason
;
if
(
_s
vc
Suspended
)
{
_miSvcSuspended
.
Text
=
@"Service suspended, reason: "
+
_s
vc
SuspendReason
;
_s
ervice
Suspended
=
_status
.
ServiceSuspended
;
_s
ervice
SuspendReason
=
_status
.
LimitReason
;
if
(
_s
ervice
Suspended
)
{
_miSvcSuspended
.
Text
=
@"Service suspended, reason: "
+
_s
ervice
SuspendReason
;
_miSvcSuspended
.
BackColor
=
Color
.
LightSalmon
;
/*
_notifyIcon.ShowBalloonTip(500, "AutoTx Monitor",
...
...
@@ -433,7 +439,7 @@ namespace ATxTray
}
}
private
void
UpdateTxInProgress
()
{
private
void
UpdateTxInProgress
State
()
{
if
(
_txInProgress
==
_status
.
TransferInProgress
&&
_txSize
==
_status
.
CurrentTransferSize
)
return
;
...
...
@@ -473,8 +479,7 @@ namespace ATxTray
}
private
void
UpdateTrayIcon
()
{
if
(
_txInProgress
&&
!
_svcSuspended
)
{
if
(
_txInProgress
&&
!
_serviceSuspended
)
{
if
(
DateTime
.
Now
.
Second
%
2
==
0
)
{
_notifyIcon
.
Icon
=
_tiTx0
;
}
else
{
...
...
@@ -485,12 +490,12 @@ namespace ATxTray
if
(!
_statusChanged
)
return
;
if
(!
_s
vcRunning
)
{
if
(!
_s
erviceProcessAlive
)
{
_notifyIcon
.
Icon
=
_tiStopped
;
return
;
}
if
(
_s
vc
Suspended
)
{
if
(
_s
ervice
Suspended
)
{
_notifyIcon
.
Icon
=
_tiSuspended
;
return
;
}
...
...
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