DynamicRest.RestClient.PerformOperation C# (CSharp) Method

PerformOperation() private method

private PerformOperation ( string operationName ) : RestOperation
operationName string
return RestOperation
        private RestOperation PerformOperation(string operationName, params object[] args)
        {
            JsonObject argsObject = null;
            if ((args != null) && (args.Length != 0)) {
                argsObject = (JsonObject)args[0];
            }

            RestOperation operation = new RestOperation();

            HttpWebRequest webRequest = CreateRequest(operationName, argsObject);

            try {
                HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

                if (webResponse.StatusCode == HttpStatusCode.OK) {
                    Stream responseStream = webResponse.GetResponseStream();

                    try {
                        object result = ProcessResponse(responseStream);
                        operation.Complete(result,
                                           webResponse.StatusCode, webResponse.StatusDescription);
                    }
                    catch (Exception e) {
                        operation.Complete(new WebException(e.Message, e),
                                           webResponse.StatusCode, webResponse.StatusDescription);
                    }
                }
                else {
                    operation.Complete(new WebException(webResponse.StatusDescription),
                                       webResponse.StatusCode, webResponse.StatusDescription);
                }
            }
            catch (WebException webException) {
                HttpWebResponse response = (HttpWebResponse)webException.Response;
                operation.Complete(webException, response.StatusCode, response.StatusDescription);
            }

            return operation;
        }