Пример #1
0
        public void TraceApiError(string appKey, String sdkVersion, string apiName, string url, System.Collections.Generic.Dictionary <string, string> parameters, double latency, string errorMessage)
        {
            StringBuilder info = new StringBuilder();

            info.Append(appKey);
            info.Append(Constants.LOG_SPLIT);
            info.Append(sdkVersion);
            info.Append(Constants.LOG_SPLIT);
            info.Append(apiName);
            info.Append(Constants.LOG_SPLIT);
            info.Append(LazopUtils.GetIntranetIp());
            info.Append(Constants.LOG_SPLIT);
            info.Append(System.Environment.OSVersion.VersionString);
            info.Append(Constants.LOG_SPLIT);
            info.Append(latency);
            info.Append(Constants.LOG_SPLIT);
            info.Append(url);
            info.Append(Constants.LOG_SPLIT);
            info.Append(WebUtils.BuildQuery(parameters));
            info.Append(Constants.LOG_SPLIT);
            info.Append(errorMessage);
            this.Error(info.ToString());
        }
Пример #2
0
        private LazopResponse DoExecute(LazopRequest request, string accessToken, DateTime timestamp)
        {
            long start = DateTime.Now.Ticks;

            // add common params
            LazopDictionary txtParams = new LazopDictionary(request.GetParameters());

            txtParams.Add(Constants.APP_KEY, appKey);
            txtParams.Add(Constants.TIMESTAMP, GetTimestamp(timestamp));
            txtParams.Add(Constants.ACCESS_TOKEN, accessToken);
            txtParams.Add(Constants.PARTNER_ID, sdkVersion);
            txtParams.AddAll(this.customrParameters);
            txtParams.Add(Constants.SIGN_METHOD, this.signMethod);
            if (IsDebugEnabled())
            {
                txtParams.Add(Constants.DEBUG, true);
            }

            // compute and add sign
            txtParams.Add(Constants.SIGN, LazopUtils.SignRequest(request.GetApiName(), txtParams, appSecret, this.signMethod));

            string realServerUrl = GetServerUrl(this.serverUrl, request.GetApiName(), accessToken);
            string reqUrl        = WebUtils.BuildRequestUrl(realServerUrl, txtParams);

            try
            {
                string body;
                if (request.GetFileParameters() != null) // if file params is set
                {
                    body = webUtils.DoPost(realServerUrl, txtParams, request.GetFileParameters(), request.GetHeaderParameters());
                }
                else
                {
                    if (request.GetHttpMethod().Equals(Constants.METHOD_POST))
                    {
                        body = webUtils.DoPost(realServerUrl, txtParams, request.GetHeaderParameters());
                    }
                    else
                    {
                        body = webUtils.DoGet(realServerUrl, txtParams, request.GetHeaderParameters());
                    }
                }

                LazopResponse response = ParseResponse(body);

                // log error response
                if (response.IsError())
                {
                    TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                    LogApiError(appKey, sdkVersion, request.GetApiName(), serverUrl, txtParams, latency.TotalMilliseconds, response.Body);
                }
                else
                {
                    if (IsDebugEnabled() || IsInfoEnabled())
                    {
                        TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                        LogApiError(appKey, sdkVersion, request.GetApiName(), serverUrl, txtParams, latency.TotalMilliseconds, response.Body);
                    }
                }

                return(response);
            }
            catch (Exception e)
            {
                TimeSpan latency = new TimeSpan(DateTime.Now.Ticks - start);
                LogApiError(appKey, sdkVersion, request.GetApiName(), serverUrl, txtParams, latency.TotalMilliseconds, e.GetType() + ": " + e.Message);
                throw e;
            }
        }