public void ProcessRequest(HttpContext context) { ApplicationQueue responses = null; // read the request context.Request.InputStream.Seek(0, SeekOrigin.Begin); using (StreamReader sr = new StreamReader(context.Request.InputStream)) { string text = sr.ReadToEnd(); //Debug.Write(text); if (text.StartsWith("Commands:")) { int x = text.IndexOf("\r\n"); if (x > 0) { int target = 0; if (int.TryParse(text.Substring(9, x - 9), out target)) { text = text.Substring(x + 2); ApplicationQueue commands = ApplicationQueue.Create("commands", target.ToString()); commands.Append(text); string[] parts = text.Split(new char[] { ' ' }, 2); if (parts.Length == 2) { int id = 0; if (int.TryParse(parts[0], out id)) { responses = ApplicationQueue.Create("responses", target.ToString(), id.ToString()); } } } } } } // send the response { // Access-Control-Allow-Origin: * // Access-Control-Allow-Headers: X-Requested-With context.Response.AddHeader("Access-Control-Allow-Origin", "*"); context.Response.AddHeader("Access-Control-Allow-Headers", "X-Requested-With"); context.Response.ContentType = "text/plain"; context.Response.ContentEncoding = Encoding.UTF8; string text = responses != null?responses.ReadAll() : null; //Debug.Write(text); context.Response.Write("Responses:\r\n" + text); } }
private void ProcessSynchronizingEvents(WinWrap.Basic.BasicNoUIObj basicNoUIObj) { string commands = commands_.ReadAll(); if (!string.IsNullOrEmpty(commands)) { timelimit_ = DateTime.Now + new TimeSpan(0, 0, 10); // timeout in ten seconds string[] commands2 = commands.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string command in commands2) { string[] parts = command.Split(new char[] { ' ' }, 2); int id = int.Parse(parts[0]); string param = Encoding.UTF8.GetString(Convert.FromBase64String(parts[1])); basicNoUIObj.Synchronize(param, id); } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string data = context.Request["data"]; string action = context.Request["action"]; if (action != null) { switch (action.ToLowerInvariant()) { case "append": queue_.Append(data); context.Response.Write("Append: '" + data + "'"); break; case "readall": data = queue_.ReadAll(); context.Response.Write("ReadAll: '" + data + "'"); break; case "attach": data = attach + "\r\n"; commands_.Append(data); context.Response.Write("attach: data='" + data + "'"); break; #if false case "info": data = "Secret=" + Util.GetNamedString("Secret") + "\r\n" + "QueueConnection=" + Util.GetNamedString("QueueConnection"); context.Response.Write(data); break; #endif default: data = commands_.ReadAll(); context.Response.Write("commands: data='" + data + "'"); data = responses_.ReadAll(); context.Response.Write("responses: data='" + data + "'"); break; } } else { context.Response.Write("data='" + data + "'"); } }