コード例 #1
0
        public void createChild <T>(RestSessionBase session, T childRestObj, int responseChoice)
        {
            String parameters = null;

            if (responseChoice != -1)
            {
                parameters = "responseChoice=" + responseChoice.ToString();
            }

            string jsonToPost = JsonConvert.SerializeObject(childRestObj, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            HttpWebResponse response = session.sendRequestWithRetry("POST", getResourceUrlForChildType(session, childRestObj.GetType()), parameters, null, jsonToPost);

            if ((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                String       data   = reader.ReadToEnd();
                reader.Close();
                response.Close();

                List <T> list = JsonConvert.DeserializeObject <List <T> >(data, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore
                });
                T responseRestObj = list[0];
                copyJsonProperties(responseRestObj, childRestObj);
            }
        }
コード例 #2
0
        public List <T> fetch(RestSessionBase session, String filter, String orderBy, String[] groupBy, int page, int pageSize, String queryParameters, bool commit)
        {
            String resourceUrl           = getResourceUrl(session);
            WebHeaderCollection headers  = prepareHeaders(filter, orderBy, groupBy, page, pageSize);
            HttpWebResponse     response = session.sendRequestWithRetry("GET", resourceUrl, queryParameters, headers);

            if ((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                String       data   = reader.ReadToEnd();
                reader.Close();
                response.Close();

                return(JsonConvert.DeserializeObject <List <T> >(data, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                }));
            }

            throw new RestException("Response received with status code: " + response.StatusCode);
        }
コード例 #3
0
        public void assign <T>(RestSessionBase session, List <string> children)
        {
            if (typeof(T) == typeof(RestObject))
            {
                throw new RestException("Must use a derived type of RestObject");
            }

            string jsonToPost = JsonConvert.SerializeObject(children, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            HttpWebResponse response = session.sendRequestWithRetry("PUT", getResourceUrlForChildType(session, typeof(T)), null, null, jsonToPost);

            if ((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
            {
                response.Close();
                return;
            }

            response.Close();
            throw new RestException("Response received with status code: " + response.StatusCode);
        }
コード例 #4
0
        public void save(RestSessionBase session, int responseChoice)
        {
            String parameters = null;

            if (responseChoice != -1)
            {
                parameters = "responseChoice=" + responseChoice.ToString();
            }
            string jsonToPost = JsonConvert.SerializeObject(this, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            HttpWebResponse response = session.sendRequestWithRetry("PUT", getResourceUrl(session), parameters, null, jsonToPost);

            if ((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
            {
                response.Close();
                return;
            }

            response.Close();
            throw new RestException("Response received with status code: " + response.StatusCode);
        }
コード例 #5
0
        public void fetch(RestSessionBase session)
        {
            HttpWebResponse response = session.sendRequestWithRetry("GET", getResourceUrl(session), null, null, null);

            if ((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                String       data   = reader.ReadToEnd();
                reader.Close();
                response.Close();

                var objList = JsonConvert.DeserializeObject <List <JObject> >(data, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore
                });
                JObject jobject = objList[0];
                var     obj     = jobject.ToObject(this.GetType());
                copyJsonProperties(obj, this);
                return;
            }

            response.Close();
            throw new RestException(response.StatusDescription);
        }