aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs52
1 files changed, 52 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
index b60bc77c0..41266cda5 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs
@@ -28,6 +28,10 @@ using Z.EntityFramework.Plus;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
+using Microsoft.WindowsAzure.Storage;
+using Tango.Web;
+using Microsoft.WindowsAzure.Storage.Table;
+using Tango.MachineService.Telemetry;
namespace Tango.MachineService.Controllers
{
@@ -1114,5 +1118,53 @@ namespace Tango.MachineService.Controllers
}
#endregion
+
+ #region Telemetry
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public TelemetrySetCheckPointsResponse SetTelemetryCheckPoints(TelemetrySetCheckPointsRequest request)
+ {
+ TelemetryCheckpointStore store = new TelemetryCheckpointStore(MachineServiceConfig.STORAGE_ACCOUNT);
+ store.SaveMany(RequestToken.Object.MachineGuid, request.Checkpoints);
+ return new TelemetrySetCheckPointsResponse();
+ }
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public TelemetryGetCheckPointsResponse GetTelemetryCheckPoints(TelemetryGetCheckPointsRequest request)
+ {
+ TelemetryCheckpointStore store = new TelemetryCheckpointStore(MachineServiceConfig.STORAGE_ACCOUNT);
+ var checkPoints = store.GetAllForMachine(RequestToken.Object.MachineGuid).ToList();
+ return new TelemetryGetCheckPointsResponse() { Checkpoints = checkPoints };
+ }
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public TelemetryDeviceRegistrationResponse GetTelemetryDeviceConnection(TelemetryDeviceRegistrationRequest request)
+ {
+ var response = new TelemetryDeviceRegistrationResponse();
+
+ using (ObservablesContext db = ObservablesWebContext.CreateContext())
+ {
+ var machine = db.Machines.SingleOrDefault(x => x.Guid == RequestToken.Object.MachineGuid);
+ if (machine == null)
+ throw new AuthenticationException("The specified machine could not be found.");
+
+ string serialNumber = machine.SerialNumber;
+ string storageAccount = MachineServiceConfig.STORAGE_ACCOUNT; // Azure Storage CS
+ string iotHubService = MachineServiceConfig.IOT_HUB_CONNECTION_STRING; // iothubowner SAS (service) CS
+
+ var mgr = new TelemetryDeviceRegistrationManager(storageAccount, iotHubService);
+
+ string iotHubDeviceConnectionString = mgr.GetOrCreateDeviceConnectionString(machine.Guid, serialNumber);
+
+ response.ConnectionString = iotHubDeviceConnectionString;
+ }
+
+ return response;
+ }
+
+ #endregion
}
}