[Test] public void Render_Request() { var fileInRoot = apiCassini.create_Random_File_Aspx().assert_File_Exists() .assert_File_Extension_Is(".aspx"); var fileName = fileInRoot.fileName(); var url = apiCassini.url_From_File(fileInRoot).assert_Equal(apiCassini.url(fileName)); var server = new Server(apiCassini.webRoot()); var host = server.GetHost(); url .GET() .assert_Valid().assert_Equals(fileInRoot.fileContents()); // check that we can get the file via a normal GET Request host.Render_Request(fileName).assert_Valid().assert_Equals(fileInRoot.fileContents()); // check that direct rendering of request produces the same value // check 404 apiCassini.host().Render_Request("a.html").assert_Contains("The resource cannot be found."); apiCassini.host().Render_Request("a.img" ).assert_Contains("The resource cannot be found."); // check that HTML returns an empty value var htmlInRoot = apiCassini.create_Random_File_Html().assert_File_Exists() .assert_File_Extension_Is(".html") .assert_File_Extension_Is_Not(".aspx"); host.Render_Request( htmlInRoot.fileName()).assert_Is(""); host.Render_Request("a" + htmlInRoot.fileName()).assert_Contains("The resource cannot be found.");; }
public void GET_Request_Using_GetHost_And_TcpClient() { var server = new Server("_temp_CassiniSite".tempDir()); var socket = Server.CreateSocketBindAndListen(AddressFamily.InterNetwork, server.IPAddress, server.Port); var thread = O2Thread.mtaThread( ()=>{ Socket acceptedSocket = socket.Accept(); var connection = new Connection(server,acceptedSocket); //var host = new Host(); // we can't get the host directly, it needs to be created using the technique coded in var host =server.GetHost(); // CreateWorkerAppDomainWithHost host.Configure(server, server.Port, server.VirtualPath, server.PhysicalPath); host.ProcessRequest(connection); }); var request1 = "GET / HTTP/1.1".line().line(); var tcpClient1 = server.Port.tcpClient(); tcpClient1.write(request1); var response1 = tcpClient1.read_Response(); Assert.IsTrue(response1.valid()); server.PhysicalPath.delete_Folder(); }
public Request(Server server, Host host, Connection connection) : base(String.Empty, String.Empty, null) { _connectionPermission = new PermissionSet(PermissionState.Unrestricted); _server = server; _host = host; _connection = connection; }
internal Connection(Server server, Socket socket) { Id = Guid.NewGuid(); _responseContent = new MemoryStream(); _server = server; _socket = socket; InitializeLogInfo(); }
/// <summary> /// </summary> public void Dispose() { if (_server != null) { StopServer(); _server.Dispose(); _server = null; } }
/// <summary> /// </summary> public void Dispose() { if (_server != null) { try { StopServer(); _server.Dispose(); _server = null; } catch { } } }
public void Init() { var dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); while (true) { if (!dir.Name.Equals("tests", StringComparison.OrdinalIgnoreCase)) { dir = dir.Parent; } else break; } _server = new Server(this.Port, this.AppPath, Path.Combine(dir.FullName, "WebSiteForIntegration"), false, true); _server.Start(); }
public static void Main() { var server = new Server("test".tempDir()); var host = server.invoke("GetHost"); var cassini = new API_Cassini(); cassini.start(); var browser = "FluentSharp.AspNet_Mvc".popupWindow() .add_WebBrowser() .add_NavigationBar(); browser.open(cassini.url()); browser.waitForClose(); cassini.stop(); }
public void TestFixtureSetup() { WebServer = (Server)ContextRegistry.GetContext().GetObject("testWebServer"); var isRunning = default(bool); try { isRunning = ((HttpWebResponse)(WebRequest.Create(BuildTestUrl("/")).GetResponse())).StatusCode == HttpStatusCode.OK; } catch (Exception ex) { } if(!isRunning) WebServer.Start(); WebClient = new WebClient(); }
public void GET_Request_Using_Start_And_TcpClient() { var server = new Server("_temp_CassiniSite".tempDir()); var fileName = "test.aspx"; var fileContents = "<%=\"some text\"%>"; var expectedResponse = "some text"; var filePath = server.PhysicalPath.pathCombine(fileName); fileContents.saveAs(filePath); server.Start(); var request = "GET /test.aspx HTTP/1.1".line().line(); var tcpClient = server.Port.tcpClient(); tcpClient.write(request); var response = tcpClient.read_Response(); Assert.IsTrue(response.valid()); var responseBody = response.subString_After("".line().line()); Assert.AreEqual(responseBody, expectedResponse); server.ShutDown(); server.PhysicalPath.delete_Folder(); }
public void Create_And_Configure_Host() { var server = new Server("_temp_CassiniSite".tempDir()); var host = new Host(); Assert.IsNotNull(host); //check values before configure Assert.Throws<NullReferenceException>(()=> host.GetProcessToken()); Assert.Throws<NullReferenceException>(()=> host.GetProcessUser()); Assert.IsNotNull(host.AppDomain); Assert.IsFalse (host.DisableDirectoryListing); Assert.IsNull (host.NormalizedClientScriptPath); Assert.IsNull (host.NormalizedVirtualPath); Assert.IsNull (host.PhysicalClientScriptPath); Assert.IsNull (host.PhysicalPath); Assert.AreEqual (0, host.Port); Assert.IsFalse (host.RequireAuthentication); Assert.IsNull (host.VirtualPath); host.Configure(server, server.Port, server.VirtualPath, server.PhysicalPath); //check values after configure Assert.AreNotEqual(host.GetProcessToken(),IntPtr.Zero); Assert.IsNotNull (host.GetProcessUser()); Assert.IsFalse (host.DisableDirectoryListing); Assert.IsNull (host.InstallPath); Assert.IsNotNull (host.NormalizedClientScriptPath); Assert.IsNotNull (host.NormalizedVirtualPath); Assert.IsNotNull (host.PhysicalClientScriptPath); Assert.IsNotNull (host.PhysicalPath); Assert.AreNotEqual(0, host.Port); Assert.IsFalse(host.RequireAuthentication); Assert.IsNotNull (host.VirtualPath); //removed tempDir server.PhysicalPath.delete_Folder(); }
public void GET_Request_Using_GetHost_And_SimpleWorkerRequest() { var server = new Server("_temp_CassiniSite".tempDir()); var host = server.GetHost(); //host.Configure(server, server.Port, server.VirtualPath, server.PhysicalPath); var fileName = "test.aspx"; var query1 = "name=John Smith"; var query2 = "name=OWASP"; var query3 = "name=42"; var query4 = ""; var fileContents = "<%=\"Hello \" + Request(\"name\") %>"; var expectedResponse1 = "Hello John Smith"; var expectedResponse2 = "Hello OWASP"; var expectedResponse3 = "Hello 42"; var expectedResponse4 = "Hello "; var filePath = server.PhysicalPath.pathCombine(fileName); fileContents.saveAs(filePath); var response1 = host.Render_Request(fileName, query1); var response2 = host.Render_Request(fileName, query2); var response3 = host.Render_Request(fileName, query3); var response4 = host.Render_Request(fileName, query4); Assert.AreEqual(response1, expectedResponse1); Assert.AreEqual(response2, expectedResponse2); Assert.AreEqual(response3, expectedResponse3); Assert.AreEqual(response4, expectedResponse4); server.ShutDown(); //delete temp server.PhysicalPath server.PhysicalPath.delete_Folder(); }
private static void Main(string[] cmdLine) { CommandLineArguments args = new CommandLineArguments(); if (!CommandLineParser.ParseArgumentsWithUsage(cmdLine, args)) { Environment.Exit(-1); } else { switch (args.RunMode) { case RunMode.Server: IPAddress ip=IPAddress.Loopback; try { args.Validate(); ip = CommandLineArguments.ParseIP(args.IPMode, args.IPv6, args.IPAddress); int port = args.PortMode == PortMode.FirstAvailable ? CassiniNetworkUtils.GetAvailablePort(args.PortRangeStart, args.PortRangeEnd, ip, true) : args.Port; if(args.AddHost) { HostsFile.AddHostEntry(ip.ToString(), args.HostName); } using (var server = new Server(port, args.VirtualPath, args.ApplicationPath, ip, args.HostName, args.TimeOut)) { server.Start(); Console.WriteLine("started: {0}\r\nPress Enter key to exit....", server.RootUrl); Console.ReadLine(); server.ShutDown(); } } catch (CassiniException ex) { Console.WriteLine("error:{0} {1}", ex.Field == ErrorField.None ? ex.GetType().Name : ex.Field.ToString(), ex.Message); } catch (Exception ex2) { Console.WriteLine("error:{0}", ex2.Message); Console.WriteLine(CommandLineParser.ArgumentsUsage(typeof(CommandLineArguments))); } finally { if (args.AddHost) { HostsFile.RemoveHostEntry(ip.ToString(), args.HostName); } } break; case RunMode.Hostsfile: SetHostsFile(args); break; } } }
public static int Main(string[] cmdLine) { Server server = null; if (cmdLine != null && cmdLine.Length > 0) { bool isVS = Assembly.GetExecutingAssembly() .GetName().Name.StartsWith("WEBDEV.WEBSERVER", StringComparison.OrdinalIgnoreCase); CommandLineArguments args = new CommandLineArguments(); if (!CommandLineParser.ParseArgumentsWithUsage(cmdLine, args)) { if (isVS) { // will display vs usage and return a code that VS understands return ValidateForVS(cmdLine); } string usage = CommandLineParser.ArgumentsUsage(typeof(CommandLineArguments), 120); ShowMessage(usage, MessageBoxIcon.Asterisk); return 0; } if (args.RunMode == RunMode.Hostsfile) { SetHostsFile(args); return 0; } // now we validate for us. int returnValue = -1; string message = null; try { args.VisualStudio = isVS; args.Validate(); } catch (CassiniException ex) { switch (ex.Message) { case SR.ErrNoAvailablePortFound: case SR.ErrApplicationPathIsNull: message = ex.Message; break; case SR.ErrInvalidIPMode: message = SR.GetString(ex.Message, args.IPMode); break; case SR.ErrInvalidPortMode: message = SR.GetString(ex.Message, args.PortMode); break; case SR.ErrPortIsInUse: message = SR.GetString(ex.Message, args.Port); break; case SR.ErrPortRangeEndMustBeEqualOrGreaterThanPortRangeSta: message = SR.GetString(ex.Message, args.PortRangeStart, args.PortRangeEnd); break; case SR.ErrInvalidPortRangeValue: message = SR.GetString(ex.Message, ex.Field == ErrorField.PortRangeStart ? "start " + args.PortRangeStart : "end " + args.PortRangeEnd); break; case SR.ErrInvalidHostname: message = SR.GetString(ex.Message, args.HostName); break; case SR.WebdevDirNotExist: message = SR.GetString(ex.Message, args.ApplicationPath); returnValue = -2; break; case SR.ErrPortOutOfRange: message = SR.GetString(ex.Message, args.Port); break; } if (!args.Silent) { ShowMessage(message, MessageBoxIcon.Asterisk); } return returnValue; } catch (Exception exception) { if (!args.Silent) { ShowMessage(SR.GetString(SR.ErrFailedToStartCassiniDevServerOnPortError, args.Port, exception.Message, exception.HelpLink), MessageBoxIcon.Error); } return -1; } server = new Server(args.Port, args.VirtualPath, args.ApplicationPath, args.Ntlm, args.Nodirlist); if (args.AddHost) { HostsFile.AddHostEntry(server.IPAddress.ToString(), server.HostName); } try { server.Start(); } catch (Exception exception) { if (!args.Silent) { ShowMessage(SR.GetString(SR.ErrFailedToStartCassiniDevServerOnPortError, args.Port, exception.Message, exception.HelpLink), MessageBoxIcon.Error); } return -4; } } using (FormView form = new FormView(server)) { Application.Run(form); } return 0; }
private void Start() { // use CommandLineArguments as a pre validation tool CommandLineArguments args = GetArgs(); ClearError(); try { args.Validate(); } catch (CassiniException ex) { SetError(ex.Field, ex.Message); return; } IPAddress = args.IPAddress; Port = args.Port; HostName = args.HostName; _server = new Server(args.Port, args.VirtualPath, args.ApplicationPath, System.Net.IPAddress.Parse(args.IPAddress), args.HostName, args.TimeOut, args.Ntlm, args.Nodirlist); if (args.AddHost) { HostsFile.AddHostEntry(_server.IPAddress.ToString(), _server.HostName); } try { _server.Start(); _server.TimedOut += OnTimedOut; UpdateUIFromServer(); InvokeSetRunState(RunState.Running); } catch (Exception ex) { SetError(ErrorField.None, ex.Message); _server.Dispose(); } }
public FormView(Server server) { _server = server; InitializeComponent(); InitializeUI(); }
public void StartServer() { if (!UpdateTargetWebConfig(_connectionString)) { return; } if (!Directory.Exists(_webFolderPath)) { _form.ShowStatusText("Folder not found"); return; } if (!File.Exists(Path.Combine(_webFolderPath, "web.config"))) { _form.ShowStatusText("Folder does not contain web files"); return; } var hostname = Dns.GetHostName(); try { _server = new Server(_port, "/TallyJ/", _webFolderPath, IPAddress.Any, hostname); _server.RequestComplete += _server_RequestComplete; _server.Start(); _url = _server.RootUrl; _form.SetUrl(_url); _form.SetButtonStates(Status.Running); _form.ShowStatusText("Server is Running"); _serverIsRunning = true; } catch (Exception ex) { _serverIsRunning = false; _form.SetButtonStates(Status.Stopped); _form.ShowStatusText(ex.Message); } }
public void Configure(Server server, int port, string virtualPath, string physicalPath, bool requireAuthentication, bool disableDirectoryListing) { _server = server; _port = port; _installPath = null; _virtualPath = virtualPath; _requireAuthentication = requireAuthentication; _disableDirectoryListing = disableDirectoryListing; _lowerCasedVirtualPath = CultureInfo.InvariantCulture.TextInfo.ToLower(_virtualPath); _lowerCasedVirtualPathWithTrailingSlash = virtualPath.EndsWith("/", StringComparison.Ordinal) ? virtualPath : virtualPath + "/"; _lowerCasedVirtualPathWithTrailingSlash = CultureInfo.InvariantCulture.TextInfo.ToLower(_lowerCasedVirtualPathWithTrailingSlash); _physicalPath = physicalPath; _physicalClientScriptPath = HttpRuntime.AspClientScriptPhysicalPath + "\\"; _lowerCasedClientScriptPathWithTrailingSlash = CultureInfo.InvariantCulture.TextInfo.ToLower(HttpRuntime.AspClientScriptVirtualPath + "/"); }
public void Configure(Server server, int port, string virtualPath, string physicalPath) { Configure(server, port, virtualPath, physicalPath, false, false); }
public void Configure(Server server, int port, string virtualPath, string physicalPath, bool requireAuthentication) { Configure(server, port, virtualPath, physicalPath, requireAuthentication, false); }
// Methods public void Dispose() { if (this._server != null) { this.StopServer(); this._server.Dispose(); this._server = null; } }
public API_Cassini(string physicalPath) { PhysicalPath = physicalPath; CassiniServer = new Server(physicalPath); }
public void StartServer(string applicationPath, IPAddress ipAddress, int port, string virtualPath, string hostname) { if (this._server != null) { throw new InvalidOperationException("Server already started"); } this._server = new CassiniDev.Server(port, virtualPath, applicationPath, ipAddress, hostname, Int32.MaxValue); try { this._server.Start(); } catch (Exception exception) { throw new InvalidOperationException("Error starting server instance.", exception); } }
protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } if (disposing && _server != null) { _server.Dispose(); _server = null; } base.Dispose(disposing); }
public API_Cassini(string physicalPath, string virtualPath, int port) { PhysicalPath = physicalPath; CassiniServer = new Server(port, virtualPath, physicalPath); }
/// <summary> /// </summary> /// <param name="applicationPath"> Physical path to application. </param> /// <param name="ipAddress"> IP to listen on. </param> /// <param name="port"> Port to listen on. </param> /// <param name="virtualPath"> Optional. default value '/' </param> /// <param name="hostname"> Optional. Used to construct RootUrl. Defaults to 'localhost' </param> public void StartServer(string applicationPath, IPAddress ipAddress, int port, string virtualPath, string hostname) { if (_server != null) { throw new InvalidOperationException("Server already started"); } _server = new Server(port, virtualPath, applicationPath, ipAddress, hostname, 60000); //try //{ // _server.Start(); //} //catch (Exception ex) //{ // throw new InvalidOperationException("Error starting server instance.", ex); //} }