[chronojump] Sprints automatically uploaded to Compujump server
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Sprints automatically uploaded to Compujump server
- Date: Wed, 5 Jul 2017 16:40:22 +0000 (UTC)
commit 1a3183d7f51d2cf9cae049ec0595b54c0476e612
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Jul 5 18:39:58 2017 +0200
Sprints automatically uploaded to Compujump server
src/gui/chronojump.cs | 8 ++++++
src/gui/networks.cs | 10 +++++++-
src/json.cs | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 1 deletions(-)
---
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index d604c76..b93ce5e 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -4451,6 +4451,14 @@ public partial class ChronoJumpWindow
event_execute_LabelEventValue = currentRunInterval.Tracks;
addTreeView_runs_interval_sprint (currentRunInterval, currentRunIntervalType);
+
+ if(configChronojump.Compujump)
+ {
+ Json js = new Json();
+ js.UploadSprintData(currentPerson.UniqueID,
+ currentRunInterval.DistanceInterval,
+ currentRunInterval.IntervalTimesString);
+ }
}
else if( currentEventExecute.ChronopicDisconnected )
chronopicDisconnectedWhileExecuting();
diff --git a/src/gui/networks.cs b/src/gui/networks.cs
index 8055291..6c682b8 100644
--- a/src/gui/networks.cs
+++ b/src/gui/networks.cs
@@ -119,7 +119,15 @@ public partial class ChronoJumpWindow
if(configChronojump.CompujumpStationMode != Constants.Menuitem_modes.UNDEFINED)
{
- select_menuitem_mode_toggled(configChronojump.CompujumpStationMode);
+ //select_menuitem_mode_toggled(configChronojump.CompujumpStationMode);
+ //better do like this because radiobuttons are not set. TODO: remove
radiobuttons checks
+ if(configChronojump.CompujumpStationMode ==
Constants.Menuitem_modes.RUNSINTERVALLIC)
+ on_button_selector_start_runs_intervallic_clicked(new object (), new
EventArgs());
+ else if(configChronojump.CompujumpStationMode ==
Constants.Menuitem_modes.POWERGRAVITATORY)
+ on_button_selector_start_encoder_gravitatory_clicked(new object (),
new EventArgs());
+ else //if(configChronojump.CompujumpStationMode ==
Constants.Menuitem_modes.POWERINERTIAL)
+ on_button_selector_start_encoder_inertial_clicked(new object (), new
EventArgs());
+
menuitem_mode.Visible = false;
button_menu_outside_menu.Visible = false;
button_menu_outside_menu1.Visible = false;
diff --git a/src/json.cs b/src/json.cs
index e54658c..8a0af95 100644
--- a/src/json.cs
+++ b/src/json.cs
@@ -609,6 +609,66 @@ public class Json
"", "", 0); //ressitance, description, speed1RM
}
+ public bool UploadSprintData(int personId, string distances, string times)
+ {
+ LogB.Information("calling upload sprint");
+ // Create a request using a URL that can receive a post.
+ WebRequest request = WebRequest.Create (serverUrl + "/uploadSprintData");
+
+ // 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", personId);
+ json.Add("distances", distances);
+ json.Add("times", times);
+
+ // 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 false;
+ }
+
+ dataStream.Write (Encoding.UTF8.GetBytes(js), 0, js.Length);
+
+ dataStream.Close ();
+
+ // Get the response.
+ WebResponse response;
+ try {
+ response = request.GetResponse ();
+ } catch {
+ this.ResultMessage =
+ string.Format(Catalog.GetString("You are not connected to the Internet\nor
{0} server is down."),
+ serverUrl);
+ return false;
+ }
+
+ // Display the status (will be 202, CREATED)
+ Console.WriteLine (((HttpWebResponse)response).StatusDescription);
+
+ // Clean up the streams.
+ dataStream.Close ();
+ response.Close ();
+
+ this.ResultMessage = "Encoder data sent.";
+ return true;
+ }
+
/*
public bool UploadEncoderData()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]