/// <summary> /// [异步async]批量查询cdn流量 /// </summary> /// <param name="request">“流量查询”请求,详情请参阅该类型的说明</param> /// <returns>流量查询的结果</returns> public async Task <FluxResult> GetFluxDataAsync(FluxRequest request) { FluxResult result = new FluxResult(); try { string url = fluxEntry(); string body = request.ToJsonStr(); string token = auth.CreateManageToken(url); HttpResult hr = await httpManager.PostJsonAsync(url, body, token); result.Shadow(hr); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("[{0}] [Flux] Error: ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")); Exception e = ex; while (e != null) { sb.Append(e.Message + " "); e = e.InnerException; } sb.AppendLine(); result.RefCode = (int)HttpCode.USER_EXCEPTION; result.RefText += sb.ToString(); } return(result); }
/// <summary> /// 批量查询cdn流量 /// </summary> /// <param name="domains">域名列表</param> /// <param name="startDate">起始日期,如2017-01-01</param> /// <param name="endDate">结束日期,如2017-01-02</param> /// <param name="granularity">时间粒度,如day</param> /// <returns>流量查询的结果</returns> public async Task <FluxResult> GetFluxData(string[] domains, string startDate, string endDate, string granularity) { var request = new FluxRequest { Domains = string.Join(";", domains), StartDate = startDate, EndDate = endDate, Granularity = granularity }; var result = new FluxResult(); try { var url = FluxEntry; var body = request.ToJsonStr(); var token = _auth.CreateManageToken(url); var hr = await _httpManager.PostJsonAsync(url, body, token); result.Shadow(hr); } catch (Exception ex) { var sb = new StringBuilder(); sb.Append($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.ffff}] [flux] Error: "); var e = ex; while (e != null) { sb.Append(e.Message + " "); e = e.InnerException; } sb.AppendLine(); result.RefCode = (int)HttpCode.INVALID_ARGUMENT; result.RefText += sb.ToString(); } return(result); }
/// <summary> /// 批量查询cdn流量 /// </summary> /// <param name="domains">域名列表</param> /// <param name="startDate">起始日期,如2017-01-01</param> /// <param name="endDate">结束日期,如2017-01-02</param> /// <param name="granularity">时间粒度,如day</param> /// <returns>流量查询的结果</returns> public FluxResult GetFluxData(string[] domains, string startDate, string endDate, string granularity) { FluxRequest request = new FluxRequest(); request.Domains = string.Join(";", domains); request.StartDate = startDate; request.EndDate = endDate; request.Granularity = granularity; FluxResult result = new FluxResult(); try { string url = fluxEntry(); string body = request.ToJsonStr(); string token = auth.CreateManageToken(url); HttpResult hr = httpManager.PostJson(url, body, token); result.Shadow(hr); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("[{0}] [flux] Error: ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")); Exception e = ex; while (e != null) { sb.Append(e.Message + " "); e = e.InnerException; } sb.AppendLine(); result.RefCode = (int)HttpCode.INVALID_ARGUMENT; result.RefText += sb.ToString(); } return(result); }