public T Request <T>(object param, OBS.Runtime.Internal.IRequest request, InterfaceType interfaceName = InterfaceType.DISInterfaceNone) where T : new()
        {
            try
            {
                Check();
                var    clientWrapper = new RestClientWrapper(request, _disConfig);
                string result        = clientWrapper.Request <string>(param, _credentials.GetAccessKeyId(), _credentials.GetSecretKey(), _region, _disConfig.GetProjectId(), interfaceName);
                result = result.Equals("Created") ? "{\"status_code\":\"201 Created\",\"content\":\"\"}"
                        : (result.Equals("NoContent") ? "{\"status_code\":\"204 NO CONTENT\",\"content\":\"\"}"
                        : result);

                if (result.Contains("errorCode") && result.Contains("message"))
                {
                    throw new Exception(result);
                }
                else
                {
                    return(JsonConvert.DeserializeObject <T>(result));
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Esempio n. 2
0
        private async new Task <T> Request <T>(object param, OBS.Runtime.Internal.IRequest request) where T : new()
        {
            try
            {
                var    clientWrapper = new RestClientWrapper(request, _disConfig);
                string result        = await clientWrapper.RequestAsync(param, _credentials.GetAccessKeyId(), _credentials.GetSecretKey(), _region, _disConfig.GetProjectId());

                int statusCode = int.Parse(result.Split('\n')[0]);
                var task       = new TaskCompletionSource <T>();
                if (statusCode >= 200 && statusCode < 300)
                {
                    result = result.Substring(statusCode.ToString().Length + 1);
                    result = result.Equals("Created") ? "{\"status_code\":\"201 Created\",\"content\":\"\"}"
                            : (result.Equals("NoContent") ? "{\"status_code\":\"204 NO CONTENT\",\"content\":\"\"}"
                            : result);
                    task.SetResult(JsonConvert.DeserializeObject <T>(result));
                    return(task.Task.Result);
                }
                else
                {
                    throw new Exception(result);
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }