public void CallPostUL() { if (inShow) { // we are in a show, users can't join anymore. return; } Guid g = Guid.NewGuid(); UL userLocation = new UL(); userLocation.userSeat = new userSeat(); // Generate unique id and save result for EJ. userLocation.userKey = g.ToString(); userLocation.userSeat.level = "floor1"; userLocation.userSeat.section = "101"; userLocation.userSeat.row = currentRow.ToString(); userLocation.userSeat.seat = "1"; // currentSeat.ToString(); currentRow++; currentSeat++; // PROD RunAsync("api/events/5704a152182753c925df18f0/user_locations", true, userLocation).Wait(1120000); // LOCAL 55f4ba853451c8bc227664ff //RunAsync("api/events/55dd5fe01c1fd0cc1c7ffeab/user_locations", true, userLocation).Wait(1120000); }
static async Task <string> RunAsync(string url, bool isPost = false, UL userLocationToRegister = null, EJ eventJoin = null) { using (var client = new HttpClient()) { // New code: //client.BaseAddress = new Uri("http://main-1156949061.us-west-2.elb.amazonaws.com/"); client.BaseAddress = new Uri("http://www.litewaveinc.com/"); //client.BaseAddress = new Uri("http://127.0.0.1:3000/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.Timeout = new TimeSpan(0, 0, 0, 0, 20000); HttpResponseMessage response = null; if (isPost) { MemoryStream ms = new MemoryStream(); DataContractJsonSerializer jsonSer; if (userLocationToRegister != null) { //Create a Json Serializer for our type jsonSer = new DataContractJsonSerializer(typeof(UL)); // use the serializer to write the object to a MemoryStream jsonSer.WriteObject(ms, userLocationToRegister); } else if (eventJoin != null) { //Create a Json Serializer for our type jsonSer = new DataContractJsonSerializer(typeof(EJ)); // use the serializer to write the object to a MemoryStream jsonSer.WriteObject(ms, eventJoin); } ms.Position = 0; // use a Stream reader to construct the StringContent (Json) StreamReader sr = new StreamReader(ms); StringContent theContent = new StringContent(sr.ReadToEnd(), System.Text.Encoding.UTF8, "application/json"); response = await client.PostAsync(url, theContent); } else { response = await client.GetAsync(url); } if (response.IsSuccessStatusCode) { string s_response = response.ToString(); string s_response_content = await response.Content.ReadAsStringAsync(); if (isPost && userLocationToRegister != null) { ULResult ulResult = new ULResult(); DataContractJsonSerializer jsonSer; jsonSer = new DataContractJsonSerializer(typeof(ULResult)); Stream streamContent = await response.Content.ReadAsStreamAsync(); ulResult = (ULResult)jsonSer.ReadObject(streamContent); ulStack.Push(ulResult._id); } return(response.StatusCode.ToString()); } else { if (eventJoin != null) { if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { inShow = false; return(System.Net.HttpStatusCode.OK.ToString()); } else { // if EJ returned successful we are in a show. Stop UL from joining. inShow = true; } } //Console.WriteLine(response); //Logger.LogDebugMessages("Failed with status code: " + response.StatusCode.ToString()); //Assert.Fail("Failed with status code: " + response.StatusCode.ToString()); return(response.StatusCode.ToString()); } } }