public bool executePhoneCmd(int cmdIndex, BackgroundWorker worker, DoWorkEventArgs e) { EventJoin ej = commandsStack[cmdIndex]; DateTime startShowTime = Convert.ToDateTime(ej.mobileStartAt); while (DateTime.Now.Ticks < startShowTime.Ticks) { // Wait here until time to start the show Thread.Sleep(50); } string black = "0,0,0"; string red = "216,19,37"; //string white = "162,157,176"; int length = ej.commands.Length; int index = 0; Commands cmds = null; while (index < length) { cmds = ej.commands[index]; if (cmds.bg != null) { if (cmds.bg == black) { worker.ReportProgress(1, "Black"); //textBox1.BackColor = Color.FromName("Black"); } else if (cmds.bg == red) { worker.ReportProgress(1, "Red"); //textBox1.BackColor = Color.FromName("Red"); } else { worker.ReportProgress(1, "White"); //textBox1.BackColor = Color.FromName("White"); } } else //if (cmds.ct =="w") { worker.ReportProgress(1, "White"); //textBox1.BackColor = Color.FromName("Purple"); } Thread.Sleep(cmds.cl); index++; } return(true); }
static string MakeWebCall(string url, bool isPost = false, UL userLocationToRegister = null, EJ eventJoin = null, int index = 0) { try { using (var client = new WebClient()) { // New code: //client.BaseAddress = new Uri("http://main-1156949061.us-west-2.elb.amazonaws.com/"); client.BaseAddress = "http://www.litewaveinc.com/"; //client.BaseAddress = "http://127.0.0.1:3000/"; //client.Headers.Add("Accept: application/json"); client.Headers.Add("Content-Type", "application/json"); string 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"); string data = sr.ReadToEnd(); byte[] postArray = Encoding.ASCII.GetBytes(data); byte[] responseArray = client.UploadData(url, "POST", postArray); response = Encoding.ASCII.GetString(responseArray); } else { Stream data = client.OpenRead(url); StreamReader reader = new StreamReader(data); response = reader.ReadToEnd(); } if (response != null) { if (isPost && userLocationToRegister != null) { ULResult ulResult = new ULResult(); DataContractJsonSerializer jsonSer; jsonSer = new DataContractJsonSerializer(typeof(ULResult)); byte[] byteArray = Encoding.ASCII.GetBytes(response); MemoryStream stream = new MemoryStream(byteArray); ulResult = (ULResult)jsonSer.ReadObject(stream); ulStack[ULCount] = ulResult._id; ULCount++; } else if (isPost && eventJoin != null) { EventJoin ej = new EventJoin(); DataContractJsonSerializer jsonSer; jsonSer = new DataContractJsonSerializer(typeof(EventJoin)); byte[] byteArray = Encoding.ASCII.GetBytes(response); MemoryStream stream = new MemoryStream(byteArray); ej = (EventJoin)jsonSer.ReadObject(stream); commandsStack[index] = ej; EJCount++; } return(response); } } } catch (WebException webEx) { HttpWebResponse response = (System.Net.HttpWebResponse)webEx.Response; if (response.StatusCode == HttpStatusCode.NotFound) { System.Diagnostics.Debug.WriteLine("Not found!"); } } return(null); }