forked from jfmatt-zz/shuttle-tracker-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tracker.ashx.cs
69 lines (52 loc) · 1.84 KB
/
Tracker.ashx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
namespace Tracker {
public class TrackerHandler : System.Web.IHttpHandler {
public void ProcessRequest (System.Web.HttpContext context) {
if (context.Request.RequestType.Equals("get",System.StringComparison.OrdinalIgnoreCase))
doGet(context);
else if (context.Request.RequestType.Equals("post",System.StringComparison.OrdinalIgnoreCase))
doPost(context);
}
public void doGet(System.Web.HttpContext context) {
context.Response.ContentType = "text/xml";
Global.xmlLock.EnterReadLock();
try {
context.Response.Write(Global.getInfo());
} finally { Global.xmlLock.ExitReadLock(); }
}
public void doPost(System.Web.HttpContext context) {
String longString = context.Request.Form["bus-tracker-longitude"];
String latString = context.Request.Form["bus-tracker-latitude"];
String timeString = context.Request.Form["bus-tracker-timestamp"];
String idString = context.Request.Form["bus-tracker-id"];
//Check that all fields are present
if (longString == null || latString == null || idString == null) {
context.Response.StatusCode = 400; //Bad request
return;
}
double longitude;
double latitude;
long timestamp;
int id;
//Check that all fields are in proper format
if (!double.TryParse(longString, out longitude) || !double.TryParse(latString, out latitude)
|| !int.TryParse(idString, out id) || !long.TryParse(timeString, out timestamp)) {
context.Response.StatusCode = 415; //Unsupported media
return;
}
// int userLastStop;
context.Response.ContentType = "text/plain";
context.Response.Write("ok");
Global.userLock.EnterWriteLock();
try {
// if (users.Try
} finally { Global.userLock.ExitWriteLock(); }
}
public bool IsReusable {
get {
return false;
}
}
}
}