// // GET: /TestRestful/Details/5 public ActionResult Details(int id) { string body = HttpHelper.Get(UriAddress + id).Content.ReadAsStringAsync().Result; var returns = SerializeMemoryHelper.DeserializeFromJson <ResponseMessage>(body); var model = SerializeMemoryHelper.DeserializeFromJson <Models.TestApiModel>(returns.Result); return(View(model)); }
public IQueryable <TEntity> GetModel() { List <TEntity> list = new List <TEntity>(); var hashVals = _db.HashValues(_tableName).ToArray(); foreach (var item in hashVals) { list.Add(SerializeMemoryHelper.DeserializeFromJson <TEntity>(item) as TEntity); } return(list.AsQueryable()); }
public ActionResult Index(int page = 1) { NameValueCollection nv = new NameValueCollection(); //读取资料 string body = HttpHelper.Get(UriAddress, nv) .Content.ReadAsStringAsync() .Result; var linq = SerializeMemoryHelper.DeserializeFromJson <ResponseMessage>(body); var model = (linq.Result).FromPagedListJson <Models.TestApiModel>(); return(View(model)); }
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext) { var responseDataSegment = new ResponseDataSegment(); var context = (HttpContextBase)actionContext.Request.Properties["MS_HttpContext"]; //获取传统context var Request = context.Request; //定义传统request对象 var query = Request.QueryString["dataSeg"]; RequestDataSegment data = new RequestDataSegment(); if (query != null) { data = SerializeMemoryHelper.DeserializeFromJson <RequestDataSegment>(query); } if (data != null && data.RequestData.Any()) { foreach (var item in data.RequestData) { try { HttpResponseMessage response; var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }; using (var http = new HttpClient(handler)) { if (item.HttpMethod == 0) { if (item.RequestParam != null) { item.Url += "?"; foreach (var p in item.RequestParam) { item.Url += p.Key + "=" + p.Value + "&"; } item.Url = item.Url.Remove(item.Url.Length - 1, 1); } response = http.GetAsync(item.Url).Result; } else { var content = new FormUrlEncodedContent(item.RequestParam); response = http.PostAsync(item.Url, content).Result; } response.EnsureSuccessStatusCode(); responseDataSegment.ResponseData.Add(new ResponseMessage { GuidKey = item.GuidKey, Status = 200, Result = response.Content.ReadAsStringAsync().Result }); } } catch (Exception ex) { responseDataSegment.ResponseData.Add(new ResponseMessage { GuidKey = item.GuidKey, Status = 100, Result = ex.Message }); } } } actionContext.Response = new HttpResponseMessage { Content = new StringContent(SerializeMemoryHelper.SerializeToJson(responseDataSegment), Encoding.GetEncoding("UTF-8"), "application/json") }; base.OnActionExecuting(actionContext); }
public TEntity Find(params object[] id) { return(SerializeMemoryHelper.DeserializeFromJson <TEntity>(_db.HashGet(_tableName, (string)id[0])) as TEntity); }
/// <summary> /// 得到键所对应的值 /// </summary> /// <param name="cache"></param> /// <param name="key"></param> /// <returns></returns> public static object Get(this IDatabase cache, string key) { return(SerializeMemoryHelper.DeserializeFromJson <object>(cache.StringGet(key))); }
/// <summary> /// 出队列JSON /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cache"></param> /// <param name="key"></param> /// <returns></returns> public static T PopJson <T>(this IDatabase cache, string key) { return(SerializeMemoryHelper.DeserializeFromJson <T>(cache.ListLeftPop(key))); }