[chronojump] export session done!
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] export session done!
- Date: Mon, 29 Jun 2020 16:13:34 +0000 (UTC)
commit 192ecc39d3bac8b6c07cd502af9deca19ff6e62c
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Jun 29 18:12:32 2020 +0200
export session done!
glade/app1.glade | 121 ++++++++++++++++++-----------
src/gui/app1/session/backup.cs | 6 +-
src/gui/app1/session/export.cs | 105 ++++++++++++++++++++-----
src/sqlite/session.cs | 171 ++++++++++++++++++++++++++++++-----------
src/util.cs | 25 +++++-
5 files changed, 311 insertions(+), 117 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 421bb9a8..a9d5662d 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -24275,6 +24275,15 @@ Concentric</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -27120,18 +27129,6 @@ Concentric</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
- <widget class="GtkLabel"
id="label_video_encoder_tests_will_be_filmed">
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">Tests
will be filmed</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
<widget class="GtkHBox"
id="hbox_video_encoder_capturing">
<property name="can_focus">False</property>
<property name="spacing">4</property>
@@ -27168,6 +27165,18 @@ Concentric</property>
</packing>
</child>
<child>
+ <widget class="GtkLabel"
id="label_video_encoder_tests_will_be_filmed">
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Tests
will be filmed</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkHBox"
id="hbox_video_encoder_no_capturing">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -35103,6 +35112,15 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -36129,11 +36147,14 @@ then click this button.</property>
</packing>
</child>
<child>
- <widget class="GtkHButtonBox" id="hbuttonbox16">
+ <widget class="GtkHBox" id="hbox397">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">16</property>
- <property name="layout_style">spread</property>
+ <child>
+ <widget class="GtkHBox" id="hbox429">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
<child>
<widget class="GtkButton"
id="button_db_backup_pre">
<property name="visible">True</property>
@@ -36143,7 +36164,7 @@ then click this button.</property>
<property name="use_underline">True</property>
<signal name="clicked"
handler="on_button_db_backup_pre_clicked" swapped="no"/>
<child>
- <widget class="GtkHBox" id="hbox397">
+ <widget class="GtkHBox" id="hbox403">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
@@ -36175,7 +36196,7 @@ then click this button.</property>
</child>
</widget>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
@@ -36188,7 +36209,7 @@ then click this button.</property>
<property name="use_underline">True</property>
<signal name="clicked"
handler="on_button_data_folder_open_clicked" swapped="no"/>
<child>
- <widget class="GtkHBox" id="hbox403">
+ <widget class="GtkHBox" id="hbox430">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
@@ -36220,16 +36241,22 @@ then click this button.</property>
</child>
</widget>
<packing>
- <property name="expand">True</property>
+ <property name="expand">False</property>
<property name="fill">False</property>
- <property name="padding">10</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">True</property>
- <property name="fill">True</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
@@ -39660,14 +39687,26 @@ then click this button.</property>
</packing>
</child>
<child>
+ <widget class="GtkHBox" id="hbox431">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
<widget class="GtkLabel"
id="app1s_label_export_destination">
+ <property name="width_request">400</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="wrap">True</property>
- <property name="wrap_mode">word-char</property>
+ <property name="justify">center</property>
+ <property name="ellipsize">middle</property>
</widget>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
@@ -39690,6 +39729,7 @@ then click this button.</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_app1s_button_export_start_clicked" swapped="no"/>
<child>
<widget class="GtkLabel" id="label549">
<property name="visible">True</property>
@@ -39712,11 +39752,6 @@ then click this button.</property>
</packing>
</child>
<child>
- <widget class="GtkVBox" id="vbox230">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="spacing">20</property>
- <child>
<widget class="GtkHBox" id="hbox427">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -39724,29 +39759,18 @@ then click this button.</property>
<widget class="GtkHBox" id="hbox428">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">20</property>
<child>
- <widget class="GtkLabel"
id="app1s_label_export_progress">
+ <widget class="GtkProgressBar"
id="app1s_pulsebarExportActivity">
+ <property name="height_request">25</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
- <child>
- <widget class="GtkProgressBar"
id="app1s_pulsebarExportActivity">
- <property name="width_request">50</property>
- <property name="can_focus">False</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
</widget>
<packing>
<property name="expand">True</property>
@@ -39758,14 +39782,19 @@ then click this button.</property>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">0</property>
+ <property name="position">2</property>
</packing>
</child>
+ <child>
+ <widget class="GtkLabel"
id="app1s_label_export_progress">
+ <property name="width_request">400</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
</widget>
<packing>
<property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">2</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
</packing>
</child>
</widget>
diff --git a/src/gui/app1/session/backup.cs b/src/gui/app1/session/backup.cs
index e2896e6a..16526f4f 100644
--- a/src/gui/app1/session/backup.cs
+++ b/src/gui/app1/session/backup.cs
@@ -133,7 +133,7 @@ public partial class ChronoJumpWindow
} else {
//if multimedia_and_encoder, then copy the folder. If not checked, then copy
only the db file
//if(check_backup_multimedia_and_encoder.Active) {
- app1s_uc = new UtilCopy(-1); //all sessions
+ app1s_uc = new UtilCopy(-1, true); //all sessions, backup
app1s_threadBackup = new Thread(new ThreadStart(app1s_copyRecursive));
GLib.Idle.Add (new GLib.IdleHandler (app1s_BackupPulseGTK));
@@ -185,7 +185,7 @@ public partial class ChronoJumpWindow
app1s_pulsebarBackupDirs.Fraction = 1;
app1s_pulsebarBackupSecondDirs.Fraction = 1;
app1s_backup_doing_sensitive_start_end(false);
- app1s_fc.Hide ();
+ //app1s_fc.Hide ();
app1s_label_backup_progress.Text =
string.Format(Catalog.GetString("Copied in {0} ms"),
app1s_copyRecursiveElapsedMs);
@@ -216,7 +216,7 @@ public partial class ChronoJumpWindow
//if multimedia_and_encoder, then copy the folder. If not checked, then copy only the
db file
//if(check_backup_multimedia_and_encoder.Active) {
Directory.Delete(app1s_fileCopy, true);
- app1s_uc = new UtilCopy(-1); //all sessions
+ app1s_uc = new UtilCopy(-1, true); //all sessions, backup
app1s_threadBackup = new Thread(new ThreadStart(app1s_copyRecursive));
GLib.Idle.Add (new GLib.IdleHandler (app1s_BackupPulseGTK));
diff --git a/src/gui/app1/session/export.cs b/src/gui/app1/session/export.cs
index 015c4e18..a865e801 100644
--- a/src/gui/app1/session/export.cs
+++ b/src/gui/app1/session/export.cs
@@ -21,6 +21,7 @@
using System;
using System.IO;
using Gtk;
+using System.Collections.Generic;
using System.Diagnostics; //Stopwatch
using System.Threading;
using Mono.Unix;
@@ -40,6 +41,7 @@ public partial class ChronoJumpWindow
app1s_label_export_destination.Text = "";
app1s_label_export_progress.Text = "";
+ app1s_exportText = "";
app1s_button_export_select.Sensitive = true;
app1s_button_export_start.Sensitive = false;
app1s_button_export_cancel_close.Sensitive = true;
@@ -88,11 +90,12 @@ public partial class ChronoJumpWindow
ConfirmWindow confirmWin = ConfirmWindow.Show(Catalog.GetString("Are you sure
you want to overwrite: "), "", app1s_fileCopy);
confirmWin.Button_accept.Clicked += new
EventHandler(app1s_export_on_overwrite_file_accepted);
} else {
- app1s_uc = new UtilCopy(currentSession.UniqueID);
- app1s_threadExport = new Thread(new ThreadStart(app1s_copyRecursive));
+ app1s_pulsebarExportActivity.Visible = true;
+ app1s_uc = new UtilCopy(currentSession.UniqueID, false);
+ app1s_threadExport = new Thread(new ThreadStart(app1s_export));
GLib.Idle.Add (new GLib.IdleHandler (app1s_ExportPulseGTK));
-// app1s_backup_doing_sensitive_start_end(true);
+ app1s_export_doing_sensitive_start_end(true);
LogB.ThreadStart();
app1s_threadExport.Start();
@@ -107,40 +110,60 @@ public partial class ChronoJumpWindow
private bool app1s_ExportPulseGTK ()
{
if ( ! app1s_threadExport.IsAlive ) {
- /*
LogB.ThreadEnding();
app1s_ExportPulseEnd();
LogB.ThreadEnded();
- */
return false;
}
- /*
app1s_pulsebarExportActivity.Pulse();
- app1s_pulsebarExportDirs.Fraction = UtilAll.DivideSafeFraction(app1s_uc.ExportMainDirsCount,
6);
- //6 for: database, encoder, forceSensor, logs, multimedia, raceAnalyzer
-
- app1s_pulsebarExportDirs.Text = app1s_uc.LastMainDir;
- app1s_pulsebarExportSecondDirs.Fraction =
- UtilAll.DivideSafeFraction(app1s_uc.ExportSecondDirsCount,
app1s_uc.ExportSecondDirsLength);
- app1s_pulsebarExportSecondDirs.Text = app1s_uc.LastSecondDir;
+ app1s_label_export_progress.Text = app1s_exportText;
Thread.Sleep (30);
- //LogB.Debug(app1s_threadExport.ThreadState.ToString());
- */
+ LogB.Debug(app1s_threadExport.ThreadState.ToString());
return true;
}
+ private void app1s_ExportPulseEnd()
+ {
+ app1s_pulsebarExportActivity.Fraction = 1;
+ app1s_label_export_progress.Text =
+ string.Format(Catalog.GetString("Exported in {0} ms"),
+ app1s_exportElapsedMs);
+
+ app1s_export_doing_sensitive_start_end(false);
+ }
+
+ private void app1s_export_doing_sensitive_start_end(bool start)
+ {
+ if(start)
+ app1s_label_export_progress.Text = "";
+
+ app1s_pulsebarExportActivity.Visible = start;
+
+ app1s_button_export_select.Sensitive = ! start;
+ app1s_button_export_start.Sensitive = false;
+
+ if(start) {
+ app1s_button_export_cancel_close.Sensitive = false; //or make cancel sensitive while
process?
+ } else {
+ app1s_button_export_cancel_close.Sensitive = true;
+ app1s_label_export_cancel_close.Text = Catalog.GetString("Close");
+ }
+ }
+
private void app1s_export_on_overwrite_file_accepted(object o, EventArgs args)
{
try {
Directory.Delete(app1s_fileCopy, true);
- app1s_uc = new UtilCopy(currentSession.UniqueID);
- app1s_threadExport = new Thread(new ThreadStart(app1s_copyRecursive));
+
+ app1s_pulsebarExportActivity.Visible = true;
+ app1s_uc = new UtilCopy(currentSession.UniqueID, false);
+ app1s_threadExport = new Thread(new ThreadStart(app1s_export));
GLib.Idle.Add (new GLib.IdleHandler (app1s_ExportPulseGTK));
-// app1s_backup_doing_sensitive_start_end(true);
+ app1s_export_doing_sensitive_start_end(true);
LogB.ThreadStart();
app1s_threadExport.Start();
@@ -150,6 +173,7 @@ public partial class ChronoJumpWindow
}
}
+ static string app1s_exportText;
static long app1s_exportElapsedMs;
private void app1s_export()
{
@@ -157,12 +181,53 @@ public partial class ChronoJumpWindow
Stopwatch sw = new Stopwatch();
sw.Start();
+ app1s_exportText = Catalog.GetString("Copying files");
+
+ //TODO: copy only needed multimedia (photos), videos are discarded by sessions
app1s_uc.CopyFilesRecursively(new DirectoryInfo(Util.GetParentDir(false)), new
DirectoryInfo(app1s_fileCopy), 0);
- //TODO: now need to open database and delete unwanted sessions, and all stuff related to
those sessions
+ //TODO: check that db exists and manage sessionSwitcher to go back
+ string exportedDB = app1s_fileCopy + System.IO.Path.DirectorySeparatorChar +
+ "database" + System.IO.Path.DirectorySeparatorChar + "chronojump.db";
+ LogB.Information("exporting to:" + exportedDB);
+ if(! File.Exists(exportedDB))
+ {
+ //TODO: some error message
+ return;
+ }
+
+ SqliteSessionSwitcher sessionSwitcher = new SqliteSessionSwitcher
+ (SqliteSessionSwitcher.DatabaseType.EXPORT, exportedDB);
- sw.Stop();
+ /*
+ * TODO (optional): use this to have objects intead of strings []
+ List<Session> session_l = SqliteSession.SelectAll();
+ foreach(Session session in session_l)
+ if(session.UniqueID != currentSession.UniqueID)
+ SqliteSession.DeleteAllStuff(session.UniqueID.ToString());
+ */
+
+ string [] mySessions = sessionSwitcher.SelectAllSessions(""); //returns a string of values
separated by ':'
+ int count = 1;
+ foreach (string session in mySessions)
+ {
+ app1s_exportText = string.Format("Adjusting new database {0}/{1}", count,
mySessions.Length);
+ LogB.Information(string.Format("session: {0}", session));
+ string [] myStringFull = session.Split(new char[] {':'});
+ string sessionID = myStringFull[0];
+ if(sessionID != currentSession.UniqueID.ToString())
+ {
+ LogB.Information(string.Format("session: {0}, will be deleted", sessionID));
+ sessionSwitcher.DeleteAllStuff(sessionID);
+ }
+ count ++;
+ }
+
+ //TODO: check if we really need this
+ reloadSession(); //to use default db again
+
+ sw.Stop();
app1s_exportElapsedMs = sw.ElapsedMilliseconds;
}
diff --git a/src/sqlite/session.cs b/src/sqlite/session.cs
index 7ce52522..d55a47d3 100644
--- a/src/sqlite/session.cs
+++ b/src/sqlite/session.cs
@@ -38,6 +38,9 @@ public class SqliteSessionSwitcher
* Doing this SessionLoadWindow can display sessions from other databases when SessionLoadWindow
* is used to import sessions from another Chronojump database instead of displaying sessions of the
current
* database.
+ *
+ * on import we want to hide simulated, because we do not want to see that session
+ * on export we want to show it to delete it and all its tests
*/
private string databasePath;
private DatabaseType type;
@@ -71,13 +74,14 @@ public class SqliteSessionSwitcher
string[] allSessions = SqliteSession.SelectAllSessions (filterName, dbcon);
- // Filtered sessions will contain all sessions but not the "SIMULATED"
+ // on IMPORT, filtered sessions will contain all sessions but not the "SIMULATED"
List<string> filteredSessions = new List<string> ();
+ foreach(string session in allSessions)
+ {
+ if (type == DatabaseType.IMPORT && session.Split (':') [1] != "SIMULATED")
+ continue;
- foreach(string session in allSessions) {
- if (session.Split (':') [1] != "SIMULATED") {
- filteredSessions.Add (session);
- }
+ filteredSessions.Add (session);
}
return filteredSessions.ToArray();
@@ -126,6 +130,22 @@ public class SqliteSessionSwitcher
return mySession;
}
}
+
+ //for export session
+ //TODO; at the moment use the above string[] SelectAllSessions(string filterName)
+ /*
+ public List<Session> SelectAll()
+ {
+ }
+ */
+
+ public void DeleteAllStuff(string sessionID)
+ {
+ SqliteGeneral sqliteGeneral = new SqliteGeneral(databasePath);
+ SqliteConnection dbcon = sqliteGeneral.connection;
+
+ SqliteSession.DeleteAllStuff (sessionID, dbcon);
+ }
}
class SqliteSession : Sqlite
@@ -879,81 +899,140 @@ class SqliteSession : Sqlite
}
}
+ // It's used by export and receives a specific database
+ // we want to delete all stuff of unwanted sessions
+ public static void DeleteAllStuff(string sessionID, SqliteConnection dbcon)
+ {
+ Sqlite.Open();
+
+ deleteAllStuffDo (sessionID, dbcon, true);
+
+ Sqlite.Close();
+ }
- public static void DeleteAllStuff(string uniqueID)
+ // This is the usual chronojump's call (default database)
+ public static void DeleteAllStuff(string sessionID)
{
Sqlite.Open();
+ deleteAllStuffDo (sessionID, dbcon, false);
+
+ Sqlite.Close();
+ }
+
+ private static void deleteAllStuffDo (string sessionID, SqliteConnection dbcon, bool export)
+ {
+ LogB.Information("DeleteAllStuffDo 0");
+ dbcmd = dbcon.CreateCommand();
+
//delete the session
- dbcmd.CommandText = "Delete FROM " + Constants.SessionTable + " WHERE uniqueID == " +
uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.SessionTable + " WHERE uniqueID == " +
sessionID;
dbcmd.ExecuteNonQuery();
//delete relations (existance) within persons and sessions in this session
- dbcmd.CommandText = "Delete FROM " + Constants.PersonSessionTable + " WHERE sessionID == " +
uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.PersonSessionTable + " WHERE sessionID == " +
sessionID;
dbcmd.ExecuteNonQuery();
- Sqlite.deleteOrphanedPersons();
+ LogB.Information("DeleteAllStuffDo 1");
+ //TODO: take care on export to do that but passing dbcon
+ if(! export)
+ Sqlite.deleteOrphanedPersons();
+ LogB.Information("DeleteAllStuffDo 2");
//delete normal jumps
- dbcmd.CommandText = "Delete FROM " + Constants.JumpTable + " WHERE sessionID == " + uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.JumpTable + " WHERE sessionID == " + sessionID;
dbcmd.ExecuteNonQuery();
//delete repetitive jumps
- dbcmd.CommandText = "Delete FROM " + Constants.JumpRjTable + " WHERE sessionID == " +
uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.JumpRjTable + " WHERE sessionID == " +
sessionID;
dbcmd.ExecuteNonQuery();
//delete normal runs
- dbcmd.CommandText = "Delete FROM " + Constants.RunTable + " WHERE sessionID == " + uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.RunTable + " WHERE sessionID == " + sessionID;
dbcmd.ExecuteNonQuery();
//delete intervallic runs
- dbcmd.CommandText = "Delete FROM " + Constants.RunIntervalTable + " WHERE sessionID == " +
uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.RunIntervalTable + " WHERE sessionID == " +
sessionID;
dbcmd.ExecuteNonQuery();
//delete reaction times
- dbcmd.CommandText = "Delete FROM " + Constants.ReactionTimeTable + " WHERE sessionID == " +
uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.ReactionTimeTable + " WHERE sessionID == " +
sessionID;
dbcmd.ExecuteNonQuery();
//delete pulses
- dbcmd.CommandText = "Delete FROM " + Constants.PulseTable + " WHERE sessionID == " + uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.PulseTable + " WHERE sessionID == " +
sessionID;
dbcmd.ExecuteNonQuery();
//delete multiChronopic
- dbcmd.CommandText = "Delete FROM " + Constants.MultiChronopicTable + " WHERE sessionID == " +
uniqueID;
+ dbcmd.CommandText = "Delete FROM " + Constants.MultiChronopicTable + " WHERE sessionID == " +
sessionID;
dbcmd.ExecuteNonQuery();
//delete from encoder start ------>
- //signals
- ArrayList encoderArray = SqliteEncoder.Select(
- true, -1, -1, Convert.ToInt32(uniqueID), Constants.EncoderGI.ALL,
- -1, "signal", EncoderSQL.Eccons.ALL, "",
- false, true);
-
- foreach(EncoderSQL eSQL in encoderArray) {
- Util.FileDelete(eSQL.GetFullURL(false)); //signal, don't convertPathToR
- if(eSQL.videoURL != "")
- Util.FileDelete(eSQL.videoURL); //video
- Sqlite.Delete(true, Constants.EncoderTable, Convert.ToInt32(eSQL.uniqueID));
- }
-
- //curves
- encoderArray = SqliteEncoder.Select(
- true, -1, -1, Convert.ToInt32(uniqueID), Constants.EncoderGI.ALL,
- -1, "curve", EncoderSQL.Eccons.ALL, "",
- false, true);
-
- foreach(EncoderSQL eSQL in encoderArray) {
- Util.FileDelete(eSQL.GetFullURL(false)); //don't convertPathToR
- /* commented: curve has no video
- if(eSQL.videoURL != "")
- Util.FileDelete(eSQL.videoURL);
- */
- Sqlite.Delete(true, Constants.EncoderTable, Convert.ToInt32(eSQL.uniqueID));
- SqliteEncoder.DeleteSignalCurveWithCurveID(true, Convert.ToInt32(eSQL.uniqueID));
-
- //delete related triggers
- SqliteTrigger.DeleteByModeID(true, Convert.ToInt32(eSQL.uniqueID));
+ /*
+ * on export we only want to delete SQL stuff, because files of other sessions will not be
copied
+ * but note if we want to call some other SQL method, we need to take care to pass dbcon or
dbcmd
+ */
+ if(export)
+ {
+ // 1 get all the encoder signals of that session
+ dbcmd.CommandText = "SELECT uniqueID FROM " + Constants.EncoderTable +
+ " WHERE signalOrCurve = \"signal\"" +
+ " AND sessionID = " + sessionID;
+
+ SqliteDataReader reader;
+ reader = dbcmd.ExecuteReader();
+ List<string> signal_l = new List<string>();
+
+ // 2 delete all the EncoderSignalCurves (relation with signal and curves) of that
signals
+ while(reader.Read())
+ signal_l.Add(reader[0].ToString());
+
+ reader.Close();
+
+ foreach(string signal in signal_l)
+ {
+ dbcmd.CommandText = "Delete FROM " + Constants.EncoderSignalCurveTable +
+ " WHERE signalID = " + signal;
+ dbcmd.ExecuteNonQuery();
+ }
+
+ // 3 delete all encoder table stuff (signals and curves)
+ dbcmd.CommandText = "Delete FROM " + Constants.EncoderTable + " WHERE sessionID = " +
sessionID;
+ dbcmd.ExecuteNonQuery();
+ } else
+ {
+ //signals
+ ArrayList encoderArray = SqliteEncoder.Select(
+ true, -1, -1, Convert.ToInt32(sessionID), Constants.EncoderGI.ALL,
+ -1, "signal", EncoderSQL.Eccons.ALL, "",
+ false, true);
+
+ foreach(EncoderSQL eSQL in encoderArray) {
+ Util.FileDelete(eSQL.GetFullURL(false)); //signal, don't convertPathToR
+ if(eSQL.videoURL != "")
+ Util.FileDelete(eSQL.videoURL); //video
+ Sqlite.Delete(true, Constants.EncoderTable, Convert.ToInt32(eSQL.uniqueID));
+ }
+
+ //curves
+ encoderArray = SqliteEncoder.Select(
+ true, -1, -1, Convert.ToInt32(sessionID), Constants.EncoderGI.ALL,
+ -1, "curve", EncoderSQL.Eccons.ALL, "",
+ false, true);
+
+ foreach(EncoderSQL eSQL in encoderArray) {
+ Util.FileDelete(eSQL.GetFullURL(false)); //don't convertPathToR
+ /* commented: curve has no video
+ if(eSQL.videoURL != "")
+ Util.FileDelete(eSQL.videoURL);
+ */
+ Sqlite.Delete(true, Constants.EncoderTable, Convert.ToInt32(eSQL.uniqueID));
+ SqliteEncoder.DeleteSignalCurveWithCurveID(true,
Convert.ToInt32(eSQL.uniqueID));
+
+ //delete related triggers
+ SqliteTrigger.DeleteByModeID(true, Convert.ToInt32(eSQL.uniqueID));
+ }
}
//<------- delete from encoder end
diff --git a/src/util.cs b/src/util.cs
index 7215d17b..4566c234 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -2304,13 +2304,15 @@ public class UtilCopy
public string LastMainDir;
public string LastSecondDir;
private int sessionID;
+ private bool backup;
//to go faster on CopyFilesRecursively
static string backupDir = Util.GetDatabaseDir() + Path.DirectorySeparatorChar + "backup";
//-1 is the default on a backup, means all sessions (regular backup)
//4 will only copy files related to session 4 (for export session)
- public UtilCopy(int sessionID)
+ //on export do not copy logs
+ public UtilCopy(int sessionID, bool backup)
{
BackupMainDirsCount = 0;
BackupSecondDirsCount = 0;
@@ -2319,6 +2321,7 @@ public class UtilCopy
LastSecondDir = "";
this.sessionID = sessionID;
+ this.backup = backup;
}
//http://stackoverflow.com/a/58779
@@ -2330,13 +2333,16 @@ public class UtilCopy
{
if(level == 0)
{
+ if(! backup && Util.GetLastPartOfPath(dir.ToString()) == "logs")
+ continue;
+
BackupMainDirsCount ++;
LastMainDir = Util.GetLastPartOfPath (dir.ToString());
BackupSecondDirsCount = 0;
//LogB.Information("at level 0: " + dir);
} else if(level == 1)
{
- //discard the unwanted sessions
+ //on export, discard the unwanted sessions
if(sessionID > 0 &&
Util.IsNumber(Util.GetLastPartOfPath(dir.ToString()), false) &&
Convert.ToInt32(Util.GetLastPartOfPath(dir.ToString())) != sessionID)
{
@@ -2348,10 +2354,25 @@ public class UtilCopy
BackupSecondDirsCount ++;
LastSecondDir = Util.GetLastPartOfPath (dir.ToString());
//LogB.Information("at level 1: " + dir);
+ } else if(level == 2)
+ {
+ //on export, discard the unwanted sessions of multimedia videos
+ if(sessionID > 0 && dir.ToString().Contains("multimedia") &&
dir.ToString().Contains("videos") &&
+ Util.IsNumber(Util.GetLastPartOfPath(dir.ToString()),
false) &&
+
Convert.ToInt32(Util.GetLastPartOfPath(dir.ToString())) != sessionID)
+ {
+ LogB.Information("Discarded video dir: " + dir.ToString());
+ continue;
+ }
}
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name), level +1);
}
foreach (FileInfo file in source.GetFiles())
+ {
+ if(file.Name == "chronojump_running") //do not copy chronojump_running file
+ continue;
+
file.CopyTo(Path.Combine(target.FullName, file.Name));
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]