[chronojump/execute-process] Uses ExecuteProcess class in chronopicRegister. It simplifies code and re-used with chronojump-impor
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/execute-process] Uses ExecuteProcess class in chronopicRegister. It simplifies code and re-used with chronojump-impor
- Date: Tue, 4 Oct 2016 22:04:24 +0000 (UTC)
commit 6f5e64950036436abcf9879fa2f25fe0e8cc6e57
Author: Carles Pina i Estany <carles pina cat>
Date: Wed Oct 5 00:03:41 2016 +0200
Uses ExecuteProcess class in chronopicRegister. It simplifies code and re-used with chronojump-importer.
src/chronopicRegister.cs | 51 +++++++--------------------------------------
1 files changed, 8 insertions(+), 43 deletions(-)
---
diff --git a/src/chronopicRegister.cs b/src/chronopicRegister.cs
index 69e3e5b..9e97347 100644
--- a/src/chronopicRegister.cs
+++ b/src/chronopicRegister.cs
@@ -246,47 +246,17 @@ public class ChronopicRegisterLinux : ChronopicRegister
//new: udevadm info -p $(udevadm info -q path -n /dev/ttyUSB0)
//TODO: find a way to call this in only one process
- ProcessStartInfo pinfo = new ProcessStartInfo();
- string pBin = "udevadm";
- pinfo.FileName=pBin;
-
- pinfo.CreateNoWindow = true;
- pinfo.UseShellExecute = false;
- pinfo.RedirectStandardError = true;
- pinfo.RedirectStandardOutput = true;
-
- //1) get path
- pinfo.Arguments = "info -q path -n " + crp.Port;
- LogB.Information("Arguments:", pinfo.Arguments);
-
- Process p = new Process();
- p.StartInfo = pinfo;
- p.Start();
-
- string path = p.StandardOutput.ReadToEnd();
- LogB.Information(path);
- string error = p.StandardError.ReadToEnd();
-
- p.WaitForExit();
-
- if(error != "") {
- LogB.Error(error);
- return crp;
- }
-
- //2) read FTDI info
- pinfo.Arguments = "info -p " + path;
- LogB.Information("Arguments:", pinfo.Arguments);
-
- p = new Process();
- p.StartInfo = pinfo;
- p.Start();
+ //1) get path
+ List<string> parameters = new List<string> { "info", "-q", "path", "-n", crp.Port };
+ ExecuteProcess.Result result = ExecuteProcess.runShowErrorIfNotStarted ("udevadm",
parameters);
+ string path = result.stdout;
- error = p.StandardError.ReadToEnd();
+ //2) read FTDI info
+ parameters = new List<string> { "info", "-p", path };
+ result = ExecuteProcess.runShowErrorIfNotStarted ("udevadm", parameters);
- while (! p.StandardOutput.EndOfStream)
+ foreach (string lineOut in result.stdout.Split('\n'))
{
- string lineOut = p.StandardOutput.ReadLine();
if (lineOut.Contains("ID_VENDOR=")) {
string [] strFull = lineOut.Split(new char[] {'='});
crp.FTDI = (strFull[1] == "FTDI");
@@ -295,11 +265,6 @@ public class ChronopicRegisterLinux : ChronopicRegister
crp.SerialNumber = strFull[1];
}
}
- p.WaitForExit();
-
- if(error != "")
- LogB.Error(error);
-
return crp;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]