void ClearLog_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (VerifySDCard()) { lock (LockObject) { using (StreamWriter sw = new StreamWriter(rootDir + fileName)) { sw.WriteLine(string.Empty); } } } responder.Respond("Log cleared."); }
void seePicture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (pic != null) { Bitmap b = new Bitmap(320, 240); b.DrawLine(Colors.Red, 20, 0, 0, 319, 239); byte[] buff = new byte[320 * 240 * 3 + 54]; GHIElectronics.NETMF.System.Util.BitmapToBMPFile(b.GetBitmap(), 320, 240, buff); GT.Picture picture = new GT.Picture(buff, GT.Picture.PictureEncoding.BMP); responder.Respond(picture); } else responder.Respond("Take picture first"); }
void toggleCapture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { captureOn = !(captureOn); string content = "<html><body><h1>" + getCaptureMode() + "</h1></body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); if (captureOn) multicolorLed.BlinkRepeatedly(GT.Color.Red); else multicolorLed.BlinkRepeatedly(GT.Color.Green); }
void getVersion_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { string content = "<html><body><h1>Version 1.0!</h1>"+getCaptureMode() + "</body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
/// <summary> /// Raises the <see cref="WebEventReceived"/> event. /// </summary> /// <param name="responder">Contains request data sent by the the client and functionality to respond to the request.</param> /// <param name="method">The incoming http method. </param> /// <param name="path">The path of the requested resource.</param> internal virtual void OnWebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (onWebEventReceived == null) onWebEventReceived = new ReceivedWebEventHandler(OnWebEventReceived); if (_WebEventReceived == null || noHandlerSet) { responder.SendResponse(); } else if (Program.CheckAndInvoke(_WebEventReceived, onWebEventReceived, path, method, responder)) { _WebEventReceived(path, method, responder); } }
/// <summary> /// Processes incoming requests /// </summary> protected void ProcessRequest() { // accept an incoming connection request and once we have one, spawn a new thread to accept more bool newThread = false; System.Net.Sockets.Socket clientSocket = null; Responder responder = null; while (IsRunning && !newThread) { try { // process incoming request clientSocket = LocalServer.Accept(); clientSocket.ReceiveTimeout = Timeout; clientSocket.SendTimeout = Timeout; // parse message an create an object containing parsed data responder = new Responder(); responder.ClientEndpoint = clientSocket.RemoteEndPoint.ToString(); responder.ClientSocket = clientSocket; Thread t = new Thread(new ThreadStart(ProcessRequest)); t.Start(); newThread = true; } catch { if (clientSocket != null) { try { clientSocket.Close(); } catch { } } } } // now process the request try { bool finishedParsing = false; TimeSpan parseStart = Timer.GetMachineTime(); while (!finishedParsing) { if (Timer.GetMachineTime() - parseStart > MaxProcessingTime) { return; } // receiving data, add to an array to process later byte[] buffer = new byte[clientSocket.Available]; clientSocket.Receive(buffer); finishedParsing = responder.parse(buffer); } // trigger event to get response WebEvent webevent = null; if (responder.Path != null && responder.Path.Length > 1) { webevent = serverManager.GetWebEventById(responder.Path); } if (webevent == null) { webevent = serverManager.DefaultEvent; } responder.webEvent = webevent; webevent.OnWebEventReceived(responder.Path, responder.HttpMethod, responder); } catch { } }
/// <summary> /// Raises the <see cref="WebEventReceived"/> event. /// </summary> /// <param name="responder">Contains request data sent by the the client and functionality to respond to the request.</param> /// <param name="method">The incoming http method. </param> /// <param name="path">The path of the requested resource.</param> internal virtual void OnWebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (onWebEventReceived == null) { onWebEventReceived = new ReceivedWebEventHandler(OnWebEventReceived); } if (_WebEventReceived == null || noHandlerSet) { responder.SendResponse(); } else if (Program.CheckAndInvoke(_WebEventReceived, onWebEventReceived, path, method, responder)) { _WebEventReceived(path, method, responder); } }
void hello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { Debug.Print("Hello world"); responder.Respond("Hello world"); }
void GetLog_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { if (VerifySDCard()) { using (StreamReader sr = new StreamReader(rootDir + fileName)) { string text = sr.ReadToEnd(); responder.Respond(text); } } else responder.Respond("No SD card detected."); }
/// <summary> /// Processes incoming requests /// </summary> protected void ProcessRequest() { // accept an incoming connection request and once we have one, spawn a new thread to accept more bool newThread = false; System.Net.Sockets.Socket clientSocket = null; Responder responder = null; while (IsRunning && !newThread) { try { // process incoming request clientSocket = LocalServer.Accept(); clientSocket.ReceiveTimeout = Timeout; clientSocket.SendTimeout = Timeout; // parse message an create an object containing parsed data responder = new Responder(); responder.ClientEndpoint = clientSocket.RemoteEndPoint.ToString(); responder.ClientSocket = clientSocket; Thread t = new Thread(new ThreadStart(ProcessRequest)); t.Start(); newThread = true; } catch { if (clientSocket != null) { try { clientSocket.Close(); } catch { } } } } // now process the request try { bool finishedParsing = false; TimeSpan parseStart = Timer.GetMachineTime(); while (!finishedParsing) { if (Timer.GetMachineTime() - parseStart > MaxProcessingTime) return; // receiving data, add to an array to process later byte[] buffer = new byte[clientSocket.Available]; clientSocket.Receive(buffer); finishedParsing = responder.parse(buffer); } // trigger event to get response WebEvent webevent = null; if (responder.Path != null) { webevent = serverManager.GetWebEventById(responder.Path); } if (webevent == null) { webevent = serverManager.DefaultEvent; } responder.webEvent = webevent; webevent.OnWebEventReceived(responder.Path, responder.HttpMethod, responder); } catch { } }
void sayHello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { string content = "<html><body><h1>Hello World!!</h1></body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
void authenticatesystem_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { string content = "<html><body><h1>connectionsuccessfulrunprogram</h1></body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
void webEventtemperature_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { string content = "<html><body><h1>" + temperature + "</h1></body></html>"; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
void view_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { led.TurnWhite(); Thread.Sleep(2000); led.TurnOff(); Debug.Print("View page requested"); TimeSpan time = GetMachineTime; new DateTime(time.Ticks).ToString("HH:mm:ss"); string content = "<html><title>Web Access</title><center><h1>Room Climate Monitor Web Access</center></h1><body></br></br></br>This is the web page for the Room Climate Control Monitor on IP" + systemip + ".</br></br>Currently the following values are detected: </br></br>Temperature: " + temperature.ToString() + "'c</br></br>Humidity: " + relativeHumidity + "</br></br>Percentage Light(Higher is Lighter): "+ lightpercentage + "%</br></br>Values change every few seconds but require the page to be refreshed for them to be updated.</br></br>Time: " + DateTime.Now + " </br></br></br>IP: " + systemip + "</br>Subnet Mask: " + ethernet.Interface.NetworkInterface.SubnetMask + "</br>Gateway: " + ethernet.Interface.NetworkInterface.GatewayAddress + "</br></br></br></br><center>Hosted on the .Net Gadgeteer Platform</center></body></html>" ; byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
void takePicture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { responder.Respond("Taking picture"); camera.TakePicture(); }
void GetReading_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { responder.Respond(GetNewReadings()); }
void state_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { responder.Respond(sensorState); }
void empty_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { responder.Respond("This is a RoboHome module and should be accessed using the API"); }
/// <summary> /// The response event for http://192.168.1.22:80/bio, /// Serialisese the bpm from the latest reading to a string, converts it to a byte array and passes it to the responder /// </summary> /// <param name="path">http://192.168.1.22:80/bio</param> /// <param name="method">Enum that represents the supported http methods, i.e. post, get, delete, put</param> /// <param name="responder">An object which responds to the request</param> void SendBioFeedback_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { string content = CurrentReading.SerialiseBpm(); byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content); responder.Respond(bytes, "text/html"); }
void sketch_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder) { Bitmap bitmap = background.Bitmap; byte[] buff = new byte[bitmap.Width * bitmap.Height * 3 + 54]; Util.BitmapToBMPFile(bitmap.GetBitmap(), bitmap.Width, bitmap.Height, buff); GT.Picture picture = new GT.Picture(buff, GT.Picture.PictureEncoding.BMP); responder.Respond(picture); }