//runs the extraction private bool runExtraction() { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = Support.InstalPath + "resources\\piconfig.exe"; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.Start(); string input = configInput(); process.StandardInput.Write(input); process.StandardInput.Flush(); process.StandardInput.Close(); string result = (process.StandardOutput.ReadToEnd()); string[] results = result.Split(new string[] { "\r\n" }, StringSplitOptions.None); string finalresult = ""; string dataline = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss"); string datalineout = DateTime.Now.ToString("yyyyMMdd_HHmmss"); string datalines = "Timestamp"; if (Mtrx == "0") { for (int i = 0; i < results.Length; i++) { //Selects only usefull info (removes alerts, erros and other messages) if (results[i].Contains(",") == true) { string[] thisline = results[i].Split(','); if (thisline.Length == 3) { DateTime timestamp; if (DateTime.TryParse(thisline[1], out timestamp)) { thisline[1] = timestamp.ToString("yyyyMMdd_HHmmss"); if (Inte == "1") { thisline[1] = datalineout; } if (thisline[2] == "Digital State") { thisline[2] = ""; } finalresult = finalresult + thisline[0] + ";" + thisline[1] + ";" + thisline[2] + "\r\n"; } } } } } else { List <string> tags = new List <string>(); List <string> times = new List <string>(); //for each line from response for (int i = 0; i < results.Length; i++) { //if line is data (non data line wont contain the "," char) if (results[i].Contains(",") == true) { string[] thisline = results[i].Split(','); if (thisline.Length == 3) { //add tag to tag array if (!tags.Contains(thisline[0])) { tags.Add(thisline[0]); } //add times to time array string hora = thisline[1]; if (Inte == "1") { hora = dataline; } if (!times.Contains(hora)) { times.Add(hora); } } } } //creates data table (matrix format) string[,] table = new string[tags.Count(), times.Count()]; for (int i = 0; i < results.Length; i++) { if (results[i].Contains(",") == true) { string[] thisline = results[i].Split(','); if (thisline.Length == 3) { //add value to the spot on the table with corresponding tag and time string hora = thisline[1]; if (Inte == "1") { hora = dataline; } if (thisline[2] == "Digital State") { thisline[2] = ""; } table[tags.IndexOf(thisline[0]), times.IndexOf(hora)] = thisline[2]; } } } foreach (var tag in tags) { datalines += ";" + tag; } datalines += "\r\n"; foreach (var time in times) { DateTime timestamp; if (DateTime.TryParse(time, out timestamp)) { datalines += timestamp.ToString("yyyyMMdd_HHmmss"); foreach (var tag in tags) { string value = (table[tags.IndexOf(tag), times.IndexOf(time)] != null) ? table[tags.IndexOf(tag), times.IndexOf(time)] : ""; datalines += ";" + value.Replace(";", ""); } datalines += "\r\n"; } } finalresult = datalines; } string Outputpath = Regex.Split(OutP, @"(.*[\\|\/])([^\\|\/]*)")[1]; try { string filename = (Pref == "") ? ConfigName : Pref; File.AppendAllText(Outputpath + filename + "_" + datalineout + ".csv", finalresult); } catch (Exception exx) { LogFile.write_LogFile("Error saving output for config " + ConfigName + " with message: " + exx.Message); } process.WaitForExit(); return(true); }