Exemple #1
0
        public setResult PostPodStatus(string id, SetAcState targetstate)
        {
            var Jstate = new JsonAcState();

            Jstate.AcState = targetstate;

            string json = JsonConvert.SerializeObject(Jstate);

            var request = (HttpWebRequest)WebRequest.Create(Schemes + "://" + Hosturl + BasePath + "/Pods/" + id + "/acStates?apiKey=" + _apikey);

            request.Method      = "POST"; //Set the request type to GET
            request.ContentType = Producer;


            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var response      = (HttpWebResponse)request.GetResponse();
            var responseValue = string.Empty;

            if (response.StatusCode != HttpStatusCode.OK)
            {
                var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
                throw new ApplicationException(message);
            }

            using (var responseStream = response.GetResponseStream())
            {
                if (responseStream != null)
                {
                    using (var reader = new StreamReader(responseStream))
                    {
                        responseValue = reader.ReadToEnd();
                    }
                }
            }

            //Convert the json respons to AcStatus object
            setResult mstatus = JsonConvert.DeserializeObject <setResult>(responseValue);

            return(mstatus);
        }
Exemple #2
0
        public setResult SetStatus(string id, SetAcState state)
        {
            RestClient sclient = new RestClient(apiKey);

            return(sclient.PostPodStatus(id, state));
        }