示例#1
0
        // GET api/Bill
        public object GetBillData(string url)
        {
            JsonResult jsonResult = new JsonResult();

            try
            {
                using (var client = new WebClient())
                {
                    var jsonData = client.DownloadString(url);
                    var jsonSerializerSettings = new JsonSerializerSettings {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    };
                    object model;
                    using (GlimpseTimeline.Capture("====> Get bills from Json URL AngularJS"))
                    {
                        model = CacheHandler.Get(homeAngularJSCacheKey, () =>
                        {
                            return(JsonConvert.DeserializeObject <BillModel>(jsonData, jsonSerializerSettings));
                        });
                    }

                    jsonResult = new JsonResult
                    {
                        Data = model,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(ex.Message));
            }

            return(jsonResult.Data);
        }
示例#2
0
        private readonly string url = "http://safe-plains-5453.herokuapp.com/bill.json"; //For demo only
        /// <summary>
        /// MVC index controller. Cache json reaults and log actions in Glimpse
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            try
            {
                using (var client = new WebClient())
                {
                    string json = client.DownloadString(url);
                    object model;
                    using (GlimpseTimeline.Capture("====> Get bills from Json URL MVC"))
                    {
                        model = CacheHandler.Get(homeMVCCacheKey, () =>
                        {
                            return(JsonConvert.DeserializeObject <BillModel>(json));
                        });
                    }

                    return(View("Index", model));
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(ex.Message));
            }

            return(View());
        }