[chronojump] Networks send mail to admin now attach CSV (UNTESTED!)



commit ddf03ea3d6d646cabbb6f6bf30bedbdb3bac85db
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Dec 21 18:23:07 2021 +0100

    Networks send mail to admin now attach CSV (UNTESTED!)

 src/gui/app1/encoder.cs | 17 +++++++++++++----
 src/gui/networks.cs     | 15 +++++++++++++--
 src/networks.cs         |  9 +++++++--
 3 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/src/gui/app1/encoder.cs b/src/gui/app1/encoder.cs
index 0a00063af..d2db3c3b0 100644
--- a/src/gui/app1/encoder.cs
+++ b/src/gui/app1/encoder.cs
@@ -2449,7 +2449,7 @@ public partial class ChronoJumpWindow
                                        else if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_AB)
                                                on_button_encoder_save_AB_file_selected (exportFileName);
                                        else if(checkFileOp == 
Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE)
-                                               on_button_encoder_save_table_file_selected (exportFileName);
+                                               on_button_encoder_save_table_file_selected (exportFileName, 
true);
                                        else if(checkFileOp == 
Constants.CheckFileOp.FORCESENSOR_SAVE_IMAGE_SIGNAL)
                                                on_button_forcesensor_save_image_signal_file_selected 
(exportFileName);
                                        else if(checkFileOp == 
Constants.CheckFileOp.FORCESENSOR_SAVE_IMAGE_RFD_AUTO)
@@ -2688,7 +2688,7 @@ public partial class ChronoJumpWindow
        }
        private void on_overwrite_file_encoder_save_table_accepted(object o, EventArgs args)
        {
-               on_button_encoder_save_table_file_selected (exportFileName);
+               on_button_encoder_save_table_file_selected (exportFileName, true);
 
                string myString = string.Format(Catalog.GetString("Saved to {0}"), exportFileName);
                new DialogMessage(Constants.MessageTypes.INFO, myString);
@@ -4957,7 +4957,11 @@ public partial class ChronoJumpWindow
                checkFile(Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_TABLE);
        }
 
-       void on_button_encoder_save_table_file_selected (string destination)
+       /*
+          if gui then can open a DialogMessage
+          if !gui is eg when sending an email, a dialogMessage will not be opened here
+          */
+       private bool on_button_encoder_save_table_file_selected (string destination, bool gui)
        {
                try {
                        //this overwrites if needed
@@ -5004,8 +5008,13 @@ public partial class ChronoJumpWindow
                } catch {
                        string myString = string.Format(
                                        Catalog.GetString("Cannot save file {0} "), destination);
-                       new DialogMessage(Constants.MessageTypes.WARNING, myString);
+                       if(gui)
+                               new DialogMessage(Constants.MessageTypes.WARNING, myString);
+
+                       return false;
                }
+
+               return true;
        }
 
        void on_button_encoder_analyze_1RM_save_clicked (object o, EventArgs args)
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index f1e0d99d6..4b928643d 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -1206,11 +1206,22 @@ public partial class ChronoJumpWindow
                {
                        LogB.Information("Sending Email to: " + configChronojump.CompujumpAdminEmail);
 
+                       LogB.Information("Creating CSV ...");
+
+                       string tableFile = "/tmp/table.csv";
+                       //save the csv, but if does not work, leave tableFile empty so it will not be sent
+                       if(! on_button_encoder_save_table_file_selected (tableFile, false))
+                               tableFile = "";
+                       //another option would be use the txt: chronojump-last-encoder-analyze-table.txt
+
+                       LogB.Information("CSV created!");
+
                        NetworksSendMail nsm = new NetworksSendMail ();
-                       if(nsm.Send(exportFileName, UtilEncoder.GetEncoderGraphTempFileName(), 
configChronojump.CompujumpAdminEmail))
+                       if(nsm.Send(exportFileName, UtilEncoder.GetEncoderGraphTempFileName(),
+                                               tableFile, configChronojump.CompujumpAdminEmail))
                        {
                                rfidWaitingAdminGuiObjects.ShowGuiMessageSuccess = true;
-                               LogB.Information("Done!");
+                               LogB.Information("Sent!");
                        } else {
                                rfidWaitingAdminGuiObjects.ShowGuiMessageFailed = true;
                                //no GTK here
diff --git a/src/networks.cs b/src/networks.cs
index ad02d6043..aa703d93e 100644
--- a/src/networks.cs
+++ b/src/networks.cs
@@ -113,7 +113,7 @@ public class NetworksSendMail
                ErrorStr = "";
        }
 
-       public bool Send (string title, string filename, string email)
+       public bool Send (string title, string filenameImage, string filenameCSV, string email)
        {
                //echo "See attached file" |mailx -s "$HOSTNAME Testing attachment" -A 
/home/chronojump/chronojump/images/calendar.png testing chronojump org
 
@@ -122,7 +122,12 @@ public class NetworksSendMail
                //parameters.Add("\"myHostName: myTitle\"");
                parameters.Add("ChronojumpNetworks: " + title);
                parameters.Add("-A");
-               parameters.Add(filename);
+               parameters.Add(filenameImage);
+               if(filenameCSV != "")
+               {
+                       parameters.Add("-A");
+                       parameters.Add(filenameCSV);
+               }
                parameters.Add(email);
 
                //note redirect output and error is false because if redirect input there are problems 
redirecting the others


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]