Example #1
0
    public static List <UploadSprintDataObject> SelectTempSprint(bool dbconOpened)
    {
        openIfNeeded(dbconOpened);

        dbcmd.CommandText = "SELECT * FROM " + tableSprint + " ORDER BY uniqueID";
        LogB.SQL(dbcmd.CommandText.ToString());
        dbcmd.ExecuteNonQuery();

        SqliteDataReader reader = dbcmd.ExecuteReader();

        List <UploadSprintDataObject> l = new List <UploadSprintDataObject>();

        while (reader.Read())
        {
            UploadSprintDataObject o = new UploadSprintDataObject(
                Convert.ToInt32(reader[0]),                                          //uniqueID
                Convert.ToInt32(reader[1]),                                          //personID
                reader[2].ToString(),                                                //sprintPositions
                UploadSprintDataObject.SplitTimesStringToList(reader[3].ToString()), //splitTimes
                Convert.ToDouble(Util.ChangeDecimalSeparator(reader[4].ToString())), //k
                Convert.ToDouble(Util.ChangeDecimalSeparator(reader[5].ToString())), //vmax
                Convert.ToDouble(Util.ChangeDecimalSeparator(reader[6].ToString())), //amax
                Convert.ToDouble(Util.ChangeDecimalSeparator(reader[7].ToString())), //fmax
                Convert.ToDouble(Util.ChangeDecimalSeparator(reader[8].ToString()))  //pmax
                );

            l.Add(o);
        }

        reader.Close();
        closeIfNeeded(dbconOpened);

        return(l);
    }
Example #2
0
    public static void InsertTempSprint(bool dbconOpened, UploadSprintDataObject o)
    {
        openIfNeeded(dbconOpened);

        dbcmd.CommandText = "INSERT INTO " + tableSprint +
                            " (uniqueID, personID, sprintPositions, splitTimes, " +
                            " k, vmax, amax, fmax, pmax) VALUES (" +
                            o.ToSQLInsertString();
        LogB.SQL(dbcmd.CommandText.ToString());

        dbcmd.ExecuteNonQuery();

        closeIfNeeded(dbconOpened);
    }
Example #3
0
    /*
     * Unused, now using the above methods
     *
     * public EncoderExercise GetEncoderExercise(int exerciseId)
     * {
     *      EncoderExercise ex = new EncoderExercise();
     *
     *      // Create a request using a URL that can receive a post.
     *      WebRequest request = WebRequest.Create (serverUrl + "/getEncoderExercise");
     *
     *      // Set the Method property of the request to POST.
     *      request.Method = "POST";
     *
     *      // Set the ContentType property of the WebRequest.
     *      request.ContentType = "application/json; Charset=UTF-8"; //but this is not enough, see this line:
     *
     *      // Creates the json object
     *      JsonObject json = new JsonObject();
     *      json.Add("exerciseId", exerciseId);
     *
     *      // Converts it to a String
     *      String js = json.ToString();
     *
     *      // Writes the json object into the request dataStream
     *      Stream dataStream;
     *      try {
     *              dataStream = request.GetRequestStream ();
     *      } catch {
     *              this.ResultMessage =
     *                      string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."),
     *                      serverUrl);
     *              return ex;
     *      }
     *
     *      dataStream.Write (Encoding.UTF8.GetBytes(js), 0, js.Length);
     *
     *      dataStream.Close ();
     *
     *      HttpWebResponse response;
     *      try {
     *              response = (HttpWebResponse) request.GetResponse();
     *      } catch {
     *              this.ResultMessage =
     *                      string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."),
     *                      serverUrl);
     *              return ex;
     *      }
     *
     *      string responseFromServer;
     *      using (var sr = new StreamReader(response.GetResponseStream()))
     *      {
     *              responseFromServer = sr.ReadToEnd();
     *      }
     *
     *      LogB.Information("GetEncoderExercise: " + responseFromServer);
     *
     *      if(responseFromServer == "")
     *              LogB.Information(" Empty "); //never happens
     *      else if(responseFromServer == "[]")
     *              LogB.Information(" Empty2 "); //when rfid is not on server
     *      else {
     *              ex = encoderExerciseDeserialize(responseFromServer);
     *      }
     *
     *      return ex;
     * }
     * private EncoderExercise encoderExerciseDeserialize(string str)
     * {
     *      JsonValue jsonEx = JsonValue.Parse(str);
     *
     *      Int32 id = jsonEx ["id"];
     *      string name = jsonEx ["name"];
     *      Int32 stationId = jsonEx ["stationId"];
     *      int percentBodyMassDisplaced = jsonEx ["percentBodyMassDisplaced"];
     *
     *      return new EncoderExercise(id, name, percentBodyMassDisplaced,
     *                      "", "", 0); //ressitance, description, speed1RM
     * }
     */

    public bool UploadSprintData(UploadSprintDataObject o)
    {
        LogB.Information("calling upload sprint");
        // Create a request using a URL that can receive a post.
        if (!createWebRequest(requestType.GENERIC, "/uploadSprintData"))
        {
            return(false);
        }

        /*
         * LogB.Information("UploadSprintData doubles:");
         * foreach(double d in splitTimesL)
         *      LogB.Information(d.ToString());
         */

        // Set the Method property of the request to POST.
        request.Method = "POST";

        // Set the ContentType property of the WebRequest.
        request.ContentType = "application/json; Charset=UTF-8";         //but this is not enough, see this line:
        //exerciseName = Util.RemoveAccents(exerciseName);

        // Creates the json object
        JsonObject json = new JsonObject();

        json.Add("personId", o.personId);
        json.Add("distances", o.sprintPositions);
        json.Add("t1", o.splitTimesL[1]);

        //splitTimesL starts with a 0 that is not passed
        if (o.splitTimesL.Count >= 3)
        {
            json.Add("t2", o.splitTimesL[2] - o.splitTimesL[1]);             //return lap (partial time) and not split (accumulated time)
        }
        else
        {
            json.Add("t2", "");
        }

        if (o.splitTimesL.Count >= 4)
        {
            json.Add("t3", o.splitTimesL[3] - o.splitTimesL[2]);
        }
        else
        {
            json.Add("t3", "");
        }

        if (o.splitTimesL.Count >= 5)
        {
            json.Add("t4", o.splitTimesL[4] - o.splitTimesL[3]);
        }
        else
        {
            json.Add("t4", "");
        }

        json.Add("k", o.k);
        json.Add("vmax", o.vmax);
        json.Add("amax", o.amax);
        json.Add("fmax", o.fmax);
        json.Add("pmax", o.pmax);

        // Converts it to a String
        String js = json.ToString();

        // Writes the json object into the request dataStream
        Stream dataStream;

        if (!getWebRequestStream(request, out dataStream, Catalog.GetString("Could not upload sprint data.")))
        {
            return(false);
        }

        dataStream.Write(Encoding.UTF8.GetBytes(js), 0, js.Length);

        dataStream.Close();

        // Get the response.
        WebResponse response;

        if (!getWebResponse(request, out response, Catalog.GetString("Could not upload sprint data.")))
        {
            return(false);
        }


        // Display the status (will be 202, CREATED)
        Console.WriteLine(((HttpWebResponse)response).StatusDescription);

        // Clean up the streams.
        dataStream.Close();
        response.Close();

        this.ResultMessage = "Sprint data sent.";
        return(true);
    }