[chronojump] exhibitionTest temp upload with transaction



commit 422ad290f55aad49b7ff495bb527cd9791155627
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Mar 1 14:13:46 2019 +0100

    exhibitionTest temp upload with transaction

 src/gui/chronojump.cs  |  4 ++--
 src/gui/encoder.cs     |  2 +-
 src/gui/exhibition.cs  | 37 ++++---------------------------------
 src/gui/forceSensor.cs |  2 +-
 src/gui/networks.cs    |  2 +-
 src/sqlite/json.cs     | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
 6 files changed, 55 insertions(+), 41 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 9d447a88..24e14f4a 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -4500,7 +4500,7 @@ public partial class ChronoJumpWindow
                                sensitiveGuiYesEvent();
 
                        if(configChronojump.Exhibition && configChronojump.ExhibitionStationType == 
ExhibitionTest.testTypes.JUMP)
-                               uploadExhibitionTest(ExhibitionTest.testTypes.JUMP, 
Convert.ToDouble(Util.GetHeightInCentimeters(currentJump.Tv.ToString())));
+                               
SqliteJson.UploadExhibitionTest(getExhibitionTestFromGui(ExhibitionTest.testTypes.JUMP, 
Convert.ToDouble(Util.GetHeightInCentimeters(currentJump.Tv.ToString()))));
                } 
                else if( currentEventExecute.ChronopicDisconnected )
                        chronopicDisconnectedWhileExecuting();
@@ -4944,7 +4944,7 @@ public partial class ChronoJumpWindow
                        event_execute_LabelTimeValue = currentRun.Time;
 
                        if(configChronojump.Exhibition && configChronojump.ExhibitionStationType == 
ExhibitionTest.testTypes.RUN)
-                               uploadExhibitionTest(ExhibitionTest.testTypes.RUN, currentRun.Time);
+                               
SqliteJson.UploadExhibitionTest(getExhibitionTestFromGui(ExhibitionTest.testTypes.RUN, currentRun.Time));
                }
                else if( currentEventExecute.ChronopicDisconnected )
                        chronopicDisconnectedWhileExecuting();
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 76e144bd..bec0178c 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -6983,7 +6983,7 @@ public partial class ChronoJumpWindow
                                                {
                                                        UploadEncoderDataObject uo = new 
UploadEncoderDataObject(
                                                                        encoderCaptureCurves, 
lastEncoderSQLSignal.eccon);
-                                                       
uploadExhibitionTest(ExhibitionTest.testTypes.INERTIAL, Convert.ToDouble(uo.pmeanByPower));
+                                                       
SqliteJson.UploadExhibitionTest(getExhibitionTestFromGui(ExhibitionTest.testTypes.INERTIAL, 
Convert.ToDouble(uo.pmeanByPower)));
 
                                                }
                                        }
diff --git a/src/gui/exhibition.cs b/src/gui/exhibition.cs
index 7d22b46b..7b6c0771 100644
--- a/src/gui/exhibition.cs
+++ b/src/gui/exhibition.cs
@@ -21,7 +21,6 @@
 using System;
 using Gtk;
 using Glade;
-using System.Collections.Generic; //List
 
 public partial class ChronoJumpWindow 
 {
@@ -177,41 +176,13 @@ public partial class ChronoJumpWindow
                }
        }
 
-       //---- json upload
-
-       private void uploadExhibitionTest(ExhibitionTest.testTypes tt, double result)
+       //read from the widgets
+       //read testTypes and result
+       private ExhibitionTest getExhibitionTestFromGui(ExhibitionTest.testTypes tt, double result)
        {
-               Json js = new Json();
-               ExhibitionTest et = new ExhibitionTest(Convert.ToInt32(spin_exhibition_school.Value),
+               return new ExhibitionTest(Convert.ToInt32(spin_exhibition_school.Value),
                                Convert.ToInt32(spin_exhibition_group.Value),
                                currentPerson.UniqueID, tt, result);
-
-               if( ! js.UploadExhibitionTest (et))
-               {
-                       LogB.Error(js.ResultMessage);
-                       SqliteJson.InsertTempExhibitionTest(false, et); //insert only if could'nt be uploaded
-               }
-       }
-
-       private void uploadExhibitionTestsPending()
-       {
-               Json json = new Json();
-               Sqlite.Open(); // ---------------->
-
-               List<ExhibitionTest> listEtTemp = SqliteJson.SelectTempExhibitionTest(true);
-               if(listEtTemp.Count > 0)
-               {
-                       foreach(ExhibitionTest et in listEtTemp)
-                       {
-                               bool success = json.UploadExhibitionTest(et);
-                               LogB.Information(json.ResultMessage);
-                               if(success)
-                                       SqliteJson.DeleteTempExhibitionTest(true, et); //delete the record
-                       }
-               }
-
-               Sqlite.Close(); // <----------------
-
        }
 
 }
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index d23ba21e..ce773842 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -857,7 +857,7 @@ LogB.Information(" re C ");
                                        if( configChronojump.Exhibition &&
                                                        ( configChronojump.ExhibitionStationType == 
ExhibitionTest.testTypes.FORCE_ROPE ||
                                                          configChronojump.ExhibitionStationType == 
ExhibitionTest.testTypes.FORCE_SHOT ) )
-                                               uploadExhibitionTest(configChronojump.ExhibitionStationType, 
forceSensorValues.ForceMax);
+                                               
SqliteJson.UploadExhibitionTest(getExhibitionTestFromGui(configChronojump.ExhibitionStationType, 
forceSensorValues.ForceMax));
 
                                }
                        } else if(forceProcessCancel || forceProcessError)
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 98be0c83..f7091ff8 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -201,7 +201,7 @@ public partial class ChronoJumpWindow
                if(configChronojump.Exhibition)
                {
                        exhibitionGuiAtStart(configChronojump.ExhibitionStationType);
-                       uploadExhibitionTestsPending();
+                       SqliteJson.UploadExhibitionTestsPending();
                }
 
                configDo();
diff --git a/src/sqlite/json.cs b/src/sqlite/json.cs
index 4deb3507..bf4da476 100644
--- a/src/sqlite/json.cs
+++ b/src/sqlite/json.cs
@@ -234,6 +234,45 @@ class SqliteJson : Sqlite
         * EXHIBITION //right now does not upload to server when connection returns
         */
 
+       public static void UploadExhibitionTest(ExhibitionTest et)
+       {
+               Json js = new Json();
+               if( ! js.UploadExhibitionTest (et))
+               {
+                       LogB.Error(js.ResultMessage);
+                       SqliteJson.InsertTempExhibitionTest(false, et); //insert only if could'nt be uploaded
+               }
+       }
+
+       //each one record needs 0.9 seconds
+       public static void UploadExhibitionTestsPending()
+       {
+               Json json = new Json();
+               Sqlite.Open(); // ---------------->
+
+               List<ExhibitionTest> listEtTemp = SqliteJson.SelectTempExhibitionTest(true);
+               if(listEtTemp.Count > 0)
+               {
+                       using(SqliteTransaction tr = dbcon.BeginTransaction())
+                       {
+                               using (SqliteCommand dbcmdTr = dbcon.CreateCommand())
+                               {
+                                       dbcmdTr.Transaction = tr;
+
+                                       foreach(ExhibitionTest et in listEtTemp)
+                                       {
+                                               bool success = json.UploadExhibitionTest(et);
+                                               LogB.Information(json.ResultMessage);
+                                               if(success)
+                                                       SqliteJson.DeleteTempExhibitionTest(true, et, 
dbcmdTr); //delete the record
+                                       }
+                               }
+                               tr.Commit();
+                       }
+               }
+               Sqlite.Close(); // <----------------
+       }
+
        protected internal static void createTableUploadExhibitionTestTemp()
        {
                dbcmd.CommandText =
@@ -292,17 +331,21 @@ class SqliteJson : Sqlite
        }
 
        public static void DeleteTempExhibitionTest(bool dbconOpened, ExhibitionTest et)
+       {
+               DeleteTempExhibitionTest(dbconOpened, et, dbcmd);
+       }
+       public static void DeleteTempExhibitionTest(bool dbconOpened, ExhibitionTest et, SqliteCommand mycmd)
        {
                openIfNeeded(dbconOpened);
 
-               dbcmd.CommandText = "Delete FROM " + tableExhibitionTest + " WHERE " +
+               mycmd.CommandText = "Delete FROM " + tableExhibitionTest + " WHERE " +
                        "schoolID = " + et.schoolID + " AND " +
                        "groupID = " + et.groupID + " AND " +
                        "personID = " + et.personID + " AND " +
                        "testType = \"" + et.testType.ToString() + "\" AND " +
                        "result = " + et.resultToJson;
-               LogB.SQL(dbcmd.CommandText.ToString());
-               dbcmd.ExecuteNonQuery();
+               LogB.SQL(mycmd.CommandText.ToString());
+               mycmd.ExecuteNonQuery();
 
                closeIfNeeded(dbconOpened);
        }


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