public async Task <HttpResponseMessage> Get(string format = "array") { var user = GetSessionUser(Request.Headers.GetCookies().FirstOrDefault()); JDBCEntity currentEntity = null;//当前处理的Entity信息 try { Uri uri = ParseToQueryUri(Request.RequestUri); List <JDBCEntity> findNode = (await MyCoreApi.FindNodeByUriAsync(uri)).ToList(); //根据uri查找父节点 if (findNode.Count != 1) //节点数不唯一 { throw new Exception("Please specify one Node!"); } else { currentEntity = findNode.FirstOrDefault(); } if (!await MyCoreApi.Authorization(currentEntity.Id, user, "4")) { throw new Exception("Not authorization!"); } if (currentEntity.EntityType != JDBCEntityType.Signal) { throw new Exception("The specifed node is not signal!"); } //get data ITypedSignal typedSignal = currentEntity as ITypedSignal; var result = await typedSignal.GetDataAsync(uri.Fragment, format); return(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(SerializeObjectToString(result), System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); } catch (Exception e) { if (currentEntity == null) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(e.InnerException != null ? e.InnerException.Message : e.Message) }); } var response = new ResponseDataMessage { Fail = new { Description = e.InnerException != null ? e.InnerException.Message : e.Message, Id = currentEntity.Id, Path = currentEntity.Path } }; return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(SerializeObjectToString(response), System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); } }
/// <summary> /// 查询得到数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="format"></param> /// <returns></returns> public async Task <object> GetDataByUriAsync(Uri uri, string format) { IQueryPlugIn queryPathPlugIn = GetBestQueryPlugin(uri); ITypedSignal signal = (await queryPathPlugIn.FindJdbcEntityAsync(uri.PathAndQuery)).FirstOrDefault() as ITypedSignal; if (signal != null) { return(await signal.GetDataAsync(uri.Fragment, format)); } else { throw new Exception(ErrorMessages.ExperimentOrSignalNotFoundError); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="signal"></param> /// <param name="fragment"></param> public SignalDataStream(ITypedSignal signal, string fragment) { this.signal = signal; this.fragment = fragment; }