[chronojump/execute-process: 4/5] Uses ExecuteProcess class in chronopicRegister. It simplifies code and re-used with chronojump-impor



commit 937a8753a2b1909f142e0f99a1e119f9f74c30a6
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 |   53 +++++++++++----------------------------------
 1 files changed, 13 insertions(+), 40 deletions(-)
---
diff --git a/src/chronopicRegister.cs b/src/chronopicRegister.cs
index 69e3e5b..4fc8cf6 100644
--- a/src/chronopicRegister.cs
+++ b/src/chronopicRegister.cs
@@ -246,47 +246,25 @@ 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);
+               //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;
+
+               if (result.stderr != "") {
                        return crp;
                }
-               
+
                //2) read FTDI info     
-               pinfo.Arguments = "info -p " + path;
-               LogB.Information("Arguments:", pinfo.Arguments);
-               
-               p = new Process();
-               p.StartInfo = pinfo;
-               p.Start();
+               parameters = new List<string> { "info", "-p", path };
+               result = ExecuteProcess.runShowErrorIfNotStarted ("udevadm", parameters);
 
-               error = p.StandardError.ReadToEnd();
+               if (result.stderr != "") {
+                       return crp;
+               }
 
-               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 +273,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]