public List <MetricSerie> PerformQuery(string db, string query) { List <MetricSerie> metricSeries; ParamterUtil.CheckEmptyString("db", db); ParamterUtil.CheckEmptyString("query", query); List <MetricSerie> metricSeries1 = new List <MetricSerie>(); try { DebugUtil.Log(string.Format("MeasurementHost: performing query '{0}' on db '{1}'.", query, db)); string appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.MeasurementApi); if (string.IsNullOrEmpty(appUri)) { DebugUtil.Log("MeasurementHost: failed to fetch measurementServerInfo.Uri from location."); } else { string str = string.Format("{0}api/measurement/run", appUri); Command command = new Command() { Type = CommandType.Read }; command.Parameters.Add("dbname", db); command.Parameters.Add("query", query); FoundationResponse <string> result = ProxyBase.Call <FoundationResponse <string>, Command>(str, command, ApiHttpMethod.POST, 180000, null).Result; if ((result == null ? true : string.IsNullOrEmpty(result.Data))) { DebugUtil.Log(string.Format("MeasurementHost: query '{0}' on db '{1}' return empty.", query, db)); } else { metricSeries1 = JsonSerializerUtil.Deserialize <List <MetricSerie> >(result.Data); } metricSeries = metricSeries1; return(metricSeries); } } catch (Exception exception) { DebugUtil.LogException(exception); } metricSeries = metricSeries1; return(metricSeries); }
private static FoundationResponse <string> PushToServer(List <MetricPoint> points, string db, string rp) { string str; FoundationResponse <string> foundationResponse = null; if ((points == null ? false : points.Count > 0)) { try { string appUri = LocationHelper.Instance.GetAppUri(AppNameEnum.MeasurementApi); if (string.IsNullOrEmpty(appUri)) { DebugUtil.Log("MeasurementHost: failed to fetch measurementServerInfo.Uri from location."); foundationResponse = new FoundationResponse <string>() { IsSuccess = false }; } else { str = (!appUri.EndsWith("/") ? string.Format("{0}/api/measurement/write/", appUri) : string.Format("{0}api/measurement/write/", appUri)); MeasurementRequest measurementRequest = new MeasurementRequest(); measurementRequest.MetricPoints.AddRange(points); measurementRequest.DBName = db; measurementRequest.RetentionPolicy = rp; DebugUtil.Log(string.Format("MeasurementHost: Sending {0} points to db '{1}' via {2}.", points.Count, measurementRequest.DBName, str)); foundationResponse = ProxyBase.Call <FoundationResponse <string>, object>(str, measurementRequest, ApiHttpMethod.POST, 180000, null).Result; if (foundationResponse == null) { foundationResponse = new FoundationResponse <string>(); } foundationResponse.IsSuccess = true; } } catch (Exception exception1) { Exception exception = exception1; foundationResponse.IsSuccess = false; foundationResponse.ErrMsg = string.Format("{0}\r\n{1}", exception.Message, exception.StackTrace); DebugUtil.LogException(exception); } } return(foundationResponse); }
public static ApiResult <TResult> PostWebApi <TResult, TData>(this string url, TData data, NameValueCollection headers = null, int timeout = 180000) { return(ProxyBase.Call <TResult, TData>(url, data, ApiHttpMethod.POST, timeout, headers)); }