Ejemplo n.º 1
0
    private void on_checkbutton_video_encoder_clicked(object o, EventArgs args)
    {
        if (checkbutton_video_encoder.Active)
        {
            if (preferences.videoDevice == "")            //on mac can be "0"... || preferences.videoDevice == "0")
            {
                new DialogMessage(Constants.MessageTypes.WARNING, "Video device is not configured. Check Preferences / Multimedia.");
                checkbutton_video_encoder.Active = false;
                return;
            }

            preferences.videoOn = true;
            SqlitePreferences.Update("videoOn", "True", false);
        }
        else
        {
            preferences.videoOn = false;
            SqlitePreferences.Update("videoOn", "False", false);
        }
        //change contacts checkbox but don't raise the signal
        checkbutton_video.Clicked -= new EventHandler(on_checkbutton_video_clicked);
        checkbutton_video.Active   = preferences.videoOn;
        checkbutton_video.Clicked += new EventHandler(on_checkbutton_video_clicked);

        changeVideoButtons(preferences.videoOn);

        //will start on record
        videoCapturePrepare(true);         //if error, show message
    }
Ejemplo n.º 2
0
    private void show_send_log(string sendLogMessage, string logLanguage)
    {
        label_send_log.Text = sendLogMessage;
        emailStored         = SqlitePreferences.Select("email");
        if (emailStored != null && emailStored != "" && emailStored != "0")
        {
            entry_send_log.Text = emailStored;
        }

        //set language radiobuttons
        if (logLanguage == "Catalan")
        {
            radio_log_catalan.Active = true;
        }
        else if (logLanguage == "Spanish")
        {
            radio_log_spanish.Active = true;
        }
        else if (logLanguage == "Portuguese")
        {
            radio_log_portuguese.Active = true;
        }
        else
        {
            radio_log_english.Active = true;
        }

        hbox_send_log.Show();
    }
Ejemplo n.º 3
0
    private void on_menuitem_view_persons_show_photo_toggled(object o, EventArgs args)
    {
        bool showPhoto = menuitem_view_persons_show_photo.Active;

        SqlitePreferences.Update("personPhoto", showPhoto.ToString(), false);
        preferences.personPhoto = showPhoto;
        showPersonPhoto(showPhoto);
    }
Ejemplo n.º 4
0
 //called on test execution
 public void UpdateAtDatabaseIfNeeded(Constants.Menuitem_modes m)
 {
     if (t != t_previous_on_this_mode)
     {
         SqlitePreferences.Update(nameAtSQL(m), t.ToString(), false);
         t_previous_on_this_mode = t;
     }
 }
Ejemplo n.º 5
0
    private void on_menuitem_view_persons_on_top_toggled(object o, EventArgs args)
    {
        bool personsOnTop = menuitem_view_persons_on_top.Active;

        LogB.Information("Toggled: " + personsOnTop.ToString());

        SqlitePreferences.Update("personWinHide", personsOnTop.ToString(), false);
        preferences.personWinHide = personsOnTop;
        showPersonsOnTop(personsOnTop);
    }
Ejemplo n.º 6
0
    public void Show_send_log()
    {
        emailStored = SqlitePreferences.Select("email");
        if (emailStored != null && emailStored != "" && emailStored != "0")
        {
            entry_send_log.Text = emailStored;
        }

        hbox_send_log.Show();

        //button_send_log.Label = "Disabled";
        //button_send_log.Sensitive = false;
    }
Ejemplo n.º 7
0
    //called when menuitem mode changes
    public bool SelectTresholdForThisMode(Constants.Menuitem_modes m)
    {
        //declare it with default value to solve potential SQL problems
        string newThreshold = "5";

        //check current mode. Power modes doesn't use threshold
        newThreshold = SqlitePreferences.Select(nameAtSQL(m), false);

        if (Util.IsNumber(newThreshold, false))
        {
            t = Convert.ToInt32(newThreshold);
            t_previous_on_this_mode = t;
            return(true);
        }
        return(false);
    }
Ejemplo n.º 8
0
    //force sensor
    public void UpdateForceSensorTare(double tare)
    {
        if (tare == -1)
        {
            return;
        }

        //change preferences object and SqlitePreferences
        DateTime dt = DateTime.Now;

        forceSensorTareDateTime = UtilDate.ToFile(dt);
        SqlitePreferences.Update(SqlitePreferences.ForceSensorTareDateTimeStr, forceSensorTareDateTime, false);

        forceSensorTare = tare;
        SqlitePreferences.Update(SqlitePreferences.ForceSensorTareStr, Util.ConvertToPoint(tare), false);
    }
Ejemplo n.º 9
0
    private void on_button_send_log_clicked(object o, EventArgs args)
    {
        string email = entry_send_log.Text.ToString();

        //email can be validated with Util.IsValidEmail(string)
        //or other methods, but maybe there's no need of complexity now

        //1st save email on sqlite
        if (email != null && email != "" && email != "0" && email != emailStored)
        {
            SqlitePreferences.Update("email", email, false);
        }

        //2nd add language as comments
        string language = get_send_log_language();

        SqlitePreferences.Update("crashLogLanguage", language, false);
        string comments = "Answer in: " + language + "\n";

        //3rd if there are comments, add them at the beginning of the file
        comments += textview_comments.Buffer.Text;

        //4th send Json
        Json js      = new Json();
        bool success = js.PostCrashLog(email, comments);

        if (success)
        {
            button_send_log.Label     = Catalog.GetString("Thanks");
            button_send_log.Sensitive = false;

            image_send_log_yes.Show();
            image_send_log_no.Hide();
            LogB.Information(js.ResultMessage);
        }
        else
        {
            button_send_log.Label = Catalog.GetString("Try again");

            image_send_log_yes.Hide();
            image_send_log_no.Show();
            LogB.Error(js.ResultMessage);
        }

        label_send_log_message.Text = js.ResultMessage;
    }
Ejemplo n.º 10
0
    //force sensor
    public void UpdateForceSensorCalibration(double weight, double calibrationFactor)
    {
        if (calibrationFactor == -1)
        {
            return;
        }

        //change preferences object and SqlitePreferences
        DateTime dt = DateTime.Now;

        forceSensorCalibrationDateTime = UtilDate.ToFile(dt);
        SqlitePreferences.Update(SqlitePreferences.ForceSensorCalibrationDateTimeStr, forceSensorCalibrationDateTime, false);

        forceSensorCalibrationWeight = weight;
        SqlitePreferences.Update(SqlitePreferences.ForceSensorCalibrationWeightStr, Util.ConvertToPoint(weight), false);

        forceSensorCalibrationFactor = calibrationFactor;
        SqlitePreferences.Update(SqlitePreferences.ForceSensorCalibrationFactorStr, Util.ConvertToPoint(calibrationFactor), false);
    }
Ejemplo n.º 11
0
 private static void createBlankDBServer()
 {
     LogB.SQL("Creating blank database for server");
     if (Sqlite.CheckFileServer())
     {
         LogB.Error("File already exists. Cannot create.");
     }
     else
     {
         Sqlite.ConnectServer();
         Sqlite.CreateFile();
         Sqlite.CreateTables(true);             //server
         LogB.SQL("Created blank database! Exiting");
         string myVersion = UtilAll.ReadVersion();
         LogB.Warning("CAUTION: client info about versionAvailable (on server): ", myVersion);
         SqlitePreferences.Update("availableVersion", myVersion, false);
         LogB.Information("Maybe you don't want to show this version on pings, change it to last stable published version");
     }
 }
Ejemplo n.º 12
0
    public static void ServerUploadEvaluator()
    {
        try {
            ChronojumpServer myServer = new ChronojumpServer();
            LogB.Information(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));
            }

            LogB.Information(myServer.DisConnectDatabase());
        } catch {
            new DialogMessage(Constants.MessageTypes.WARNING, Constants.ServerOffline);
        }
    }
Ejemplo n.º 13
0
    public bool EncoderChangeMinHeight(bool inertial, int minHeight)
    {
        bool changed = false;

        if (inertial && minHeight != encoderCaptureMinHeightInertial)
        {
            encoderCaptureMinHeightInertial = minHeight;
            SqlitePreferences.Update("encoderCaptureMinHeightInertial",
                                     minHeight.ToString(), false);
            changed = true;
        }
        else if (!inertial && minHeight != encoderCaptureMinHeightGravitatory)
        {
            encoderCaptureMinHeightGravitatory = minHeight;
            SqlitePreferences.Update("encoderCaptureMinHeightGravitatory",
                                     minHeight.ToString(), false);
            changed = true;
        }
        return(changed);
    }
Ejemplo n.º 14
0
    private void sql_stress_test(int times)
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();

        //trying if new way of Sqlite.Close disposing dbcmd fixes problems when multiple open / close connection
        for (int i = 0; i < times; i++)
        {
            LogB.Debug(" i=" + i.ToString());
            LogB.Debug(SqlitePreferences.Select("databaseVersion"));
        }
        sw.Stop();

        string message = "Success!" +
                         " Done " + times + " times." +
                         " Elapsed " + sw.ElapsedMilliseconds + " ms";

        LogB.Information(message);

        label_advanced_feedback.Text = message;
    }
Ejemplo n.º 15
0
    /*
     * EncoderConfiguration
     */

    //called on startup to load last encoderConfiguration
    public static EncoderConfiguration LoadEncoderConfiguration()
    {
        string ecStr = SqlitePreferences.Select("encoderConfiguration", false);

        //1.5.1 and previous don't store encoderConfiguration on SqlitePreferences
        if (ecStr == null || ecStr.Length == 0 || ecStr == "0" || ecStr == "")
        {
            return(new EncoderConfiguration());
        }

        string [] ecStrFull = ecStr.Split(new char[] { ':' });

        //create object
        EncoderConfiguration ec = new EncoderConfiguration(
            (Constants.EncoderConfigurationNames)
            Enum.Parse(typeof(Constants.EncoderConfigurationNames), ecStrFull[0]));

        //assign the rest of params
        ec.ReadParamsFromSQL(ecStrFull);

        return(ec);
    }
Ejemplo n.º 16
0
    /*
     * 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();
            LogB.Information(myServer.ConnectDatabase());

            int    evalSID   = Convert.ToInt32(SqlitePreferences.Select("evaluatorServerID"));
            string machineID = SqlitePreferences.Select("machineID");

            ServerPing myPing = new ServerPing(evalSID, progName + " " + progVersion, UtilAll.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);

            LogB.Information(myServer.DisConnectDatabase());
            return(versionAvailable);
        } catch (Exception e) {
            LogB.Information("Server Connection", e.Message);
            return(Constants.ServerOffline);
        }
    }
    public string UploadPing(ServerPing myPing, bool doInsertion)
    {
        //problemes getting user ip:
        //when it works it should be assigned to myPing.IP
        //string a = Request.UserHostName;
        //Console.WriteLine(System.Web.HttpRequest.UserHostAdress);

        Console.WriteLine("ping string: " + myPing.ToString());


        string strHostName = "";

        strHostName = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);

        IPAddress[] addr = ipEntry.AddressList;
        string      ip   = addr[addr.Length - 1].ToString();

        Console.WriteLine("ip: " + ip);



        //!doInsertion is a way to know if server is connected
        //but without inserting nothing
        //is ok before uploading a session

        //Console.WriteLine("IP: " + System.Web.HttpRequest.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + System.Net.HttpRequest.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + System.Net.Request.UserHostAddress.ToString());
        //Console.WriteLine("IP: " + HttpContext.Current.Request.UserHostAddress);
        //Console.WriteLine("IP context : " + this.Context.Request.UserHostAddress);
        //Console.WriteLine("IP : " + this.Request.UserHostAddress);

        //Console.WriteLine("IP : " + System.Net.HttpListenerRequest.UserHostAddress.ToString());
        //System.Net.HttpListenerRequest req = new System.Net.HttpListenerRequest();
        //Console.WriteLine("IP : " + req.UserHostAddress.ToString());

//		System.Net.HttpListenerRequest req;
        //string a = System.Net.HttpListenerRequest.UserHostAddress;
//		string a = req.UserHostAddress;

        //string a = this.System.Net.HttpListenerRequest.UserHostAddress;

//		System.Net.HttpListenerRequest request = new HttpListenerRequest (String.Empty, "http://localhost/", String.Empty);
//		string a = request.UserHostAddress;

        //http://lists.ximian.com/pipermail/mono-list/2007-January/033998.html

        /*
         * HttpListener listener = new HttpListener();
         *
         * listener.AuthenticationSchemeSelectorDelegate += delegate{
         *      Console.WriteLine("Asking for authentication scheme");
         *      return AuthenticationSchemes.Basic;
         * };
         *
         *
         *
         * listener.Start();
         * HttpListenerContext context = listener.GetContext();
         * HttpListenerRequest request = context.Request;
         * Console.WriteLine("IP req: " + request.UserHostAddress);
         */



        if (doInsertion)
        {
            myPing.InsertAtDB(false);
        }

        return(SqlitePreferences.Select("versionAvailable"));
    }
Ejemplo n.º 18
0
    public static void Main(string [] args)
    {    /*
          *     bool timeLogPassedOk = Log.Start(args);
          *     Log.WriteLine(string.Format("Time log passed: {0}", timeLogPassedOk.ToString()));
          *     Log.WriteLine(string.Format("Client database option 1 in ... " + Util.GetDatabaseDir()));
          *     Log.WriteLine(string.Format("Client database option 2 in ... " + Util.GetDatabaseTempDir()));
          */
        LogSync.Initialize();
        //1.4.10
        Log.Start();
        LogB.Debugging = true;         //now LogB.Debug will be shown. Also there will be thread info on Warning, Error, Information
        if (args.Length > 0 && args[0] == "printAll")
        {
            LogB.PrintAllThreads = true;
        }

        var envPath  = Environment.GetEnvironmentVariable("PATH");
        var rBinPath = "";

        baseDirectory = Util.GetPrefixDir();

        /*
         * location of gtkrc file
         * DISABLED tight now because on windows there are inestabilities on jumps results
         * and on Mode menu
         */
        //Rc.AddDefaultFile (Util.GetThemeFile());
        //LogB.Information("gtk theme:" + Util.GetThemeFile());

        if (UtilAll.IsWindows())
        {
            //Environment.SetEnvironmentVariable ("R_HOME", RelativeToPrefix ("library"));
            //rBinPath = RelativeToPrefix ("lib");
            //rBinPath = RelativeToPrefix ("library");
            //var rPath = System.Environment.Is64BitProcess ? @"C:\Program Files\R\R-3.0.2\bin\x64" : @"C:\Program Files\R\R-3.0.2\bin\i386";
            string x64   = "bin" + System.IO.Path.DirectorySeparatorChar + "x64";
            string i386  = "bin" + System.IO.Path.DirectorySeparatorChar + "i386";
            var    rPath = System.Environment.Is64BitProcess ?
                           System.IO.Path.Combine(baseDirectory, x64) : System.IO.Path.Combine(baseDirectory, i386);

            if (Directory.Exists(rPath) == false)
            {
                LogB.Error("Could not found the specified path to the directory containing R.dll: ", rPath);
                throw new DirectoryNotFoundException(string.Format("Could not found the specified path to the directory containing R.dll: {0}", rPath));
            }

            var newPath = string.Format("{0}{1}{2}", rPath, System.IO.Path.PathSeparator, envPath);
            LogB.Information("newPath:", newPath);

            System.Environment.SetEnvironmentVariable("PATH", newPath);
            LogB.Information("path:", System.Environment.GetEnvironmentVariable("PATH"));

            //use this because we don't want to look at the registry
            //we don't want to force user to install R
            Environment.SetEnvironmentVariable("R_HOME", baseDirectory);
            LogB.Information("R_HOME:", baseDirectory);
        }
        else
        {
            switch (UtilAll.GetOSEnum())
            {
            case UtilAll.OperatingSystems.MACOSX:
                LogB.Information(Environment.GetEnvironmentVariable("R_HOME"));
                rBinPath = "/Library/Frameworks/R.Framework/Libraries";
                Environment.SetEnvironmentVariable("R_HOME", "/Library/Frameworks/R.Framework/Resources");
                Environment.SetEnvironmentVariable("PATH", rBinPath + Path.PathSeparator + envPath);
                LogB.Information("environments");
                LogB.Information(Environment.GetEnvironmentVariable("R_HOME"));
                LogB.Information(Environment.GetEnvironmentVariable("PATH"));

                //Gstreamer stuff
                string prefix = "/Applications/Chronojump.app/Contents/Home/";
                Environment.SetEnvironmentVariable("GST_PLUGIN_PATH", prefix + "lib/gstreamer-0.10");
                Environment.SetEnvironmentVariable("GST_PLUGIN_SYSTEM_PATH", prefix + "lib/gstreamer-0.10");
                Environment.SetEnvironmentVariable("GST_PLUGIN_SCANNER_PATH", prefix + "lib/gstreamer-0.10/gst-plugin-scanner");
                break;

            case UtilAll.OperatingSystems.LINUX:
                rBinPath = @"/usr/lib/R/lib";
                Environment.SetEnvironmentVariable("R_HOME", @"/usr/lib/R");
                Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath);
                break;
            }
        }

        LogB.Information("Platform:" + Environment.OSVersion.Platform);

        LogB.Information("baseDir0:", System.AppDomain.CurrentDomain.BaseDirectory);
        LogB.Information("baseDir1:", baseDirectory);
        LogB.Information("envPath+rBinPath:", envPath + Path.PathSeparator + rBinPath);


        //UtilCSV.ReadValues("/tmp/chronojump-encoder-graph-input-multi.csv");

        if (UtilAll.IsWindows())
        {
            Environment.SetEnvironmentVariable("GST_PLUGIN_PATH", RelativeToPrefix("lib\\gstreamer-0.10"));
        }

        //this call has to be done to chronojump.prg
        //chronojump.prg createBlankDB
        //this creates a blank database and exists.
        //Then new user will have an updated database without the need of creating in
        if (args.Length > 0 && args[0] == "createBlankDB")
        {
            createBlankDB();
            Environment.Exit(1);
        }

        if (args.Length > 0 && args[0] == "createBlankDBServer")
        {
            createBlankDBServer();
            Environment.Exit(1);
        }


        string language = "";

        if (File.Exists(System.IO.Path.Combine(Util.GetDatabaseDir(), "chronojump.db")))
        {
            try {
                Sqlite.Connect();

                /*
                 * chronojump 1.5.2 converts DB 1.24 to 1.25 changing language to ""
                 * but this operation is done later (on sqliteThings)
                 * We need here! to define the language from the beginning
                 * so we use language = "" if version is prior to 1.25
                 */
                string currentDBVersion       = SqlitePreferences.Select("databaseVersion", false);
                double currentDBVersionDouble = Convert.ToDouble(Util.ChangeDecimalSeparator(currentDBVersion));
                if (currentDBVersionDouble < Convert.ToDouble(Util.ChangeDecimalSeparator("1.25")))
                {
                    language = "";
                }
                else
                {
                    language = SqlitePreferences.Select("language", false);
                }

                Sqlite.DisConnect();

                if (language != "")
                {
                    //convert pt-BR to pt_BR
                    if (language.Contains("-"))
                    {
                        language = language.Replace("-", "_");
                    }

                    Environment.SetEnvironmentVariable("LANGUAGE", language);              //works
#if OSTYPE_WINDOWS
                    g_setenv("LANGUAGE", language, true);
#endif
                }
            }
            catch {
                LogB.Warning("Problem reading language on start");
            }
        }

        Catalog.Init("chronojump", System.IO.Path.Combine(Util.GetPrefixDir(), "share/locale"));

        new ChronoJump(args);
    }
Ejemplo n.º 19
0
    protected void sqliteThings()
    {
        configChronojump = new Config();
        configChronojump.Read();

        bool badExit = checkIfChronojumpExitAbnormally();

        if (badExit)
        {
            if (chronojumpIsExecutingNTimes())
            {
                messageToShowOnBoot += Catalog.GetString("Chronojump is already running") + "\n\n" +
                                       Catalog.GetString("Chronojump will exit now.");

                chronojumpHasToExit = true;
                quitNowCjTwoTimes   = true;
                LogB.Error("Chronojump is already running.");

                return;
            }
            else
            {
                chronojumpCrashedBefore();
            }
        }

        //print version of chronojump
        progVersion = BuildInfo.chronojumpVersion;

        LogB.Information("Chronojump version: {0}", progVersion);

        //to store user videos and photos
        Util.CreateMultimediaDirsIfNeeded();

        //to store (encoder, force sensor, run encoder) data and graphs
        UtilEncoder.CreateEncoderDirIfNeeded();
        Util.CreateForceSensorDirIfNeeded();
        Util.CreateRaceAnalyzerDirIfNeeded();

//TODO: when a session is deleted, encoder data has to be deleted, also multimedia videos, I suppose. Show message to user warning about it
//TODO: encoder weight auto written depending on person loaded, and changes if it changes person or weight


        //move database to new location if chronojump version is before 0.7
        moveDatabaseToNewLocationIfNeeded();

        LogB.Information("move? ended");

        splashMessageChange(1);          //checking database

        /*
         * splashMessage = "pre-connect";
         * needUpdateSplashMessage = true;
         * Console.ReadLine();
         */

        Sqlite.CreateDir();
        bool defaultDBLocation = Sqlite.Connect();

        LogB.SQL("sqlite connected");

        /*
         * splashMessage = "post-connect" + defaultDBLocation.ToString();
         * needUpdateSplashMessage = true;
         * Console.ReadLine();
         */

        //Chech if the DB file exists
        if (!Sqlite.CheckTables(defaultDBLocation))
        {
            LogB.SQL(Catalog.GetString("no tables, creating ..."));

            creatingDB = true;
            splashMessageChange(2);              //creating database



            /*
             * splashMessage = "pre-create";
             * needUpdateSplashMessage = true;
             * Console.ReadLine();
             */



            Sqlite.CreateDir();
            Sqlite.CreateFile();
            //Sqlite.CreateFile(defaultDBLocation);



            /*
             * splashMessage = "post-create";
             * needUpdateSplashMessage = true;
             * Console.ReadLine();
             */



            createRunningFileName(runningFileName);
            Sqlite.CreateTables(false);             //not server
            creatingDB = false;
        }
        else
        {
            LogB.SQL("doing backup");
            //backup the database
            Util.BackupDirCreateIfNeeded();

            splashMessageChange(3);              //making db backup

            Util.BackupDatabase();
            LogB.SQL("made a database backup");              //not compressed yet, it seems System.IO.Compression.DeflateStream and
            //System.IO.Compression.GZipStream are not in mono


            if (!Sqlite.IsSqlite3())
            {
                bool ok = Sqlite.ConvertFromSqlite2To3();
                if (!ok)
                {
                    LogB.Error("problem with sqlite");
                    //check (spanish)
                    //http://mail.gnome.org/archives/chronojump-devel-list/2008-March/msg00011.html
                    string errorMessage = Catalog.GetString("Failed database conversion, ensure you have libsqlite3-0 installed. \nIf problems persist ask in chronojump-list");
                    errorMessage += "\n\n" + string.Format(Catalog.GetString("If you have no data on your database (you just installed Chronojump), you can fix this problem deleting this file: {0}"),
                                                           Util.GetDatabaseDir() + Path.DirectorySeparatorChar + "chronojump.db") +
                                    "\n" + Catalog.GetString("And starting Chronojump again.");
                    LogB.Error(errorMessage);
                    messageToShowOnBoot += errorMessage;
                    chronojumpHasToExit  = true;
                    return;
                }
                Sqlite.Connect();
            }

            splashMessageChange(4);              //updating DB
            updatingDB = true;

            if (Sqlite.ChangeDjToDJna())
            {
                messageToShowOnBoot += Catalog.GetString("All DJ jumps have been renamed as 'DJna' (Drop Jumps with No Arms).") + "\n\n" +
                                       Catalog.GetString("If your Drop Jumps were executed using the arms, please rename them manually as 'DJa'.") + "\n";
            }

            bool softwareIsNew = Sqlite.ConvertToLastChronojumpDBVersion();
            updatingDB = false;


            if (!softwareIsNew)
            {
                //Console.Clear();
                string errorMessage = string.Format(Catalog.GetString("Sorry, this Chronojump version ({0}) is too old for your database."), progVersion) + "\n" +
                                      Catalog.GetString("Please update Chronojump") + ":\n";
                errorMessage += "http://chronojump.org";
                //errorMessage += "\n\n" + Catalog.GetString("Press any key");
                LogB.Error(errorMessage);
                messageToShowOnBoot += errorMessage;
                chronojumpHasToExit  = true;
            }

            LogB.Information(Catalog.GetString("tables already created"));


            //check for bad Rjs (activate if program crashes and you use it in the same db before v.0.41)
            //SqliteJump.FindBadRjs();

            createRunningFileName(runningFileName);
        }


        //splashMessageChange(5);  //check for new version
        splashMessageChange(5);          //connecting to server

        messageToShowOnBoot += recuperateBrokenEvents();

        //connect to server to Ping
        versionAvailable = "";
        versionAvailable = Constants.ServerOffline;


        //doing ping using json methods

        /*
         * temporarily disabled on start
         * string machineID = SqlitePreferences.Select("machineID", false);
         * Json js = new Json();
         * bool success = js.Ping(UtilAll.GetOS(), progVersion, machineID);
         * if(success)
         *      LogB.Information(js.ResultMessage);
         * else
         *      LogB.Error(js.ResultMessage);
         */

        allSQLCallsDoneOnSqliteThingsThread = false;

        //wait until pinging ends (or it's cancelled)
        //while(! pingEnd) {
        //}

        Sqlite.Open();

//TODO: fix this to the new code

        string versionAvailableKnown = SqlitePreferences.Select("versionAvailable", true);

        if (versionAvailable != Constants.ServerOffline && new Version(versionAvailable) > new Version(progVersion))
        {
            //check if available version is higher than known available version
            Version versionAvailableAsV = new Version(versionAvailable);

            Version versionAvailableKnownAsV;
            bool    updateKnownVersion = false;
            if (versionAvailableKnown == "")
            {
                updateKnownVersion = true;
            }
            else
            {
                versionAvailableKnownAsV = new Version(versionAvailableKnown);
                if (versionAvailableAsV > versionAvailableKnownAsV)
                {
                    updateKnownVersion = true;
                }
            }

            if (updateKnownVersion)
            {
                //is the first time we know about this new version
                //just write on db and show message to user
                SqlitePreferences.Update(Constants.PrefVersionAvailable, versionAvailable, true);
                versionAvailableKnown = versionAvailable;
                messageToShowOnBoot  += string.Format(Catalog.GetString(
                                                          "\nNew Chronojump version available on website.\nYour Chronojump version is: {1}"),
                                                      versionAvailable, progVersion) + "\n\n" +
                                        Catalog.GetString("Please, update to new version.") + "\n";
            }
        }


        //if chronojump chrashed before
        if (badExit)
        {
            if (versionAvailableKnown.Length > 0 && new Version(versionAvailableKnown) > new Version(progVersion))
            {
                messageToShowOnBoot += "\n" + Catalog.GetString("Chronojump crashed before.") + "\n" +
                                       Catalog.GetString("Please, update to new version: ") + versionAvailableKnown + "\n";
            }
            else
            {
                messageToShowOnBoot += messageCrashedBefore;
                //SqlitePreferences.Update("videoOn", "False", true);
            }
        }


        splashMessageChange(6);          //preparing main window


        //start as "simulated"
        SqlitePreferences.Update("simulated", "True", true);         //dbcon opened

        Sqlite.Close();

        // Chronojump sqlite is in an initialized state, let's keep the Sqlite state here
        // to be re-used
        Sqlite.saveClassState();

        allSQLCallsDoneOnSqliteThingsThread = true;
        LogB.SQL("all SQL calls done on sqliteThings thread");

        UtilAll.IsWindows();            //only as additional info here

        //Application.Init();

        needEndSplashWin = true;
    }
Ejemplo n.º 20
0
    public void UpdateEncoderRhythm(EncoderRhythm er)
    {
        if (
            encoderRhythmActive != er.Active ||
            encoderRhythmRepsOrPhases != er.RepsOrPhases ||
            encoderRhythmRepSeconds != er.RepSeconds ||
            encoderRhythmEccSeconds != er.EccSeconds ||
            encoderRhythmConSeconds != er.ConSeconds ||
            encoderRhythmRestRepsSeconds != er.RestRepsSeconds ||
            encoderRhythmRestAfterEcc != er.RestAfterEcc ||
            encoderRhythmRepsCluster != er.RepsCluster ||
            encoderRhythmRestClustersSeconds != er.RestClustersSeconds
            )
        {
            Sqlite.Open();
        }
        else
        {
            return;
        }

        if (encoderRhythmActive != er.Active)
        {
            encoderRhythmActive = er.Active;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmActiveStr,
                                     er.Active.ToString(), true);    //bool
        }

        if (encoderRhythmRepsOrPhases != er.RepsOrPhases)
        {
            encoderRhythmRepsOrPhases = er.RepsOrPhases;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRepsOrPhasesStr,
                                     er.RepsOrPhases.ToString(), true);    //bool
        }

        if (encoderRhythmRepSeconds != er.RepSeconds)
        {
            encoderRhythmRepSeconds = er.RepSeconds;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRepSecondsStr,
                                     Util.ConvertToPoint(er.RepSeconds), true);    //double to point
        }

        if (encoderRhythmEccSeconds != er.EccSeconds)
        {
            encoderRhythmEccSeconds = er.EccSeconds;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmEccSecondsStr,
                                     Util.ConvertToPoint(er.EccSeconds), true);    //double to point
        }

        if (encoderRhythmConSeconds != er.ConSeconds)
        {
            encoderRhythmConSeconds = er.ConSeconds;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmConSecondsStr,
                                     Util.ConvertToPoint(er.ConSeconds), true);    //double to point
        }

        if (encoderRhythmRestRepsSeconds != er.RestRepsSeconds)
        {
            encoderRhythmRestRepsSeconds = er.RestRepsSeconds;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRestRepsSecondsStr,
                                     Util.ConvertToPoint(er.RestRepsSeconds), true);    //double to point
        }

        if (encoderRhythmRestAfterEcc != er.RestAfterEcc)
        {
            encoderRhythmRestAfterEcc = er.RestAfterEcc;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRestAfterEccStr,
                                     er.RestAfterEcc.ToString(), true);    //bool
        }

        if (encoderRhythmRepsCluster != er.RepsCluster)
        {
            encoderRhythmRepsCluster = er.RepsCluster;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRepsClusterStr,
                                     er.RepsCluster.ToString(), true);    //int
        }

        if (encoderRhythmRestClustersSeconds != er.RestClustersSeconds)
        {
            encoderRhythmRestClustersSeconds = er.RestClustersSeconds;
            SqlitePreferences.Update(SqlitePreferences.EncoderRhythmRestClustersSecondsStr,
                                     Util.ConvertToPoint(er.RestClustersSeconds), true);    //double to point
        }

        Sqlite.Close();
    }
Ejemplo n.º 21
0
 public static Preferences LoadAllFromSqlite()
 {
     return(SqlitePreferences.SelectAll());
 }
Ejemplo n.º 22
0
    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;
        }
    }
Ejemplo n.º 23
0
    //change stuff in Sqlite and in preferences object that will be retrieved by GetPreferences
    void on_button_accept_clicked(object o, EventArgs args)
    {
        Sqlite.Open();

        if (preferences.digitsNumber != Convert.ToInt32(UtilGtk.ComboGetActive(combo_decimals)))
        {
            SqlitePreferences.Update("digitsNumber", UtilGtk.ComboGetActive(combo_decimals), true);
            preferences.digitsNumber = Convert.ToInt32(UtilGtk.ComboGetActive(combo_decimals));
        }

        if (preferences.showPower != PreferencesWindowBox.checkbutton_power.Active)
        {
            SqlitePreferences.Update("showPower", PreferencesWindowBox.checkbutton_power.Active.ToString(), true);
            preferences.showPower = PreferencesWindowBox.checkbutton_power.Active;
        }

        if (preferences.showStiffness != PreferencesWindowBox.checkbutton_stiffness.Active)
        {
            SqlitePreferences.Update("showStiffness", PreferencesWindowBox.checkbutton_stiffness.Active.ToString(), true);
            preferences.showStiffness = PreferencesWindowBox.checkbutton_stiffness.Active;
        }

        if (preferences.showInitialSpeed != PreferencesWindowBox.checkbutton_initial_speed.Active)
        {
            SqlitePreferences.Update("showInitialSpeed", PreferencesWindowBox.checkbutton_initial_speed.Active.ToString(), true);
            preferences.showInitialSpeed = PreferencesWindowBox.checkbutton_initial_speed.Active;
        }

        if (preferences.showAngle != PreferencesWindowBox.checkbutton_angle.Active)
        {
            SqlitePreferences.Update("showAngle", PreferencesWindowBox.checkbutton_angle.Active.ToString(), true);
            preferences.showAngle = PreferencesWindowBox.checkbutton_angle.Active;
        }

        if (PreferencesWindowBox.checkbutton_show_tv_tc_index.Active)
        {
            SqlitePreferences.Update("showQIndex", PreferencesWindowBox.radiobutton_show_q_index.Active.ToString(), true);
            SqlitePreferences.Update("showDjIndex", PreferencesWindowBox.radiobutton_show_dj_index.Active.ToString(), true);
            preferences.showQIndex  = PreferencesWindowBox.radiobutton_show_q_index.Active;
            preferences.showDjIndex = PreferencesWindowBox.radiobutton_show_dj_index.Active;
        }
        else
        {
            SqlitePreferences.Update("showQIndex", "False", true);
            SqlitePreferences.Update("showDjIndex", "False", true);
            preferences.showQIndex  = false;
            preferences.showDjIndex = false;
        }


        if (preferences.askDeletion != PreferencesWindowBox.checkbutton_ask_deletion.Active)
        {
            SqlitePreferences.Update("askDeletion", PreferencesWindowBox.checkbutton_ask_deletion.Active.ToString(), true);
            preferences.askDeletion = PreferencesWindowBox.checkbutton_ask_deletion.Active;
        }

        if (preferences.weightStatsPercent != PreferencesWindowBox.radio_weight_percent.Active)
        {
            SqlitePreferences.Update("weightStatsPercent", PreferencesWindowBox.radio_weight_percent.Active.ToString(), true);
            preferences.weightStatsPercent = PreferencesWindowBox.radio_weight_percent.Active;
        }

        if (preferences.heightPreferred != PreferencesWindowBox.radio_elevation_height.Active)
        {
            SqlitePreferences.Update("heightPreferred", PreferencesWindowBox.radio_elevation_height.Active.ToString(), true);
            preferences.heightPreferred = PreferencesWindowBox.radio_elevation_height.Active;
        }

        if (preferences.metersSecondsPreferred != PreferencesWindowBox.radio_speed_ms.Active)
        {
            SqlitePreferences.Update("metersSecondsPreferred", PreferencesWindowBox.radio_speed_ms.Active.ToString(), true);
            preferences.metersSecondsPreferred = PreferencesWindowBox.radio_speed_ms.Active;
        }

        if (preferences.runSpeedStartArrival != PreferencesWindowBox.radio_runs_speed_start_arrival.Active)
        {
            SqlitePreferences.Update("runSpeedStartArrival", PreferencesWindowBox.radio_runs_speed_start_arrival.Active.ToString(), true);
            preferences.runSpeedStartArrival = PreferencesWindowBox.radio_runs_speed_start_arrival.Active;
        }

        //start of double contacts stuff ----

        //1 simple runs ----

        //1.1 was FIRST or AVERAGE or LAST and now will be NONE
        if ((preferences.runDoubleContactsMode != Constants.DoubleContact.NONE) &&
            !PreferencesWindowBox.checkbutton_runs_prevent_double_contact.Active)
        {
            SqlitePreferences.Update("runDoubleContactsMode", Constants.DoubleContact.NONE.ToString(), true);
            preferences.runDoubleContactsMode = Constants.DoubleContact.NONE;
        }
        else if (PreferencesWindowBox.checkbutton_runs_prevent_double_contact.Active)
        {
            //1.2 mode has changed between FIRST, AVERAGE or LAST
            if (PreferencesWindowBox.radio_runs_prevent_double_contact_first.Active &&
                (preferences.runDoubleContactsMode != Constants.DoubleContact.FIRST))
            {
                SqlitePreferences.Update("runDoubleContactsMode", Constants.DoubleContact.FIRST.ToString(), true);
                preferences.runDoubleContactsMode = Constants.DoubleContact.FIRST;
            }
            else if (PreferencesWindowBox.radio_runs_prevent_double_contact_average.Active &&
                     (preferences.runDoubleContactsMode != Constants.DoubleContact.AVERAGE))
            {
                SqlitePreferences.Update("runDoubleContactsMode", Constants.DoubleContact.AVERAGE.ToString(), true);
                preferences.runDoubleContactsMode = Constants.DoubleContact.AVERAGE;
            }
            else if (PreferencesWindowBox.radio_runs_prevent_double_contact_last.Active &&
                     (preferences.runDoubleContactsMode != Constants.DoubleContact.LAST))
            {
                SqlitePreferences.Update("runDoubleContactsMode", Constants.DoubleContact.LAST.ToString(), true);
                preferences.runDoubleContactsMode = Constants.DoubleContact.LAST;
            }

            if (preferences.runDoubleContactsMS != (int)PreferencesWindowBox.spinbutton_runs_prevent_double_contact.Value)
            {
                SqlitePreferences.Update("runDoubleContactsMS",
                                         PreferencesWindowBox.spinbutton_runs_prevent_double_contact.Value.ToString(), true);        //saved as string
                preferences.runDoubleContactsMS = (int)spinbutton_runs_prevent_double_contact.Value;
            }
        }

        //2 intervallic runs ----

        //2.1 was FIRST or AVERAGE or LAST and now will be NONE
        if ((preferences.runIDoubleContactsMode != Constants.DoubleContact.NONE) &&
            !PreferencesWindowBox.checkbutton_runs_i_prevent_double_contact.Active)
        {
            SqlitePreferences.Update("runIDoubleContactsMode", Constants.DoubleContact.NONE.ToString(), true);
            preferences.runIDoubleContactsMode = Constants.DoubleContact.NONE;
        }
        else if (PreferencesWindowBox.checkbutton_runs_i_prevent_double_contact.Active)
        {
            //2.2 mode has changed between FIRST, AVERAGE or LAST
            if (PreferencesWindowBox.radio_runs_i_prevent_double_contact_first.Active &&
                (preferences.runIDoubleContactsMode != Constants.DoubleContact.FIRST))
            {
                SqlitePreferences.Update("runIDoubleContactsMode", Constants.DoubleContact.FIRST.ToString(), true);
                preferences.runIDoubleContactsMode = Constants.DoubleContact.FIRST;
            }
            else if (PreferencesWindowBox.radio_runs_i_prevent_double_contact_average.Active &&
                     (preferences.runIDoubleContactsMode != Constants.DoubleContact.AVERAGE))
            {
                SqlitePreferences.Update("runIDoubleContactsMode", Constants.DoubleContact.AVERAGE.ToString(), true);
                preferences.runIDoubleContactsMode = Constants.DoubleContact.AVERAGE;
            }
            else if (PreferencesWindowBox.radio_runs_i_prevent_double_contact_last.Active &&
                     (preferences.runIDoubleContactsMode != Constants.DoubleContact.LAST))
            {
                SqlitePreferences.Update("runIDoubleContactsMode", Constants.DoubleContact.LAST.ToString(), true);
                preferences.runIDoubleContactsMode = Constants.DoubleContact.LAST;
            }

            if (preferences.runIDoubleContactsMS != (int)PreferencesWindowBox.spinbutton_runs_i_prevent_double_contact.Value)
            {
                SqlitePreferences.Update("runIDoubleContactsMS",
                                         PreferencesWindowBox.spinbutton_runs_i_prevent_double_contact.Value.ToString(), true);        //saved as string
                preferences.runIDoubleContactsMS = (int)spinbutton_runs_i_prevent_double_contact.Value;
            }
        }

        //---- end of double contacts stuff


        if (preferences.encoderPropulsive != PreferencesWindowBox.checkbutton_encoder_propulsive.Active)
        {
            SqlitePreferences.Update("encoderPropulsive",
                                     PreferencesWindowBox.checkbutton_encoder_propulsive.Active.ToString(), true);
            preferences.encoderPropulsive = PreferencesWindowBox.checkbutton_encoder_propulsive.Active;
        }

        if (preferences.encoderSmoothCon != (double)PreferencesWindowBox.spin_encoder_smooth_con.Value)
        {
            SqlitePreferences.Update("encoderSmoothCon", Util.ConvertToPoint(
                                         (double)PreferencesWindowBox.spin_encoder_smooth_con.Value), true);
            preferences.encoderSmoothCon = (double)PreferencesWindowBox.spin_encoder_smooth_con.Value;
        }

        if (preferences.videoDeviceNum != UtilGtk.ComboGetActivePos(combo_camera))
        {
            SqlitePreferences.Update("videoDevice", UtilGtk.ComboGetActivePos(combo_camera).ToString(), true);
            preferences.videoDeviceNum = UtilGtk.ComboGetActivePos(combo_camera);
        }


        if (PreferencesWindowBox.radio_export_latin.Active)
        {
            SqlitePreferences.Update("CSVExportDecimalSeparator", "COMMA", true);
            preferences.CSVExportDecimalSeparator = "COMMA";
        }
        else
        {
            SqlitePreferences.Update("CSVExportDecimalSeparator", "POINT", true);
            preferences.CSVExportDecimalSeparator = "POINT";
        }

        string selectedLanguage = getSelectedLanguage();

        //if there was a language on SQL but now "detected" is selected, put "" in language on SQL
        if (preferences.language != "" && radio_language_detected.Active)
        {
            SqlitePreferences.Update("language", "", true);
            preferences.language = "";
        }
        //if force a language, and SQL language is != than selected language, change language on SQL
        else if (radio_language_force.Active && preferences.language != selectedLanguage)
        {
            SqlitePreferences.Update("language", selectedLanguage, true);
            preferences.language = selectedLanguage;
        }


        if (preferences.RGraphsTranslate != PreferencesWindowBox.radio_graphs_translate.Active)
        {
            SqlitePreferences.Update("RGraphsTranslate",
                                     PreferencesWindowBox.radio_graphs_translate.Active.ToString(), true);
            preferences.RGraphsTranslate = PreferencesWindowBox.radio_graphs_translate.Active;
        }

        if (preferences.useHeightsOnJumpIndexes != PreferencesWindowBox.radio_use_heights_on_jump_indexes.Active)
        {
            SqlitePreferences.Update("useHeightsOnJumpIndexes",
                                     PreferencesWindowBox.radio_use_heights_on_jump_indexes.Active.ToString(), true);
            preferences.useHeightsOnJumpIndexes = PreferencesWindowBox.radio_use_heights_on_jump_indexes.Active;
        }

        if (PreferencesWindowBox.radio_encoder_auto_save_curve_best.Active)
        {
            SqlitePreferences.Update("encoderAutoSaveCurve", Constants.EncoderAutoSaveCurve.BEST.ToString(), true);
            preferences.encoderAutoSaveCurve = Constants.EncoderAutoSaveCurve.BEST;
        }
        else if (PreferencesWindowBox.radio_encoder_auto_save_curve_all.Active)
        {
            SqlitePreferences.Update("encoderAutoSaveCurve", Constants.EncoderAutoSaveCurve.ALL.ToString(), true);
            preferences.encoderAutoSaveCurve = Constants.EncoderAutoSaveCurve.ALL;
        }
        else
        {
            SqlitePreferences.Update("encoderAutoSaveCurve", Constants.EncoderAutoSaveCurve.NONE.ToString(), true);
            preferences.encoderAutoSaveCurve = Constants.EncoderAutoSaveCurve.NONE;
        }

        Constants.Encoder1RMMethod encoder1RMMethod;
        if (PreferencesWindowBox.radio_encoder_1RM_nonweighted.Active)
        {
            encoder1RMMethod = Constants.Encoder1RMMethod.NONWEIGHTED;
        }
        else if (PreferencesWindowBox.radio_encoder_1RM_weighted.Active)
        {
            encoder1RMMethod = Constants.Encoder1RMMethod.WEIGHTED;
        }
        else if (PreferencesWindowBox.radio_encoder_1RM_weighted2.Active)
        {
            encoder1RMMethod = Constants.Encoder1RMMethod.WEIGHTED2;
        }
        else         // (PreferencesWindowBox.radio_encoder_1RM_weighted3.Active)
        {
            encoder1RMMethod = Constants.Encoder1RMMethod.WEIGHTED3;
        }

        SqlitePreferences.Update("encoder1RMMethod", encoder1RMMethod.ToString(), true);
        preferences.encoder1RMMethod = encoder1RMMethod;

        Sqlite.Close();

        PreferencesWindowBox.preferences_win.Hide();
        PreferencesWindowBox = null;
    }