-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
190 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* ============================================================================== | ||
* | ||
* Filename: AdbServerKiller | ||
* Description: | ||
* | ||
* Version: 1.0 | ||
* Created: 2020/8/14 0:23:38 | ||
* Compiler: Visual Studio 2019 | ||
* | ||
* Author: zsh2401 | ||
* | ||
* ============================================================================== | ||
*/ | ||
using AutumnBox.Basic.ManagedAdb.CommandDriven; | ||
using AutumnBox.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace AutumnBox.Basic.Util | ||
{ | ||
internal sealed class LocalAdbServerKiller | ||
{ | ||
private const int MAX_TIMEOUT = 3000; | ||
private readonly ICommandProcedure commandKillServer; | ||
private readonly ILogger logger; | ||
public LocalAdbServerKiller(ICommandProcedure killServerCommand) | ||
{ | ||
logger = LoggerFactory.Auto<LocalAdbServerKiller>(); | ||
commandKillServer = killServerCommand ?? throw new ArgumentNullException(nameof(killServerCommand)); | ||
} | ||
|
||
public Task Kill() | ||
{ | ||
return Task.Run(() => | ||
{ | ||
commandKillServer.OutputReceived += (s, e) => | ||
{ | ||
SLogger.Info(this, $"{e.Text}"); | ||
}; | ||
commandKillServer.ExecuteAsync(); | ||
Thread.Sleep(MAX_TIMEOUT); | ||
if (commandKillServer.Status != CommandStatus.Executing && commandKillServer.Result.ExitCode == 0) | ||
{ | ||
commandKillServer.Cancel(); | ||
commandKillServer.Dispose(); | ||
KilProcesses(); | ||
} | ||
}); | ||
} | ||
|
||
private void KilProcesses() | ||
{ | ||
var psi = new ProcessStartInfo() | ||
{ | ||
FileName = "taskkill", | ||
Arguments = "/f /im adb.exe", | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
CreateNoWindow = true, | ||
UseShellExecute = false, | ||
}; | ||
var proc = Process.Start(psi); | ||
proc.BeginOutputReadLine(); | ||
proc.BeginErrorReadLine(); | ||
proc.OutputDataReceived += (s, e) => SLogger<LocalAdbServerKiller>.Info(e.Data); | ||
proc.ErrorDataReceived += (s, e) => SLogger<LocalAdbServerKiller>.Warn(e.Data); | ||
//proc.WaitForExit(); | ||
Thread.Sleep(MAX_TIMEOUT); | ||
if (proc.HasExited) | ||
{ | ||
if (proc.ExitCode != 0) | ||
{ | ||
logger.Warn("The command taskkil looks like not working. Exit code is " + proc.ExitCode); | ||
} | ||
logger.Info("The command taskkil has successfully executed."); | ||
} | ||
else | ||
{ | ||
logger.Warn("The command taskkil looks like not working."); | ||
} | ||
proc.CancelOutputRead(); | ||
proc.CancelErrorRead(); | ||
proc.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* ============================================================================== | ||
* | ||
* Filename: TraceLogger | ||
* Description: | ||
* | ||
* Version: 1.0 | ||
* Created: 2020/8/14 1:44:55 | ||
* Compiler: Visual Studio 2019 | ||
* | ||
* Author: zsh2401 | ||
* | ||
* ============================================================================== | ||
*/ | ||
using System.Diagnostics; | ||
|
||
namespace AutumnBox.Logging.Management | ||
{ | ||
public class TraceLogger : CoreLoggerBase | ||
{ | ||
public void Dispose() | ||
{ | ||
//pass | ||
} | ||
|
||
public override void Log(ILog log) | ||
{ | ||
Trace.WriteLine(log.ToFormatedString()); | ||
} | ||
} | ||
} |