// Get public JsonMarkerInfoReply GetMarkerInfo(string s) { var invalid = new JsonMarkerInfoReply { Ok = "0" }; if (string.IsNullOrWhiteSpace(s)) { invalid.EMsg = "params is empty"; return(invalid); } var arr = s.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); if (arr.Length < 1) { return(invalid); } var nvc = new NameValueCollection(); foreach (var a in arr) { var kv = a.Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries); if (kv.Length != 2) { continue; } nvc.Add(kv[0], kv[1]); } foreach (var key in Ajax.MarkerInfoReq) { if (nvc[key] != null) { continue; } invalid.EMsg = string.Format("param {0} is missing", key); return(invalid); } try { var id = nvc[Ajax.id]; var sid = nvc[Ajax.sid] == null ? 1 : int.Parse(nvc[Ajax.sid]); // values are validated there return(MarkerInfo(id, sid)); } catch (Exception ex) { invalid.EMsg = string.Format("Parsing error param: {0}", ex.Message); } return(invalid); }
// Post public JsonMarkerInfoReply MarkerInfo(string id, int sendid) { var sw = new Stopwatch(); sw.Start(); var uid = int.Parse(id); var marker = MemoryDatabase.GetPoints().Data.SingleOrDefault(i => i.I == uid); if (marker == null) { return(new JsonMarkerInfoReply { Id = id, Content = "Marker could not be found", Rid = sendid, Msec = Sw(sw) }); } var reply = new JsonMarkerInfoReply { Rid = sendid, }; reply.BuildContent(marker); reply.Msec = Sw(sw); return(reply); }
/// <summary> /// Read Through Cache /// </summary> /// <param name="id"></param> /// <returns></returns> public JsonMarkerInfoReply GetMarkerInfoHelper(string id) { if (string.IsNullOrWhiteSpace(id)) { return(new JsonMarkerInfoReply { Ok = "0", EMsg = "MapService says: params is invalid" }); } try { var uid = int.Parse(id); var cacheKey = CacheKeys.GetMarkerInfo(uid); var reply = _memCache.Get <JsonMarkerInfoReply>(cacheKey); if (reply != null) { // return cached data reply.Cache = true; return(reply); } P marker = _pointsDatabase.GetPoints().SingleOrDefault(i => i.I == uid); reply = new JsonMarkerInfoReply { Id = id }; reply.BuildContent(marker); if (GmcSettings.Get.CacheServices) { _memCache.Set(reply, cacheKey, TimeSpan.FromMinutes(10)); // cache data } return(reply); } catch (Exception ex) { return(new JsonMarkerInfoReply { Ok = "0", EMsg = string.Format("MapService says: Parsing error param: {0}", ex.Message) }); } }