private static void on_server_upload_session_started() { int evalSID = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID")); try { ChronojumpServer myServer = new ChronojumpServer(); Log.WriteLine(myServer.ConnectDatabase()); int state = (int) Constants.ServerSessionStates.UPLOADINGSESSION; //create ServerSession based on Session currentSession ServerSession serverSession = new ServerSession(currentSession, evalSID, progName + " " + progVersion, Util.GetOS(), DateTime.Now, state); //if uploading session for first time if(currentSession.ServerUniqueID == Constants.ServerUndefinedID) { //upload ServerSession int idAtServer = myServer.UploadSession(serverSession); //update session currentSession (serverUniqueID) on client database currentSession.ServerUniqueID = idAtServer; SqliteSession.UpdateServerUniqueID(currentSession.UniqueID, currentSession.ServerUniqueID); } state = (int) Constants.ServerSessionStates.UPLOADINGDATA; myServer.UpdateSession(currentSession.ServerUniqueID, state); sessionUploadPersonData.testTypes = ""; string testTypesSeparator = ""; sessionUploadPersonData.sports = ""; string sportsSeparator = ""; //upload persons (updating also person.serverUniqueID locally) ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons(serverSession.UniqueID); Constants.UploadCodes uCode; ArrayList notToUpload = SqlitePersonSessionNotUpload.SelectAll(currentSession.UniqueID); //store in variable for updating progressBar from other thread progressBarPersonsNum = persons.Count - notToUpload.Count; foreach(Person p in persons) { Person person = p; //do not continue with this person if has been banned to upload if(Util.FoundInArrayList(notToUpload, person.UniqueID.ToString())) continue; PersonSession ps = SqlitePersonSession.Select(person.UniqueID, currentSession.UniqueID); //check person if exists if(person.ServerUniqueID != Constants.ServerUndefinedID) uCode = Constants.UploadCodes.EXISTS; else { uCode = Constants.UploadCodes.OK; person = serverUploadPerson(myServer, person, serverSession.UniqueID); } //if sport is user defined, upload it //and when upload the person, do it with new sportID Sport sport = SqliteSport.Select(ps.SportID); //but record old sport ID because locally will be a change in serverUniqueID //(with slite update) //but local sport has not to be changed int sportUserDefinedLocal = -1; if(sport.UserDefined) { sportUserDefinedLocal = sport.UniqueID; //this will be uploaded int newSport = myServer.UploadSport(sport); if(newSport != -1) { ps.SportID = newSport; sessionUploadPersonData.sports += sportsSeparator + sport.Name; sportsSeparator = ", "; } } //a person can be in the database for one session, //but maybe now we add jumps from another session and we should add an entry at personsession serverUploadPersonSessionIfNeeded(myServer, person.ServerUniqueID, currentSession.ServerUniqueID, ps, sportUserDefinedLocal); //other thread updates the gui: sessionUploadPersonData.person = person; sessionUploadPersonData.personCode = uCode; //upload jumps int countU = 0; int countE = 0; int countS = 0; string [] jumps = SqliteJump.SelectJumps(currentSession.UniqueID, person.UniqueID, "", ""); Sqlite.Open(); foreach(string myJump in jumps) { string [] js = myJump.Split(new char[] {':'}); //select jump Jump test = SqliteJump.SelectJumpData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; //if test is not simulated and has not been uploaded, //see if it's type is not predefined and is not in the database //then upload it first if(test.Simulated == 0) { //upload jumpType if is user defined and doesn't exists in server database //JumpType type = new JumpType(test.Type); JumpType type = SqliteJumpType.SelectAndReturnJumpType(test.Type, true); if( ! type.IsPredefined) { //Console.WriteLine("USER DEFINED TEST: " + test.Type); // //this uploads the new type, as it's user created, it will be like this //eg: for user defined jumpType: "supra" of evaluatorServerID: 9 //at server will be "supra-9" //then two problems get solved: //1.- every evaluator that uploads a type will have a different name //than other evaluator uploading a type that is named the same but could be different //(one can think that "supra" is another thing //2- when the same evaluator upload some supra's, only a new type is created //test.Type = myServer.UploadJumpType(type, evalSID); //int testType = (int) Constants.TestTypes.JUMP; //string insertedType = myServer.UploadTestType(Constants.TestTypes.JUMP, type, evalSID); //string insertedType = myServer.UploadTestType(testType, type, evalSID); string insertedType = myServer.UploadJumpType(type, evalSID); if(insertedType != "-1") { //record type in test (with the "-7" if it's done by evaluator 7) test.Type = insertedType; //show user uploaded type (without the "-7") sessionUploadPersonData.testTypes += testTypesSeparator + type.Name; testTypesSeparator = ", "; } //test.Type in the server will have the correct name "supra-9" } } //upload... (if not because of simulated or uploaded before, report also the user) uCode = serverUploadTest(myServer, Constants.TestTypes.JUMP, Constants.JumpTable, test); if(uCode == Constants.UploadCodes.OK) countU ++; else if(uCode == Constants.UploadCodes.EXISTS) countE ++; else //SIMULATED countS ++; } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.jumpsU = countU; sessionUploadPersonData.jumpsE = countE; sessionUploadPersonData.jumpsS = countS; //upload jumpsRj countU = 0; countE = 0; countS = 0; string [] jumpsRj = SqliteJumpRj.SelectJumps(currentSession.UniqueID, person.UniqueID, "", ""); Sqlite.Open(); foreach(string myJump in jumpsRj) { string [] js = myJump.Split(new char[] {':'}); //select jump JumpRj test = SqliteJumpRj.SelectJumpData(Constants.JumpRjTable, Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; if(test.Simulated == 0) { JumpType type = SqliteJumpType.SelectAndReturnJumpRjType(test.Type, true); if( ! type.IsPredefined) { string insertedType = myServer.UploadJumpRjType(type, evalSID); if(insertedType != "-1") { test.Type = insertedType; sessionUploadPersonData.testTypes += testTypesSeparator + type.Name; testTypesSeparator = ", "; } } } //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.JUMP_RJ, Constants.JumpRjTable, test); if(uCode == Constants.UploadCodes.OK) countU ++; else if(uCode == Constants.UploadCodes.EXISTS) countE ++; else //SIMULATED countS ++; } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.jumpsRjU = countU; sessionUploadPersonData.jumpsRjE = countE; sessionUploadPersonData.jumpsRjS = countS; //upload runs countU = 0; countE = 0; countS = 0; string [] runs = SqliteRun.SelectRuns(currentSession.UniqueID, person.UniqueID, ""); Sqlite.Open(); foreach(string myRun in runs) { string [] js = myRun.Split(new char[] {':'}); //select run Run test = SqliteRun.SelectRunData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; if(test.Simulated == 0) { RunType type = SqliteRunType.SelectAndReturnRunType(test.Type, true); if( ! type.IsPredefined) { string insertedType = myServer.UploadRunType(type, evalSID); if(insertedType != "-1") { test.Type = insertedType; sessionUploadPersonData.testTypes += testTypesSeparator + type.Name; testTypesSeparator = ", "; } } } //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.RUN, Constants.RunTable, test); if(uCode == Constants.UploadCodes.OK) countU ++; else if(uCode == Constants.UploadCodes.EXISTS) countE ++; else //SIMULATED countS ++; } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.runsU = countU; sessionUploadPersonData.runsE = countE; sessionUploadPersonData.runsS = countS; //upload runs intervallic countU = 0; countE = 0; countS = 0; string [] runsI = SqliteRunInterval.SelectRuns(currentSession.UniqueID, person.UniqueID, ""); Sqlite.Open(); foreach(string myRun in runsI) { string [] js = myRun.Split(new char[] {':'}); //select run RunInterval test = SqliteRunInterval.SelectRunData(Constants.RunIntervalTable, Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; if(test.Simulated == 0) { RunType type = SqliteRunIntervalType.SelectAndReturnRunIntervalType(test.Type, true); if( ! type.IsPredefined) { string insertedType = myServer.UploadRunIntervalType(type, evalSID); if(insertedType != "-1") { test.Type = insertedType; sessionUploadPersonData.testTypes += testTypesSeparator + type.Name; testTypesSeparator = ", "; } } } //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.RUN_I, Constants.RunIntervalTable, test); if(uCode == Constants.UploadCodes.OK) countU ++; else if(uCode == Constants.UploadCodes.EXISTS) countE ++; else //SIMULATED countS ++; } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.runsIU = countU; sessionUploadPersonData.runsIE = countE; sessionUploadPersonData.runsIS = countS; //upload reaction times countU = 0; countE = 0; countS = 0; string [] rts = SqliteReactionTime.SelectReactionTimes(currentSession.UniqueID, person.UniqueID); Sqlite.Open(); foreach(string myRt in rts) { string [] js = myRt.Split(new char[] {':'}); //select rt ReactionTime test = SqliteReactionTime.SelectReactionTimeData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.RT, Constants.ReactionTimeTable, test); if(uCode == Constants.UploadCodes.OK) countU ++; else if(uCode == Constants.UploadCodes.EXISTS) countE ++; else //SIMULATED countS ++; } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.rtsU = countU; sessionUploadPersonData.rtsE = countE; sessionUploadPersonData.rtsS = countS; //upload pulses countU = 0; countE = 0; countS = 0; string [] pulses = SqlitePulse.SelectPulses(currentSession.UniqueID, person.UniqueID); Sqlite.Open(); foreach(string myPulse in pulses) { string [] js = myPulse.Split(new char[] {':'}); //select pulse Pulse test = SqlitePulse.SelectPulseData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.PULSE, Constants.PulseTable, test); if(uCode == Constants.UploadCodes.OK) countU ++; else if(uCode == Constants.UploadCodes.EXISTS) countE ++; else //SIMULATED countS ++; } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.pulsesU = countU; sessionUploadPersonData.pulsesE = countE; sessionUploadPersonData.pulsesS = countS; //upload multiChronopic countU = 0; countE = 0; countS = 0; string [] mcs = SqliteMultiChronopic.SelectTests(currentSession.UniqueID, person.UniqueID); Sqlite.Open(); foreach(string mc in mcs) { string [] js = mc.Split(new char[] {':'}); //select mc MultiChronopic test = SqliteMultiChronopic.SelectMultiChronopicData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.MULTICHRONOPIC, Constants.MultiChronopicTable, test); if(uCode == Constants.UploadCodes.OK) countU ++; else if(uCode == Constants.UploadCodes.EXISTS) countE ++; else //SIMULATED countS ++; } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.mcsU = countU; sessionUploadPersonData.mcsE = countE; sessionUploadPersonData.mcsS = countS; needUpdateServerSession = true; while(needUpdateServerSession) { //wait until data is printed on the other thread } } state = (int) Constants.ServerSessionStates.DONE; //myServer.UpdateSession(currentSession.ServerUniqueID, (ServerSessionStates) Constants.ServerSessionStates.DONE); myServer.UpdateSession(currentSession.ServerUniqueID, state); Log.WriteLine(myServer.DisConnectDatabase()); } catch { //other thread updates the gui: serverSessionError = true; } }
private void on_menuitem_server_stats(object o, EventArgs args) { if(connectedAndCanI(Constants.ServerActionStats)) { ChronojumpServer myServer = new ChronojumpServer(); Log.WriteLine(myServer.ConnectDatabase()); string [] statsServer = myServer.Stats(); Log.WriteLine(myServer.DisConnectDatabase()); string [] statsMine = SqliteServer.StatsMine(); new DialogServerStats(statsServer, statsMine); } }
public static void ServerUploadEvaluator() { try { ChronojumpServer myServer = new ChronojumpServer(); Log.WriteLine(myServer.ConnectDatabase()); ServerEvaluator myEval = SqliteServer.SelectEvaluator(1); bool success = false; int evalSID = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID")); if(evalSID == Constants.ServerUndefinedID) { string idCode = myServer.UploadEvaluator(myEval); myEval.Code = Util.FetchName(idCode); myEval.Update(false); evalSID = Util.FetchID(idCode); SqlitePreferences.Update("evaluatorServerID", evalSID.ToString(), false); success = true; } else success = myServer.EditEvaluator(myEval, evalSID); if(success) new DialogMessage(Constants.MessageTypes.INFO, string.Format(Catalog.GetString("Successfully Uploaded evaluator with ID: {0}"), evalSID)); else new DialogMessage(Constants.MessageTypes.WARNING, string.Format(Catalog.GetString("Evaluator {0} has not been correctly uploaded. Maybe codes doesn't match."), evalSID)); Log.WriteLine(myServer.DisConnectDatabase()); } catch { new DialogMessage(Constants.MessageTypes.WARNING, Constants.ServerOffline); } }
/* private static string getIP() { string strHostName = ""; strHostName = System.Net.Dns.GetHostName(); IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName); IPAddress[] addr = ipEntry.AddressList; return addr[addr.Length-1].ToString(); } */ public static string Ping(bool doInsertion, string progName, string progVersion) { try { ChronojumpServer myServer = new ChronojumpServer(); Log.WriteLine(myServer.ConnectDatabase()); int evalSID = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID")); string machineID = SqlitePreferences.Select("machineID"); ServerPing myPing = new ServerPing(evalSID, progName + " " + progVersion, Util.GetOS(), //getIP(), DateTime.Now); //evaluator IP, date machineID, DateTime.Now); //evaluator machineID, date //if !doIsertion nothing will be uploaded, //is ok for uploadPerson to know if server is online string versionAvailable = myServer.UploadPing(myPing, doInsertion); Log.WriteLine(myServer.DisConnectDatabase()); return versionAvailable; } catch (Exception e){ Log.WriteLine("Server Connection "+e.Message); return Constants.ServerOffline; } }
string sqlBuildSelect(bool performQuery) { string testType = UtilGtk.ComboGetActive(combo_test_types); string tableName = ""; if (testType == Catalog.GetString(Constants.JumpSimpleName)) tableName = Constants.JumpTable; else if (testType == Catalog.GetString(Constants.JumpReactiveName)) tableName = Constants.JumpRjTable; else if (testType == Catalog.GetString(Constants.RunSimpleName)) tableName = Constants.RunTable; else { new DialogMessage(Constants.MessageTypes.WARNING, "Problem on sqlBuildSelect"); return ""; } string strVariable = UtilGtk.ComboGetActive(combo_variables); if(strVariable == Constants.DjIndexFormula) strVariable = Constants.DjIndexFormulaOnly; else if(strVariable == Constants.QIndexFormula) strVariable = Constants.QIndexFormulaOnly; else if(strVariable == Catalog.GetString("Average Index")) strVariable = Constants.RjIndexFormulaOnly; else if(strVariable == Constants.RJPotencyBoscoFormula) strVariable = Constants.RJPotencyBoscoFormulaOnly; /* as in server maybe Catalog locale is different than in client we cannot pass a localized "Any" hoping that will match server. then if it's any, pass "" (if string) or corresponding undefined ID (if int) */ int sexID = Constants.AnyID; if(UtilGtk.ComboGetActive(combo_sexes) == Catalog.GetString(Constants.Males)) sexID = Constants.MaleID; else if(UtilGtk.ComboGetActive(combo_sexes) == Catalog.GetString(Constants.Females)) sexID = Constants.FemaleID; /* ageInterval can be: "" -> any ages ">=|30" -> higher or equal than 30 ">=|30|< |40" -> higher or equal than 30 and lower than 40 */ string ageInterval = ""; string age1 = UtilGtk.ComboGetActive(combo_ages1); if(age1 != "" && age1 != Catalog.GetString(Constants.Any)) { ageInterval = age1.Substring(0,2); //get the code ageInterval += ":" + spin_ages1.Value.ToString(); string age2 = UtilGtk.ComboGetActive(combo_ages2); if(age2 != "" && age2 != Catalog.GetString(Constants.Any)) { ageInterval += ":" + age2.Substring(0,2); //get the code ageInterval += ":" + spin_ages2.Value.ToString(); } } try { string sqlString = Sqlite.SQLBuildQueryString( tableName, UtilGtk.ComboGetActive(combo_tests), strVariable, sexID, ageInterval, Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_countries), countries)), Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_sports), sports)), Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_speciallities), speciallities)), Util.FetchID(UtilGtk.ComboGetActive(combo_levels)), Util.FetchID(UtilGtk.ComboGetActive(combo_evaluators)) ); if(performQuery) { ChronojumpServer myServer = new ChronojumpServer(); myServer.ConnectDatabase(); string result = myServer.Query( tableName, UtilGtk.ComboGetActive(combo_tests), strVariable, sexID, ageInterval, Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_countries), countries)), Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_sports), sports)), Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_speciallities), speciallities)), Util.FetchID(UtilGtk.ComboGetActive(combo_levels)), Util.FetchID(UtilGtk.ComboGetActive(combo_evaluators)) ); myServer.DisConnectDatabase(); string [] resultFull = result.Split(new char[] {':'}); label_results_num.Text = resultFull[0]; printUnits(resultFull[0]); if(resultFull[0] == "0") label_results_avg.Text = "-"; else label_results_avg.Text = Util.TrimDecimals( Util.ChangeDecimalSeparator(resultFull[1]), pDN); } return sqlString; } catch { //fix problem on changing continent that updates country and two signals come //also on run (maybe because there's no data) label_results_num.Text = "0"; label_results_avg.Text = "-"; printUnits("0"); return ""; } }
string sqlBuildSelect(bool performQuery) { string testType = UtilGtk.ComboGetActive(combo_test_types); string tableName = ""; if (testType == Catalog.GetString(Constants.JumpSimpleName)) { tableName = Constants.JumpTable; } else if (testType == Catalog.GetString(Constants.JumpReactiveName)) { tableName = Constants.JumpRjTable; } else if (testType == Catalog.GetString(Constants.RunSimpleName)) { tableName = Constants.RunTable; } else { new DialogMessage(Constants.MessageTypes.WARNING, "Problem on sqlBuildSelect"); return(""); } string strVariable = UtilGtk.ComboGetActive(combo_variables); if (strVariable == Constants.DjIndexFormula) { strVariable = Constants.DjIndexFormulaOnly; } else if (strVariable == Constants.QIndexFormula) { strVariable = Constants.QIndexFormulaOnly; } else if (strVariable == Catalog.GetString("Average Index")) { strVariable = Constants.RjIndexFormulaOnly; } else if (strVariable == Constants.RJPotencyBoscoFormula) { strVariable = Constants.RJPotencyBoscoFormulaOnly; } /* * as in server maybe Catalog locale is different than in client * we cannot pass a localized "Any" hoping that will match server. * then if it's any, pass "" (if string) or corresponding undefined ID (if int) */ int sexID = Constants.AnyID; if (UtilGtk.ComboGetActive(combo_sexes) == Catalog.GetString(Constants.Males)) { sexID = Constants.MaleID; } else if (UtilGtk.ComboGetActive(combo_sexes) == Catalog.GetString(Constants.Females)) { sexID = Constants.FemaleID; } /* * ageInterval can be: * "" -> any ages * ">=|30" -> higher or equal than 30 * ">=|30|< |40" -> higher or equal than 30 and lower than 40 */ string ageInterval = ""; string age1 = UtilGtk.ComboGetActive(combo_ages1); if (age1 != "" && age1 != Catalog.GetString(Constants.Any)) { ageInterval = age1.Substring(0, 2); //get the code ageInterval += ":" + spin_ages1.Value.ToString(); string age2 = UtilGtk.ComboGetActive(combo_ages2); if (age2 != "" && age2 != Catalog.GetString(Constants.Any)) { ageInterval += ":" + age2.Substring(0, 2); //get the code ageInterval += ":" + spin_ages2.Value.ToString(); } } try { string sqlString = Sqlite.SQLBuildQueryString( tableName, UtilGtk.ComboGetActive(combo_tests), strVariable, sexID, ageInterval, Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_countries), countries)), Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_sports), sports)), Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_speciallities), speciallities)), Util.FetchID(UtilGtk.ComboGetActive(combo_levels)), Util.FetchID(UtilGtk.ComboGetActive(combo_evaluators)) ); if (performQuery) { ChronojumpServer myServer = new ChronojumpServer(); myServer.ConnectDatabase(); string result = myServer.Query( tableName, UtilGtk.ComboGetActive(combo_tests), strVariable, sexID, ageInterval, Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_countries), countries)), Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_sports), sports)), Convert.ToInt32(Util.FindOnArray(':', 2, 0, UtilGtk.ComboGetActive(combo_speciallities), speciallities)), Util.FetchID(UtilGtk.ComboGetActive(combo_levels)), Util.FetchID(UtilGtk.ComboGetActive(combo_evaluators)) ); myServer.DisConnectDatabase(); string [] resultFull = result.Split(new char[] { ':' }); label_results_num.Text = resultFull[0]; printUnits(resultFull[0]); if (resultFull[0] == "0") { label_results_avg.Text = "-"; } else { label_results_avg.Text = Util.TrimDecimals( Util.ChangeDecimalSeparator(resultFull[1]), pDN); } } return(sqlString); } catch { //fix problem on changing continent that updates country and two signals come //also on run (maybe because there's no data) label_results_num.Text = "0"; label_results_avg.Text = "-"; printUnits("0"); return(""); } }
private static void on_server_upload_session_started() { int evalSID = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID")); try { ChronojumpServer myServer = new ChronojumpServer(); LogB.Information(myServer.ConnectDatabase()); int state = (int)Constants.ServerSessionStates.UPLOADINGSESSION; //create ServerSession based on Session currentSession ServerSession serverSession = new ServerSession(currentSession, evalSID, progName + " " + progVersion, UtilAll.GetOS(), DateTime.Now, state); //if uploading session for first time if (currentSession.ServerUniqueID == Constants.ServerUndefinedID) { //upload ServerSession int idAtServer = myServer.UploadSession(serverSession); //update session currentSession (serverUniqueID) on client database currentSession.ServerUniqueID = idAtServer; SqliteSession.UpdateServerUniqueID(currentSession.UniqueID, currentSession.ServerUniqueID); } state = (int)Constants.ServerSessionStates.UPLOADINGDATA; myServer.UpdateSession(currentSession.ServerUniqueID, state); sessionUploadPersonData.testTypes = ""; string testTypesSeparator = ""; sessionUploadPersonData.sports = ""; string sportsSeparator = ""; //upload persons (updating also person.serverUniqueID locally) ArrayList persons = SqlitePersonSession.SelectCurrentSessionPersons( serverSession.UniqueID, false); //means: do not returnPersonAndPSlist Constants.UploadCodes uCode; ArrayList notToUpload = SqlitePersonSessionNotUpload.SelectAll(currentSession.UniqueID); //store in variable for updating progressBar from other thread progressBarPersonsNum = persons.Count - notToUpload.Count; foreach (Person p in persons) { Person person = p; //do not continue with this person if has been banned to upload if (Util.FoundInArrayList(notToUpload, person.UniqueID.ToString())) { continue; } PersonSession ps = SqlitePersonSession.Select(person.UniqueID, currentSession.UniqueID); //check person if exists if (person.ServerUniqueID != Constants.ServerUndefinedID) { uCode = Constants.UploadCodes.EXISTS; } else { uCode = Constants.UploadCodes.OK; person = serverUploadPerson(myServer, person, serverSession.UniqueID); } //if sport is user defined, upload it //and when upload the person, do it with new sportID Sport sport = SqliteSport.Select(false, ps.SportID); //but record old sport ID because locally will be a change in serverUniqueID //(with slite update) //but local sport has not to be changed int sportUserDefinedLocal = -1; if (sport.UserDefined) { sportUserDefinedLocal = sport.UniqueID; //this will be uploaded int newSport = myServer.UploadSport(sport); if (newSport != -1) { ps.SportID = newSport; sessionUploadPersonData.sports += sportsSeparator + sport.Name; sportsSeparator = ", "; } } //a person can be in the database for one session, //but maybe now we add jumps from another session and we should add an entry at personsession serverUploadPersonSessionIfNeeded(myServer, person.ServerUniqueID, currentSession.ServerUniqueID, ps, sportUserDefinedLocal); //other thread updates the gui: sessionUploadPersonData.person = person; sessionUploadPersonData.personCode = uCode; //upload jumps int countU = 0; int countE = 0; int countS = 0; string [] jumps = SqliteJump.SelectJumps(false, currentSession.UniqueID, person.UniqueID, "", "", Sqlite.Orders_by.DEFAULT, -1); Sqlite.Open(); foreach (string myJump in jumps) { string [] js = myJump.Split(new char[] { ':' }); //select jump Jump test = SqliteJump.SelectJumpData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; //if test is not simulated and has not been uploaded, //see if it's type is not predefined and is not in the database //then upload it first if (test.Simulated == 0) { //upload jumpType if is user defined and doesn't exists in server database //JumpType type = new JumpType(test.Type); JumpType type = SqliteJumpType.SelectAndReturnJumpType(test.Type, true); if (!type.IsPredefined) { //Console.WriteLine("USER DEFINED TEST: " + test.Type); // //this uploads the new type, as it's user created, it will be like this //eg: for user defined jumpType: "supra" of evaluatorServerID: 9 //at server will be "supra-9" //then two problems get solved: //1.- every evaluator that uploads a type will have a different name //than other evaluator uploading a type that is named the same but could be different //(one can think that "supra" is another thing //2- when the same evaluator upload some supra's, only a new type is created //test.Type = myServer.UploadJumpType(type, evalSID); //int testType = (int) Constants.TestTypes.JUMP; //string insertedType = myServer.UploadTestType(Constants.TestTypes.JUMP, type, evalSID); //string insertedType = myServer.UploadTestType(testType, type, evalSID); string insertedType = myServer.UploadJumpType(type, evalSID); if (insertedType != "-1") { //record type in test (with the "-7" if it's done by evaluator 7) test.Type = insertedType; //show user uploaded type (without the "-7") sessionUploadPersonData.testTypes += testTypesSeparator + type.Name; testTypesSeparator = ", "; } //test.Type in the server will have the correct name "supra-9" } } //upload... (if not because of simulated or uploaded before, report also the user) uCode = serverUploadTest(myServer, Constants.TestTypes.JUMP, Constants.JumpTable, test); if (uCode == Constants.UploadCodes.OK) { countU++; } else if (uCode == Constants.UploadCodes.EXISTS) { countE++; } else //SIMULATED { countS++; } } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.jumpsU = countU; sessionUploadPersonData.jumpsE = countE; sessionUploadPersonData.jumpsS = countS; //upload jumpsRj countU = 0; countE = 0; countS = 0; string [] jumpsRj = SqliteJumpRj.SelectJumps(false, currentSession.UniqueID, person.UniqueID, "", ""); Sqlite.Open(); foreach (string myJump in jumpsRj) { string [] js = myJump.Split(new char[] { ':' }); //select jump JumpRj test = SqliteJumpRj.SelectJumpData(Constants.JumpRjTable, Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; if (test.Simulated == 0) { JumpType type = SqliteJumpType.SelectAndReturnJumpRjType(test.Type, true); if (!type.IsPredefined) { string insertedType = myServer.UploadJumpRjType(type, evalSID); if (insertedType != "-1") { test.Type = insertedType; sessionUploadPersonData.testTypes += testTypesSeparator + type.Name; testTypesSeparator = ", "; } } } //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.JUMP_RJ, Constants.JumpRjTable, test); if (uCode == Constants.UploadCodes.OK) { countU++; } else if (uCode == Constants.UploadCodes.EXISTS) { countE++; } else //SIMULATED { countS++; } } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.jumpsRjU = countU; sessionUploadPersonData.jumpsRjE = countE; sessionUploadPersonData.jumpsRjS = countS; //upload runs countU = 0; countE = 0; countS = 0; string [] runs = SqliteRun.SelectRuns(false, currentSession.UniqueID, person.UniqueID, "", Sqlite.Orders_by.DEFAULT, -1); Sqlite.Open(); foreach (string myRun in runs) { string [] js = myRun.Split(new char[] { ':' }); //select run Run test = SqliteRun.SelectRunData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; if (test.Simulated == 0) { RunType type = SqliteRunType.SelectAndReturnRunType(test.Type, true); if (!type.IsPredefined) { string insertedType = myServer.UploadRunType(type, evalSID); if (insertedType != "-1") { test.Type = insertedType; sessionUploadPersonData.testTypes += testTypesSeparator + type.Name; testTypesSeparator = ", "; } } } //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.RUN, Constants.RunTable, test); if (uCode == Constants.UploadCodes.OK) { countU++; } else if (uCode == Constants.UploadCodes.EXISTS) { countE++; } else //SIMULATED { countS++; } } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.runsU = countU; sessionUploadPersonData.runsE = countE; sessionUploadPersonData.runsS = countS; //upload runs intervallic countU = 0; countE = 0; countS = 0; string [] runsI = SqliteRunInterval.SelectRuns(false, currentSession.UniqueID, person.UniqueID, ""); Sqlite.Open(); foreach (string myRun in runsI) { string [] js = myRun.Split(new char[] { ':' }); //select run RunInterval test = SqliteRunInterval.SelectRunData(Constants.RunIntervalTable, Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; if (test.Simulated == 0) { RunType type = SqliteRunIntervalType.SelectAndReturnRunIntervalType(test.Type, true); if (!type.IsPredefined) { string insertedType = myServer.UploadRunIntervalType(type, evalSID); if (insertedType != "-1") { test.Type = insertedType; sessionUploadPersonData.testTypes += testTypesSeparator + type.Name; testTypesSeparator = ", "; } } } //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.RUN_I, Constants.RunIntervalTable, test); if (uCode == Constants.UploadCodes.OK) { countU++; } else if (uCode == Constants.UploadCodes.EXISTS) { countE++; } else //SIMULATED { countS++; } } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.runsIU = countU; sessionUploadPersonData.runsIE = countE; sessionUploadPersonData.runsIS = countS; //upload reaction times countU = 0; countE = 0; countS = 0; string [] rts = SqliteReactionTime.SelectReactionTimes(false, currentSession.UniqueID, person.UniqueID, Sqlite.Orders_by.DEFAULT, -1); Sqlite.Open(); foreach (string myRt in rts) { string [] js = myRt.Split(new char[] { ':' }); //select rt ReactionTime test = SqliteReactionTime.SelectReactionTimeData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.RT, Constants.ReactionTimeTable, test); if (uCode == Constants.UploadCodes.OK) { countU++; } else if (uCode == Constants.UploadCodes.EXISTS) { countE++; } else //SIMULATED { countS++; } } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.rtsU = countU; sessionUploadPersonData.rtsE = countE; sessionUploadPersonData.rtsS = countS; //upload pulses countU = 0; countE = 0; countS = 0; string [] pulses = SqlitePulse.SelectPulses(false, currentSession.UniqueID, person.UniqueID); Sqlite.Open(); foreach (string myPulse in pulses) { string [] js = myPulse.Split(new char[] { ':' }); //select pulse Pulse test = SqlitePulse.SelectPulseData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.PULSE, Constants.PulseTable, test); if (uCode == Constants.UploadCodes.OK) { countU++; } else if (uCode == Constants.UploadCodes.EXISTS) { countE++; } else //SIMULATED { countS++; } } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.pulsesU = countU; sessionUploadPersonData.pulsesE = countE; sessionUploadPersonData.pulsesS = countS; //upload multiChronopic countU = 0; countE = 0; countS = 0; string [] mcs = SqliteMultiChronopic.SelectTests(false, currentSession.UniqueID, person.UniqueID); Sqlite.Open(); foreach (string mc in mcs) { string [] js = mc.Split(new char[] { ':' }); //select mc MultiChronopic test = SqliteMultiChronopic.SelectMultiChronopicData(Convert.ToInt32(js[1]), true); //uniqueID //fix it to server person, session keys test.PersonID = person.ServerUniqueID; test.SessionID = currentSession.ServerUniqueID; //upload... uCode = serverUploadTest(myServer, Constants.TestTypes.MULTICHRONOPIC, Constants.MultiChronopicTable, test); if (uCode == Constants.UploadCodes.OK) { countU++; } else if (uCode == Constants.UploadCodes.EXISTS) { countE++; } else //SIMULATED { countS++; } } Sqlite.Close(); //other thread updates the gui: sessionUploadPersonData.mcsU = countU; sessionUploadPersonData.mcsE = countE; sessionUploadPersonData.mcsS = countS; needUpdateServerSession = true; while (needUpdateServerSession) { //wait until data is printed on the other thread } } state = (int)Constants.ServerSessionStates.DONE; //myServer.UpdateSession(currentSession.ServerUniqueID, (ServerSessionStates) Constants.ServerSessionStates.DONE); myServer.UpdateSession(currentSession.ServerUniqueID, state); LogB.Information(myServer.DisConnectDatabase()); } catch { //other thread updates the gui: serverSessionError = true; } }