protected override Task ProcessRequestAsync(HttpContext context) { var checker = Throttle.check("dvsPostGet", Global.throttle, context); if (!checker.CheckResult) { Errors.GetError().p406(context); return(context.Response.Output.WriteAsync(string.Empty)); } context.Response.ContentType = "application/json"; var appKey = context.Request.Headers["U-ApiKey"]; if (appKey != "appkey") { Errors.GetError().p412(context); return(context.Response.Output.WriteAsync(string.Empty)); } var meth = context.Request.HttpMethod; //添加设备 if (meth == "POST") { if (context.Request.InputStream.Length == 0) { Errors.GetError().p204(context); return(context.Response.Output.WriteAsync(string.Empty)); } using (var reader = new StreamReader(context.Request.InputStream)) { DeviceModel model; try { model = BsonSerializer.Deserialize <DeviceModel>(reader.ReadToEnd()); if (string.IsNullOrEmpty(model.title)) { return(context.Response.Output.WriteAsync(Errors.e7001)); } return(context.Response.Output.WriteAsync( Controller.DevicesController.GetDevices().Create( appKey, model.ToBsonDocument()))); } catch { return(context.Response.Output.WriteAsync(Errors.e7003)); } } } //罗列设备 if (meth == "GET") { return(context.Response.Output.WriteAsync( Controller.DevicesController.GetDevices().GetAll(appKey))); } Errors.GetError().p404(context); return(context.Response.Output.WriteAsync(string.Empty)); }
protected override Task ProcessRequestAsync(HttpContext context) { var checker = Throttle.check("dpsLast", Global.throttle1, context); if (!checker.CheckResult) { Errors.GetError().p406(context); return(context.Response.Output.WriteAsync(string.Empty)); } context.Response.ContentType = "application/json"; var appKey = context.Request.Headers["U-ApiKey"]; if (appKey != "appkey") { Errors.GetError().p412(context); return(context.Response.Output.WriteAsync(string.Empty)); } var meth = context.Request.HttpMethod; var routeValues = context.Request.RequestContext.RouteData.Values; string dvid = routeValues["dvid"].ToString(); string ssid = routeValues["ssid"].ToString(); //查看设备信息 if (meth == "GET") { int dv; int ss; if (int.TryParse(dvid, out dv) && int.TryParse(ssid, out ss)) { var result = SensorsController.GetSensors().GetSensorType(dv, ss); if (!result.hasError) { if (result.type == em_SensorType.gen) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().GetGenLast(dv, ss, result.type))); } else if (result.type == em_SensorType.gps || result.type == em_SensorType.photo || result.type == em_SensorType.value) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().GetGpsValImgLast(dv, ss, result.type))); } } else { return(context.Response.Output.WriteAsync(result.error)); } } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } Errors.GetError().p404(context); return(context.Response.Output.WriteAsync(string.Empty)); }
protected override Task ProcessRequestAsync(HttpContext context) { var checker = Throttle.check("alsGet", 10, context); if (!checker.CheckResult) { return(context.Response.Output.WriteAsync("{Error:406}")); } context.Response.ContentType = "application/json"; var appKey = context.Request.Headers["U-ApiKey"]; if (appKey != "appkey") { return(context.Response.Output.WriteAsync("{Error:412}")); } var meth = context.Request.HttpMethod; //查看数据结点信息 if (meth == "GET") { var routeValues = context.Request.RequestContext.RouteData.Values; string dvid = routeValues["dvid"].ToString(); string ssid = routeValues["ssid"].ToString(); var start = context.Request.QueryString["start"]; var end = context.Request.QueryString["end"]; var interval = context.Request.QueryString["interval"]; var page = context.Request.QueryString["page"]; } return(context.Response.Output.WriteAsync("{value:39.4}")); }
protected override Task ProcessRequestAsync(HttpContext context) { var checker = Throttle.check("sssPostGet", Global.throttle, context); if (!checker.CheckResult) { Errors.GetError().p406(context); return(context.Response.Output.WriteAsync(string.Empty)); } context.Response.ContentType = "application/json"; var appKey = context.Request.Headers["U-ApiKey"]; if (appKey != "appkey") { Errors.GetError().p412(context); return(context.Response.Output.WriteAsync(string.Empty)); } var meth = context.Request.HttpMethod; var routeValues = context.Request.RequestContext.RouteData.Values; int dvid; if (!int.TryParse(routeValues["dvid"].ToString(), out dvid)) { Errors.GetError().p404(context); return(context.Response.Output.WriteAsync(string.Empty)); } //string ssid = routeValues["ssid"].ToString(); //添加设备 if (meth == "POST") { if (context.Request.InputStream.Length == 0) { Errors.GetError().p204(context); return(context.Response.Output.WriteAsync(string.Empty)); } using (var reader = new StreamReader(context.Request.InputStream)) { SensorModel model; try { model = BsonSerializer.Deserialize <SensorModel>(reader.ReadToEnd()); if (string.IsNullOrEmpty(model.title)) { return(context.Response.Output.WriteAsync(Errors.e7001)); } return(context.Response.Output.WriteAsync( Controller.SensorsController.GetSensors().Create( dvid, model.ToBsonDocument()))); } catch { return(context.Response.Output.WriteAsync(Errors.e7003)); } } } //罗列设备 if (meth == "GET") { return(context.Response.Output.WriteAsync( Controller.SensorsController.GetSensors().GetAll(dvid))); } Errors.GetError().p404(context); return(context.Response.Output.WriteAsync(string.Empty)); }
protected override Task ProcessRequestAsync(HttpContext context) { var checker = Throttle.check("dvsPutDel", Global.throttle, context); if (!checker.CheckResult) { Errors.GetError().p406(context); return(context.Response.Output.WriteAsync(string.Empty)); } context.Response.ContentType = "application/json"; var appKey = context.Request.Headers["U-ApiKey"]; if (appKey != "appkey") { Errors.GetError().p412(context); return(context.Response.Output.WriteAsync(string.Empty)); } var meth = context.Request.HttpMethod; var routeValues = context.Request.RequestContext.RouteData.Values; string dvid = routeValues["dvid"].ToString(); //判断是否有模拟put,delete请求 var req = context.Request.QueryString["method"]; if (!string.IsNullOrEmpty(req)) { var mt = req.ToUpper(); if (Enum.GetNames(typeof(em_HttpMeth)).Contains(mt)) { meth = mt; } else { Errors.GetError().p417(context); return(context.Response.Output.WriteAsync(string.Empty)); } } //查看设备信息 if (meth == "GET") { int dv; if (int.TryParse(dvid, out dv)) { return(context.Response.Output.WriteAsync( Controller.DevicesController.GetDevices().GetOne(appKey, dv))); } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } //修改设备信息 if (meth == "PUT") { if (context.Request.InputStream.Length == 0) { Errors.GetError().p204(context); return(context.Response.Output.WriteAsync(string.Empty)); } using (var reader = new StreamReader(context.Request.InputStream)) { int dv; if (int.TryParse(dvid, out dv)) { if (!DataDV.GetDV().CheckConnected()) { return(context.Response.Output.WriteAsync(Errors.e7006)); } var obj = Controller.DevicesController.GetDevices().GetOne(appKey, dv); if (obj != null) { DeviceModel model; try { model = BsonSerializer.Deserialize <DeviceModel>(reader.ReadToEnd()); if (string.IsNullOrEmpty(model.title)) { return(context.Response.Output.WriteAsync(Errors.e7001)); } return(context.Response.Output.WriteAsync( Controller.DevicesController.GetDevices().Edit(appKey, dv, model.ToBsonDocument()))); } catch { return(context.Response.Output.WriteAsync(Errors.e7005)); } } else { return(context.Response.Output.WriteAsync(Errors.e7004)); } } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } } //删除设备 if (meth == "DELETE") { int dv; if (int.TryParse(dvid, out dv)) { if (!DataDV.GetDV().CheckConnected()) { return(context.Response.Output.WriteAsync(Errors.e7006)); } var obj = Controller.DevicesController.GetDevices().GetOne(appKey, dv); if (obj != null) { return(context.Response.Output.WriteAsync( Controller.DevicesController.GetDevices().Delete(appKey, dv))); } else { return(context.Response.Output.WriteAsync(Errors.e7004)); } } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } Errors.GetError().p404(context); return(context.Response.Output.WriteAsync(string.Empty)); }
protected override Task ProcessRequestAsync(HttpContext context) { var checker = Throttle.check("dpsPost", Global.throttle1, context); if (!checker.CheckResult) { Errors.GetError().p406(context); return(context.Response.Output.WriteAsync(string.Empty)); } context.Response.ContentType = "application/json"; var appKey = context.Request.Headers["U-ApiKey"]; if (appKey != "appkey") { Errors.GetError().p412(context); return(context.Response.Output.WriteAsync(string.Empty)); } var meth = context.Request.HttpMethod; var routeValues = context.Request.RequestContext.RouteData.Values; string dvid = routeValues["dvid"].ToString(); string ssid = routeValues["ssid"].ToString(); string skey = routeValues["key"].ToString(); //判断是否有模拟put,delete请求 var req = context.Request.QueryString["method"]; if (!string.IsNullOrEmpty(req)) { var mt = req.ToUpper(); if (Enum.GetNames(typeof(em_HttpMeth)).Contains(mt)) { meth = mt; } else { Errors.GetError().p417(context); return(context.Response.Output.WriteAsync(string.Empty)); } } //查看设备信息 if (meth == "GET") { int dv; int ss; if (int.TryParse(dvid, out dv) && int.TryParse(ssid, out ss)) { var result = SensorsController.GetSensors().GetSensorType(dv, ss); if (!result.hasError) { var type = result.type; if (type == em_SensorType.gen) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().GetGen(dv, ss, type, skey))); } else if (type == em_SensorType.gps || type == em_SensorType.value || type == em_SensorType.photo) { DateTime dt; try { dt = DateTime.ParseExact(skey, "yyyy-MM-ddTHH:mm:ss", new CultureInfo("zh-CN"), DateTimeStyles.AssumeUniversal); } catch { return(context.Response.Output.WriteAsync(Errors.e7002)); } return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().GetGpsValImg(dv, ss, type, dt))); } } else { return(context.Response.Output.WriteAsync(result.error)); } } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } //修改设备信息 if (meth == "PUT") { int dv; int ss; if (int.TryParse(dvid, out dv) && int.TryParse(ssid, out ss)) { string netjson; using (var reader = new StreamReader(context.Request.InputStream)) { netjson = reader.ReadToEnd(); } var result = SensorsController.GetSensors().GetSensorType(dv, ss); if (!result.hasError) { var type = result.type; if (type == em_SensorType.gen) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().EditGen(dv, ss, type, skey, netjson))); } else if (type == em_SensorType.gps) { DateTime dt; try { dt = DateTime.ParseExact(skey, "yyyy-MM-ddTHH:mm:ss", new CultureInfo("zh-CN"), DateTimeStyles.AssumeUniversal); } catch { return(context.Response.Output.WriteAsync(Errors.e7002)); } return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().EditGps(dv, ss, type, dt, netjson))); } else if (type == em_SensorType.value) { DateTime dt; try { dt = DateTime.ParseExact(skey, "yyyy-MM-ddTHH:mm:ss", new CultureInfo("zh-CN"), DateTimeStyles.AssumeUniversal); } catch { return(context.Response.Output.WriteAsync(Errors.e7002)); } return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().EditVal(dv, ss, type, dt, netjson))); } else if (type == em_SensorType.photo) { DateTime dt; try { dt = DateTime.ParseExact(skey, "yyyy-MM-ddTHH:mm:ss", new CultureInfo("zh-CN"), DateTimeStyles.AssumeUniversal); } catch { return(context.Response.Output.WriteAsync(Errors.e7002)); } return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().EditImg(dv, ss, type, dt, netjson))); } } else { return(context.Response.Output.WriteAsync(result.error)); } } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } //删除设备 if (meth == "DELETE") { int dv; int ss; if (int.TryParse(dvid, out dv) && int.TryParse(ssid, out ss)) { var result = SensorsController.GetSensors().GetSensorType(dv, ss); if (!result.hasError) { var type = result.type; if (type == em_SensorType.gen) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().DelGen(dv, ss, type, skey))); } else if (type == em_SensorType.gps || type == em_SensorType.value || type == em_SensorType.photo) { DateTime dt; try { dt = DateTime.ParseExact(skey, "yyyy-MM-ddTHH:mm:ss", new CultureInfo("zh-CN"), DateTimeStyles.AssumeUniversal); } catch { return(context.Response.Output.WriteAsync(Errors.e7002)); } return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().DelGpsValImg(dv, ss, type, dt))); } } else { return(context.Response.Output.WriteAsync(result.error)); } } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } Errors.GetError().p404(context); return(context.Response.Output.WriteAsync(string.Empty)); }
protected override Task ProcessRequestAsync(HttpContext context) { var checker = Throttle.check("dpsPost", Global.throttle1, context); if (!checker.CheckResult) { Errors.GetError().p406(context); return(context.Response.Output.WriteAsync(string.Empty)); } context.Response.ContentType = "application/json"; var appKey = context.Request.Headers["U-ApiKey"]; if (appKey != "appkey") { Errors.GetError().p412(context); return(context.Response.Output.WriteAsync(string.Empty)); } var meth = context.Request.HttpMethod; var routeValues = context.Request.RequestContext.RouteData.Values; string dvid = routeValues["dvid"].ToString(); string ssid = routeValues["ssid"].ToString(); //添加设备 if (meth == "POST") { if (context.Request.InputStream.Length == 0) { Errors.GetError().p204(context); return(context.Response.Output.WriteAsync(string.Empty)); } int dv; int ss; if (int.TryParse(dvid, out dv) && int.TryParse(ssid, out ss)) { string netjson; using (var reader = new StreamReader(context.Request.InputStream)) { netjson = reader.ReadToEnd(); } var result = SensorsController.GetSensors().GetSensorType(dv, ss); if (!result.hasError) { var type = result.type; if (type == em_SensorType.gen) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().CreateGen(dv, ss, type, netjson))); } else if (type == em_SensorType.gps) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().CreateGps(dv, ss, type, netjson))); } else if (type == em_SensorType.value) { if (netjson.StartsWith("{")) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().CreateValOne(dv, ss, type, netjson))); } else if (netjson.StartsWith("[")) { return(context.Response.Output.WriteAsync( DataPointController.GetDataPoints().CreateValMultible(dv, ss, type, netjson))); } } else if (type == em_SensorType.photo) { //有另外专属接口处理图片管理 //return context.Response.Output.WriteAsync( // DataPointController.GetDataPoints().CreateImg(dv, ss, type, netjson)); return(context.Response.Output.WriteAsync(Errors.e7009)); } } else { return(context.Response.Output.WriteAsync(result.error)); } } else { return(context.Response.Output.WriteAsync(Errors.e7002)); } } Errors.GetError().p404(context); return(context.Response.Output.WriteAsync(string.Empty)); }