///<summary> /// Stops the server and removes all added resources. ///</summary> public static void StopLocalServer() { if (WebServerManager.GetInstance().ServerIsRunning()) { WebServerManager.GetInstance().StopAll(); } }
///<summary> /// Creates a WebEvent with the given path. ///</summary> ///<param name="path">A string that identifies the event when an http request is received.</param> internal WebEvent(string path) { noHandlerSet = true; this.Path = path; this.manager = WebServerManager.GetInstance(); manager.AddWebEvent(this); ContentType = "text/plain"; }
/// <summary> /// Creates a path on the server so that an http GET request can be processed. /// Specifies a path of the form: http://{IP}:{port}/{path}. /// </summary> /// <param name="path">The path used to identify a resource.</param> /// <returns>A <see cref="T:GTM.NetworkModule.WebEvent"/> object that is used to update data and respond to incoming requests. /// </returns> public static WebEvent SetupWebEvent(string path) { WebEvent webEvent = WebServerManager.GetInstance().GetWebEventById(path); if (webEvent == null) { webEvent = new WebEvent(path); } return(webEvent); }
/// <summary> /// Creates a path to a resource on the server so that a http GET requests can be processed. /// Specifies the path of the form: http://{IP}:{port}/{path}. /// </summary> /// <param name="path">The path used to identify a resource.</param> /// <param name="refreshAfter">Specifies the refresh interval in seconds.</param> /// <returns>A <see cref="WebEvent"/> object that is used to update data and respond to incoming requests. /// </returns> public static WebEvent SetupWebEvent(string path, uint refreshAfter) { WebEvent webEvent = WebServerManager.GetInstance().GetWebEventById(path); if (webEvent == null) { webEvent = new WebEvent(path); } webEvent.refreshAfter = refreshAfter; return(webEvent); }
/// <summary> /// Gets the WebServerManager instance, which is handled as a singleton. /// </summary> /// <returns>The <see cref="T:GTM.NetworkModule.WebServerManager"/> instance</returns> public static WebServerManager GetInstance() { if (serverManager == null) { serverManager = new WebServerManager(); serverManager.DefaultEvent = new WebEvent("index.html"); serverManager.DefaultEvent.ResponseData = Encoding.UTF8.GetBytes("<html><head></head><body><h1>Hey, it works:-)</h1><p>Your .NET Gadgeteer Web Server is up and running!</p></body></html>"); serverManager.DefaultEvent.ContentType = "text/html"; Timeout = 60000; return serverManager; } else { return serverManager; } }
/// <summary> /// Gets the WebServerManager instance, which is handled as a singleton. /// </summary> /// <returns>The <see cref="T:GTM.NetworkModule.WebServerManager"/> instance</returns> public static WebServerManager GetInstance() { if (serverManager == null) { serverManager = new WebServerManager(); serverManager.DefaultEvent = new WebEvent("index.html"); serverManager.DefaultEvent.ResponseData = Encoding.UTF8.GetBytes("<html><head></head><body><h1>Hey, it works:-)</h1><p>Your .NET Gadgeteer Web Server is up and running!</p></body></html>"); serverManager.DefaultEvent.ContentType = "text/html"; Timeout = 60000; return(serverManager); } else { return(serverManager); } }
/// <summary> /// Creates the <see cref="Server"/> object. /// </summary> /// <param name="WebServerManager">The WebServerManager object that manages the server.</param> public Server(WebServerManager WebServerManager) { this.WebServerManager = WebServerManager; }
///<summary> /// Starts the web server and configures the network for the specified port. ///</summary> ///<param name="ipAddress">Ip address of the server</param> ///<param name="port">An <see cref="T:System.int"/> that specifies a port on which the web server runs.</param> ///<remarks> /// The server starts automatically when a resource is shared and the network interface is /// up. If this does not happen, stop the server before sharing data. /// </remarks> public static void StartLocalServer(string ipAddress, int port) { _ipAddress = ipAddress; _port = port; WebServerManager.GetInstance().StartServer(_ipAddress, _port); }
/// <summary> /// If the web server is running or not. /// </summary> /// <returns>True if the web server is running</returns> public static bool IsRunning() { return(WebServerManager.GetInstance().ServerIsRunning()); }
///<summary> /// Stops and removes a single resource. If the resource is requested again, the server will return the default page. ///</summary> ///<param name="webEvent">The <see cref="WebEvent"/> to be stopped</param> ///<returns>The result of the operation, <b>true</b> if the resource is found and removed, otherwise <b>false</b>.</returns> public static bool DisableWebEvent(WebEvent webEvent) { return(WebServerManager.GetInstance().Stop(webEvent)); }