// 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);
        }
예제 #2
0
        /// <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)
                });
            }
        }