コード例 #1
0
        public RestPartNameInfo GetPartyName(string confNumericId, ulong deviceId, HandleErrorMessage hdlErrMsg)
        {
            Dictionary <object, object> uriParams = new Dictionary <object, object>();

            uriParams.Add("confNumericId", confNumericId);
            uriParams.Add("deviceId", deviceId);
            string url = GetFullAcsUrl(REST_GET_PARTY_NAME_API, true, uriParams);

            return(GetObject <RestPartNameInfo>(url, null, hdlErrMsg));
        }
コード例 #2
0
        public AcsRest GetAcsInfoByCallNumber(string confNumericId, ulong deviceId, HandleErrorMessage hdlErrMsg)
        {
            Dictionary <object, object> uriParams = new Dictionary <object, object>();

            uriParams.Add("confNumericId", confNumericId);
            uriParams.Add("deviceId", deviceId);
            string url = GetFullDoradoUrl(REST_GET_ACS_API, true, uriParams);

            log.InfoFormat("Get acs info from {0}", url);
            return(GetObject <AcsRest>(url, null, hdlErrMsg));
        }
コード例 #3
0
        private bool DeleteObject(string url, HandleException handleException, HandleErrorMessage handleErrorMessage, bool isDoradoMsg = true)
        {
            bool         result   = true;
            RestResponse response = null;

            try
            {
                response = restClient.DeleteObject(url);
                if (response.StatusCode >= HttpStatusCode.BadRequest)
                {
                    log.InfoFormat("Failed to delete, status code: {0}, url: {1}", response.StatusCode, url);
                    if (handleErrorMessage == null)
                    {
                        HandleErrorMessageDefault(response, false, isDoradoMsg);
                    }
                    else
                    {
                        handleErrorMessage(response);
                    }
                    result = false;
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Failed to delete object, exception:{0}", ex);
                log.InfoFormat("Failed to delete, url:{0}", url);
                if (null == response)
                {
                    log.Info("The response is null for delete object");
                }
                else
                {
                    log.InfoFormat("Failed to delete object, the response is {0}", response.Content);
                }
                handleException?.Invoke(ex);
                result = false;
            }
            return(result);
        }
コード例 #4
0
        private RESPONSE PostObject <REQUEST, RESPONSE>(string url, REQUEST req, HandleException handleException, HandleErrorMessage handleErrorMessage, bool isDoradoMsg = true)
        {
            string       jsonData = JsonConvert.SerializeObject(req);
            RestResponse response = null;

            try
            {
                response = restClient.PostObject(url, jsonData);
                if (response.StatusCode >= HttpStatusCode.BadRequest)
                {
                    log.InfoFormat("Failed to post, status code: {0}, url: {1}", response.StatusCode, url);
                    if (handleErrorMessage == null)
                    {
                        HandleErrorMessageDefault(response, false, isDoradoMsg);
                    }
                    else
                    {
                        handleErrorMessage(response);
                    }
                    return(default(RESPONSE));
                }

                return(JsonConvert.DeserializeObject <RESPONSE>(response.Content));
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Failed to post object, exception:{0}", ex);
                log.InfoFormat("Failed to post, url:{0}", url);
                if (null == response)
                {
                    log.Info("The response is null for post object");
                }
                else
                {
                    log.InfoFormat("Failed to post object, the response is {0}", response.Content);
                }
                handleException?.Invoke(ex);
            }

            return(default(RESPONSE));
        }
コード例 #5
0
        public LoginResultByTokenRest GetDxjcLoginInfo(string serverAddress, string protocol, int port, string token, HandleErrorMessage hdlErrMsg)
        {
            log.InfoFormat("GetDxjcLoginInfo, protocol: {0}, port: {1}, token: {2}", protocol, port, token);
            string url         = string.Format(REST_GET_DXJC_LOGIN_INFO_API, token);
            string curProtocol = protocol;
            int    curPort     = port;

            if (string.IsNullOrEmpty(protocol))
            {
                curProtocol = "http";
            }

            if (0 == curPort)
            {
                curPort = "http" == curProtocol ? 80 : 443;
            }

            StringBuilder sb = new StringBuilder();

            sb.Append(curProtocol)
            .Append("://")
            .Append(serverAddress)
            .Append(":")
            .Append(string.Format("{0}", curPort))
            .Append(url);

            string fullUrl = sb.ToString();

            log.InfoFormat("GetDxjcLoginInfo full url: {0}", fullUrl);
            return(GetObject <LoginResultByTokenRest>(fullUrl, null, hdlErrMsg));
        }
コード例 #6
0
 protected override void ErrorMessage(string message) =>
 HandleErrorMessage?.Invoke($"[sttp] ERROR: {message}");