Exemplo n.º 1
0
        /*returns a specific number (amount) of scores of a specific name*/
        public List <JsonItem> GetXScores(string name, int amount)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(Getxscores);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "{\"name\":\"" + name + "\"," + "\"amount\":" + amount + "}";

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var      result = streamReader.ReadToEnd();
                JsonWrap resp   = JsonConvert.DeserializeObject <JsonWrap>(result);


                List <JsonItem> res = JsonConvert.DeserializeObject <List <JsonItem> >(resp.m_StringValue);

                return(res);
            }
        }
Exemplo n.º 2
0
        /*add a user score to the cloud*/
        public void AddScore(string name, string time, string date, string distance)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(Addscore);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                string json = "{\"name\":\"" + name + "\"," + "\"time\":\"" + time + "\"," + "\"date\":\"" + date + "\"," + "\"distance\":\"" + distance + "\"}";

                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var      result = streamReader.ReadToEnd();
                JsonWrap resp   = JsonConvert.DeserializeObject <JsonWrap>(result);
                if (resp.m_StringValue != "OK")
                {
                    throw new Exception();  //note : catch the exception! - maybe no internet connection (!)
                }
            }
        }