public WebServer(Namiono namiono, string ident, string hostname, int port) { docRoot = Path.Combine(Environment.CurrentDirectory, ident); provider = namiono; provider.WebRequestHandled += (sender, e) => { var data = Encoding.UTF8.GetBytes(e.Content); Send(ref data, ref e.Context); }; socket = new HTTPSocket(hostname, port); socket.HTTPDataReceived += (sender, e) => { var evtargs = new WSDataReceivedEventArgs(); evtargs.Context = e.context; var path = FileSystem.ResolvePath(e.context.Request.Url.LocalPath, docRoot); if (path.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase) || path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase) || path.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase) || path.EndsWith(".ico", StringComparison.InvariantCultureIgnoreCase)) { var data = new byte[FileSystem.Size(path)]; var bytesRead = 0; FileSystem.Read(path, ref data, out bytesRead); e.context.Response.StatusCode = 200; e.context.Response.StatusDescription = "OK"; Send(ref data, ref e.context); } else { if (!string.IsNullOrEmpty(e.context.Request.Headers["Needs"])) { var needsHeader = e.context.Request.Headers["Needs"]; if (needsHeader == "shoutcast") { evtargs.Needs = Needs.ShoutCast; } if (needsHeader == "user") { evtargs.Needs = Needs.User; } if (needsHeader == "site") { evtargs.Needs = Needs.Site; } } else { evtargs.Needs = Needs.Nothing; } if (WSDataReceived != null) { WSDataReceived.Invoke(this, evtargs); } } }; socket.HTTPError += (sender, e) => { if (WSError == null) { return; } var evrgs = new WSErrorEventArgs(); evrgs.Exception = e.Exception; WSError.Invoke(this, evrgs); }; }
public UserProvider(Namiono namiono) { provider = namiono; }