public string CreateImg(int dvid, int ssid, em_SensorType type, string netjson) { var coll = DataDV.GetDV().getCol().GetCollection(dvid.ToString() + ssid.ToString() + type.ToString()); DataPointImgModel gm; try { gm = BsonSerializer.Deserialize <DataPointImgModel>(netjson); if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var query = Query.EQ("timestamp", gm.timestamp); var obj = coll.FindOne(query); if (obj == null) { coll.Insert(gm.ToBsonDocument()); return(string.Empty); } else { return(Errors.e7008); } } catch { return(Errors.e7003); } }
public string CreateValMultible(int dvid, int ssid, em_SensorType type, string netjson) { var coll = DataDV.GetDV().getCol().GetCollection(dvid.ToString() + ssid.ToString() + type.ToString()); ///数组形数值结点数据 List <DataPointValModel> gm; try { gm = BsonSerializer.Deserialize <List <DataPointValModel> >(netjson); if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } List <IMongoQuery> CheckQuery = new List <IMongoQuery>(); foreach (var item in gm) { var query = Query.EQ("timestamp", item.timestamp); CheckQuery.Add(query); } var obj = coll.FindOne(Query.Or(CheckQuery)); if (obj == null) { coll.InsertBatch(gm); return(string.Empty); } else { return(Errors.e7008); } } catch { return(Errors.e7003); } }
public string CreateGen(int dvid, int ssid, em_SensorType type, string netjson) { var coll = DataDV.GetDV().getCol().GetCollection(dvid.ToString() + ssid.ToString() + type.ToString()); DataPointGenModel gm; try { gm = BsonSerializer.Deserialize <DataPointGenModel>(netjson); if (string.IsNullOrEmpty(gm.key) || gm.key.Length > 128 || gm.value.LongCount() > 1024) { return(Errors.e7001); } if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var query = Query.EQ("key", gm.key); var obj = coll.FindOne(query); if (obj == null) { coll.Insert(gm.ToBsonDocument()); return(string.Empty); } else { return(Errors.e7008); } } catch { return(Errors.e7003); } }
public TypeResult GetSensorType(int dvid, int ssid) { if (!DataDV.GetDV().CheckConnected()) { return(new TypeResult() { hasError = true, error = Errors.e7006 }); } var query1 = Query.EQ("dvid", dvid); var query2 = Query.EQ("ssid", ssid); var query = Query.And(query1, query2); var obj = sss.FindOne(query); if (obj != null) { return(new TypeResult() { hasError = false, type = (em_SensorType)obj["type"].AsInt32 }); } else { return(new TypeResult() { hasError = true, error = Errors.e7004 }); } }
public string Create(string appKey, BsonDocument data) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var last = dvs.FindAll().LastOrDefault(); data.Add("ukey", appKey); data.Add("dvid", last == null ? 1 : last["dvid"].AsInt32 + 1); dvs.Insert(data); return("{device_id:" + data["dvid"].ToString() + "}"); }
public string Create(int dvid, BsonDocument data) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var last = sss.FindAll().LastOrDefault(); data.Add("dvid", dvid); data.Add("ssid", last == null ? 1 : last["ssid"].AsInt32 + 1); sss.Insert(data); return("{sensor_id:" + data["ssid"].ToString() + "}"); }
public string Edit(int dvid, int ssid, BsonDocument data) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var query1 = Query.EQ("dvid", dvid); var query2 = Query.EQ("ssid", ssid); var query = Query.And(query1, query2); UpdateDocument update = new UpdateDocument("$set", data); sss.Update(query, update, UpdateFlags.Upsert); return(string.Empty); }
public string Delete(string appKey, int dvid) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var sensors = SensorsController.GetSensors().GetAllForDel(dvid); Parallel.ForEach(sensors, item => { SensorsController.GetSensors().Delete(item["dvid"].AsInt32, item["ssid"].AsInt32); }); var query1 = Query.EQ("ukey", appKey); var query2 = Query.EQ("dvid", dvid); var query = Query.And(query1, query2); dvs.Remove(query); return(string.Empty); }
public string GetAll(int dvid) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var query = Query.EQ("dvid", dvid); var dball = sss.Find(query).AsParallel(); var display = new List <BsonDocument>(); Parallel.ForEach(dball, item => { item.Add("id", item["ssid"].ToInt32()); item.Remove("_id"); item.Remove("dvid"); item.Remove("ssid"); display.Add(item); }); return(display.ToJson()); }
public string DelGpsValImg(int dvid, int ssid, em_SensorType type, DateTime key) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var coll = DataDV.GetDV().getCol().GetCollection(dvid.ToString() + ssid.ToString() + type.ToString()); var query = Query.EQ("timestamp", key); var obj = coll.FindOne(query); if (obj != null) { coll.Remove(query); return(string.Empty); } else { return(Errors.e7004); } }
public string GetGpsValImgLast(int dvid, int ssid, em_SensorType type) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var coll = DataDV.GetDV().getCol().GetCollection(dvid.ToString() + ssid.ToString() + type.ToString()); var obj = coll.FindAll().LastOrDefault(); if (obj != null) { obj.Remove("_id"); obj["timestamp"] = obj["timestamp"].ToString().Replace("Z", ""); return(obj.ToJson()); } else { return(Errors.e7004); } }
public string GetGen(int dvid, int ssid, em_SensorType type, string key) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var coll = DataDV.GetDV().getCol().GetCollection(dvid.ToString() + ssid.ToString() + type.ToString()); var query = Query.EQ("key", key); var obj = coll.FindOne(query); if (obj != null) { obj.Remove("_id"); obj.Remove("key"); return(obj.ToJson()); } else { return(Errors.e7004); } }
public string Delete(int dvid, int ssid) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } //继续删除数据结点表 var result = GetSensorType(dvid, ssid); if (!result.hasError) { var coll = DataDV.GetDV().getCol().GetCollection(dvid.ToString() + ssid.ToString() + result.type.ToString()); coll.Drop(); } //删除传感器 var query1 = Query.EQ("dvid", dvid); var query2 = Query.EQ("ssid", ssid); var query = Query.And(query1, query2); sss.Remove(query); return(string.Empty); }
public string EditImg(int dvid, int ssid, em_SensorType type, DateTime key, string netjson) { var coll = DataDV.GetDV().getCol().GetCollection(dvid.ToString() + ssid.ToString() + type.ToString()); DataPointImgModel gm; try { gm = BsonSerializer.Deserialize <DataPointImgModel>(netjson); if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var query = Query.EQ("timestamp", key); gm.timestamp = key; UpdateDocument update = new UpdateDocument("$set", gm.ToBsonDocument()); coll.Update(query, update, UpdateFlags.Upsert); return(string.Empty); } catch { return(Errors.e7003); } }
public string GetOne(int dvid, int ssid) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var query1 = Query.EQ("dvid", dvid); var query2 = Query.EQ("ssid", ssid); var query = Query.And(query1, query2); var obj = sss.FindOne(query); if (obj != null) { obj.Add("id", obj["ssid"].ToInt32()); obj.Remove("_id"); obj.Remove("dvid"); obj.Remove("ssid"); return(obj.ToJson()); } else { return(Errors.e7004); } }
public string GetOne(string appKey, int dvid) { if (!DataDV.GetDV().CheckConnected()) { return(Errors.e7006); } var query1 = Query.EQ("ukey", appKey); var query2 = Query.EQ("dvid", dvid); var query = Query.And(query1, query2); var obj = dvs.FindOne(query); if (obj != null) { obj.Add("id", obj["dvid"].ToString()); obj.Remove("_id"); obj.Remove("ukey"); obj.Remove("dvid"); return(obj.ToString()); } else { return(Errors.e7004); } }
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)); }