Exemple #1
0
        /// <summary>
        /// [异步async]批量查询cdn带宽
        /// </summary>
        /// <param name="request">“带宽查询”请求,详情请参阅该类型的说明</param>
        /// <returns>带宽查询的结果</returns>
        public async Task <BandwidthResult> GetBandwidthDataAsync(BandwidthRequest request)
        {
            BandwidthResult result = new BandwidthResult();

            try
            {
                string url   = bandwidthEntry();
                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}] [Bandwidth] 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 <BandwidthResult> GetBandwidthData(string[] domains, string startDate, string endDate, string granularity)
        {
            var request = new BandwidthRequest
            {
                Domains     = string.Join(";", domains),
                StartDate   = startDate,
                EndDate     = endDate,
                Granularity = granularity
            };

            var result = new BandwidthResult();

            try
            {
                var url   = BandwidthEntry;
                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}] [bandwidth] 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 BandwidthResult GetBandwidthData(string[] domains, string startDate, string endDate, string granularity)
        {
            BandwidthRequest request = new BandwidthRequest();

            request.Domains     = string.Join(";", domains);
            request.StartDate   = startDate;
            request.EndDate     = endDate;
            request.Granularity = granularity;

            BandwidthResult result = new BandwidthResult();

            try
            {
                string url   = bandwidthEntry();
                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}] [bandwidth] 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);
        }