[chronojump] networks send email fills ok title and body



commit 9a6a0a637b00c220579a279a8644a7034dad95bd
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jul 19 13:02:00 2019 +0200

    networks send email fills ok title and body

 src/constants.cs    |  1 +
 src/gui/encoder.cs  | 20 ++++++++++++++++----
 src/gui/networks.cs |  8 +++++---
 src/networks.cs     | 23 ++++++++++++++++++++---
 4 files changed, 42 insertions(+), 10 deletions(-)
---
diff --git a/src/constants.cs b/src/constants.cs
index 0db2712c..88fc029d 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -815,6 +815,7 @@ public class Constants
                JUMPS_PROFILE_SAVE_IMAGE,
                RUNS_SPRINT_SAVE_IMAGE,
                ENCODER_CAPTURE_EXPORT_ALL, ENCODER_ANALYZE_SAVE_IMAGE,
+               ENCODER_ANALYZE_SEND_IMAGE, //like save image but just defines the name exportFileName to be 
sended
                ENCODER_ANALYZE_SAVE_AB, ENCODER_ANALYZE_SAVE_TABLE,
                FORCESENSOR_SAVE_IMAGE_SIGNAL, FORCESENSOR_SAVE_IMAGE_RFD_AUTO,
                FORCESENSOR_SAVE_IMAGE_RFD_MANUAL, FORCESENSOR_ANALYZE_SAVE_AB
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index effc063f..8cdaf0ff 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -2031,8 +2031,11 @@ public partial class ChronoJumpWindow
                string nameString = currentPerson.Name + "_" + currentSession.DateShortAsSQL;
 
                //on encoder analyze save image, show analysis on filename
-               if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE &&
-                               encoderLastAnalysis != "null" && encoderLastAnalysis != "")
+               if(
+                               ( checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE ||
+                               checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SEND_IMAGE )
+                               &&
+                               encoderLastAnalysis != "null" && encoderLastAnalysis != "" )
                {
                        nameString += "_" + encoderLastAnalysis;
                }
@@ -2048,6 +2051,13 @@ public partial class ChronoJumpWindow
                                nameString = lastForceSensorFile;
                }
 
+               //when we send an image we just want to define the name
+               if(checkFileOp == Constants.CheckFileOp.ENCODER_ANALYZE_SEND_IMAGE)
+               {
+                       exportFileName = nameString;
+                       return;
+               }
+
                if(checkFileOp == Constants.CheckFileOp.ENCODER_CAPTURE_EXPORT_ALL)
                        nameString += "_encoder_set_export.csv";
                else if(
@@ -4262,8 +4272,10 @@ public partial class ChronoJumpWindow
        void on_button_encoder_analyze_image_compujump_send_email_clicked (object o, EventArgs args)
        {
                if(configChronojump.CompujumpUserIsAdmin(currentPerson))
-                       compujumpSendEmail(Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE);
-               else
+               {
+                       checkFile(Constants.CheckFileOp.ENCODER_ANALYZE_SEND_IMAGE);
+                       compujumpSendEmail(Constants.CheckFileOp.ENCODER_ANALYZE_SEND_IMAGE);
+               } else
                {
                        LogB.Information("rfidWaitingAdminGuiObjects is null: " + (rfidWaitingAdminGuiObjects 
== null).ToString());
                        if(rfidWaitingAdminGuiObjects != null)
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 3c12604a..f039ff65 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -276,7 +276,8 @@ public partial class ChronoJumpWindow
 
        private void rfidAdminDetectedSendMail(object sender, EventArgs e)
        {
-               compujumpSendEmail(Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE);
+               checkFile(Constants.CheckFileOp.ENCODER_ANALYZE_SEND_IMAGE);
+               compujumpSendEmail(Constants.CheckFileOp.ENCODER_ANALYZE_SEND_IMAGE);
        }
 
        private void rfidDisconnected(object sender, EventArgs e)
@@ -998,12 +999,12 @@ public partial class ChronoJumpWindow
        //no GTK here because can be called from rfidChanged()
        private void compujumpSendEmail(Constants.CheckFileOp op)
        {
-               if(op == Constants.CheckFileOp.ENCODER_ANALYZE_SAVE_IMAGE)
+               if(op == Constants.CheckFileOp.ENCODER_ANALYZE_SEND_IMAGE)
                {
                        LogB.Information("Sending Email to: " + configChronojump.CompujumpAdminEmail);
 
                        NetworksSendMail nsm = new NetworksSendMail ();
-                       if(nsm.Send(UtilEncoder.GetEncoderGraphTempFileName(), 
configChronojump.CompujumpAdminEmail))
+                       if(nsm.Send(exportFileName, UtilEncoder.GetEncoderGraphTempFileName(), 
configChronojump.CompujumpAdminEmail))
                        {
                                rfidWaitingAdminGuiObjects.ShowGuiMessageSuccess = true;
                                LogB.Information("Done!");
@@ -1015,6 +1016,7 @@ public partial class ChronoJumpWindow
                        }
 
                }
+               //other future send email send objects
        }
 
        /*
diff --git a/src/networks.cs b/src/networks.cs
index c357dd97..1e0c0f8c 100644
--- a/src/networks.cs
+++ b/src/networks.cs
@@ -112,19 +112,20 @@ public class NetworksSendMail
                ErrorStr = "";
        }
 
-       public bool Send (string filename, string email)
+       public bool Send (string title, string filename, string email)
        {
                //echo "See attached file" |mailx -s "$HOSTNAME Testing attachment" -A 
/home/chronojump/chronojump/images/calendar.png testing chronojump org
 
                List<string> parameters = new List<string>();
                parameters.Add("-s");
-               parameters.Add("\"myHostName: myTitle\"");
+               //parameters.Add("\"myHostName: myTitle\"");
+               parameters.Add("ChronojumpNetworks: " + title);
                parameters.Add("-A");
                parameters.Add(filename);
                parameters.Add(email);
 
                //note redirect output and error is false because if redirect input there are problems 
redirecting the others
-               ExecuteProcess.Result execute_result = ExecuteProcess.run ("mail.mailutils", parameters, 
"myBody", false, false);
+               ExecuteProcess.Result execute_result = ExecuteProcess.run ("mail.mailutils", parameters, 
getBody(title), false, false);
                if(! execute_result.success) {
                        ErrorStr = "Need to install mail.mailutils";
                }
@@ -132,6 +133,22 @@ public class NetworksSendMail
                return execute_result.success;
        }
 
+       //currently on Spanish and Spanish date localization
+       private string getBody(string s)
+       {
+               string [] strFull = s.Split(new char[] {'_'}); //player_YYY-M-D_exercise
+
+               if(strFull.Length < 3)
+                       return "";
+
+               string dateString = "";
+               string [] strFullDate = strFull[1].Split(new char[] {'-'});
+               if(strFullDate.Length == 3)
+                       dateString = string.Format("Fecha: Día: {0}, Mes: {1}, Año: {2}", strFullDate[2], 
strFullDate[1], strFullDate[0]);
+
+               return string.Format("Gráfica del jugador: {0}\nTest: {1}\n{2}", strFull[0], strFull[2], 
dateString);
+       }
+
        // another option will be use C-sharp methods, see:
        // 
https://stackoverflow.com/questions/2825950/sending-email-with-attachments-from-c-attachments-arrive-as-part-1-2-in-thunde
 }


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