public void CallPostEJ() { if (ulStack.Count < 100) { return; } EJ eventJoin = new EJ(); eventJoin.mobileTime = new DateTime(DateTime.Now.Ticks).ToString(); Logger.LogDebugMessages("eventJoin.mobileTime: " + eventJoin.mobileTime); // Get next UL from stack and join show. string api = "api/user_locations/" + ulStack.Pop() + "/event_joins"; RunAsync(api, true, null, eventJoin).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()); } } }