Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Automatická detekce a dokumentace připojených USB zařízení - Bug Thugs
Manage
Activity
Members
Labels
Plan
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ASWI
ASWI 2022
Automatická detekce a dokumentace připojených USB zařízení - Bug Thugs
Merge requests
!31
re
#9568
Finished ld code refactoring
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
re
#9568
Finished ld code refactoring
ld-client-refactoring
into
ld-client-dev
Overview
0
Commits
5
Pipelines
0
Changes
9
Merged
Jakub Šilhavý
requested to merge
ld-client-refactoring
into
ld-client-dev
2 years ago
Overview
0
Commits
5
Pipelines
0
Changes
9
Expand
0
0
Merge request reports
Compare
ld-client-dev
ld-client-dev (base)
and
latest version
latest version
19c2a5c4
5 commits,
2 years ago
9 files
+
107
−
58
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
9
Search (e.g. *.vue) (Ctrl+P)
ld_client/LDClient/detection/InfoFetcher.cs
+
30
−
13
Options
using
System.Diagnostics
;
using
LDClient.utils.loggers
;
namespace
LDClient.detection
{
@@ -7,8 +8,9 @@ namespace LDClient.detection {
private
const
string
UndefinedSerialNumber
=
"number"
;
private
readonly
string
_f32RemExecutable
;
private
readonly
string
_f32RemArguments
;
private
readonly
string
[]
_f32RemArguments
;
private
readonly
int
_f32SuccessExitCode
;
private
readonly
int
_f32WaitTimeoutMs
;
private
readonly
uint
_maxAttempts
;
private
readonly
uint
_waitPeriodMs
;
private
readonly
string
_infoFilePath
;
@@ -16,17 +18,19 @@ namespace LDClient.detection {
public
string
HeadSerialNumber
{
get
;
private
set
;
}
=
UndefinedSerialNumber
;
public
string
BodySerialNumber
{
get
;
private
set
;
}
=
UndefinedSerialNumber
;
public
InfoFetcher
(
uint
maxAttempts
,
uint
waitPeriodMs
,
string
infoFilePath
,
string
f32RemExecutable
,
string
f32RemArguments
)
{
public
InfoFetcher
(
uint
maxAttempts
,
uint
waitPeriodMs
,
string
infoFilePath
,
string
f32RemExecutable
,
string
[]
f32RemArguments
,
int
f32SuccessExitCode
,
int
f32WaitTimeoutMs
)
{
_maxAttempts
=
maxAttempts
;
_waitPeriodMs
=
waitPeriodMs
;
_infoFilePath
=
infoFilePath
;
_f32RemExecutable
=
f32RemExecutable
;
_f32RemArguments
=
f32RemArguments
;
_f32SuccessExitCode
=
f32SuccessExitCode
;
_f32WaitTimeoutMs
=
f32WaitTimeoutMs
;
}
public
async
Task
<
bool
>
FetchDataAsync
()
{
Program
.
DefaultLogger
.
Info
(
"Fetching data from the debugger."
);
var
success
=
await
SendRetrieveInfoCommand
Async
(
_f32RemExecutable
,
_f32RemArguments
);
var
success
=
SendRetrieveInfoCommand
s
(
_f32RemExecutable
,
_f32RemArguments
,
_f32SuccessExitCode
,
_f32WaitTimeoutMs
);
if
(!
success
)
{
Program
.
DefaultLogger
.
Error
(
"Failed to fetch data from the debugger."
);
return
false
;
@@ -57,17 +61,30 @@ namespace LDClient.detection {
return
true
;
}
private
static
async
Task
<
bool
>
SendRetrieveInfoCommandAsync
(
string
executableFile
,
string
arguments
)
{
var
t32RemProcess
=
new
Process
();
t32RemProcess
.
StartInfo
.
FileName
=
executableFile
;
t32RemProcess
.
StartInfo
.
Arguments
=
arguments
;
try
{
t32RemProcess
.
Start
();
await
t32RemProcess
.
WaitForExitAsync
();
}
catch
(
Exception
exception
)
{
Program
.
DefaultLogger
.
Error
(
$"Failed to run
{
executableFile
}
.
{
exception
.
Message
}
"
);
private
static
bool
SendRetrieveInfoCommands
(
string
executableFile
,
IReadOnlyList
<
string
>?
arguments
,
int
successExitCode
,
int
waitTimeoutMs
)
{
if
(
arguments
==
null
)
{
Program
.
DefaultLogger
.
Error
(
$"Failed to run
{
executableFile
}
- no parameters were given"
);
return
false
;
}
foreach
(
var
argument
in
arguments
)
{
var
t32RemProcess
=
new
Process
();
t32RemProcess
.
StartInfo
.
FileName
=
executableFile
;
t32RemProcess
.
StartInfo
.
Arguments
=
argument
;
try
{
t32RemProcess
.
Start
();
if
(!
t32RemProcess
.
WaitForExit
(
waitTimeoutMs
))
{
Program
.
DefaultLogger
.
Error
(
$"Execution has not terminated within a predefined timeout of
{
waitTimeoutMs
}
ms"
);
return
false
;
}
if
(
t32RemProcess
.
ExitCode
!=
successExitCode
)
{
Program
.
DefaultLogger
.
Error
(
$"Execution terminated with an error code of
{
t32RemProcess
.
ExitCode
}
"
);
return
false
;
}
}
catch
(
Exception
exception
)
{
Program
.
DefaultLogger
.
Error
(
$"Failed to run
{
executableFile
}
{
argument
}
.
{
exception
.
Message
}
"
);
return
false
;
}
}
return
true
;
}
}
Loading