/// <summary> /// Applies the configuration of the server to the instance. /// </summary> /// <param name="configuration"> /// The <see cref="AspServerConfiguration" /> used to initialize the instance. /// </param> /// <param name="initializer">The initializer used to setup the pipeline for this instance.</param> public void ApplyConfiguration(IAspServerConfiguration configuration, IAspInitializer initializer) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (initializer == null) { throw new ArgumentNullException("initializer"); } _config = configuration; _httpListener = new HttpListener(); _httpListener.Prefixes.Add( string.Format(CultureInfo.InvariantCulture, "http://*:{0}{1}", _config.Port, _config.VirtualPath)); _processor = initializer.ConfigurationInitializer(_config.VirtualPath, _config.PhysicalPath); }
/// <summary> /// Applies the configuration of the server to the instance. /// </summary> /// <param name="configuration"> /// The <see cref="AspServerConfiguration" /> used to initialize the instance. /// </param> /// <param name="initializer">The initializer used to setup the pipeline for this instance.</param> public void ApplyConfiguration(IAspServerConfiguration configuration, IAspInitializer initializer) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (initializer == null) { throw new ArgumentNullException("initializer"); } _config = configuration; _httpListener = new HttpListener(); _httpListener.Prefixes.Add( string.Format(CultureInfo.InvariantCulture, "http://*:{0}{1}", _config.Port, _config.VirtualPath)); _processor = initializer.ConfigurationInitializer(_config.VirtualPath, _config.PhysicalPath); }
/// <summary> /// Initializes a new instance of the <see cref="T:Netty.NettyServer" /> class. /// </summary> /// <param name="physicalPath">The physical path to the website.</param> /// <param name="virtualPath">The virtual path the website runs on.</param> /// <param name="port">The port the website runs on.</param> /// <param name="enforcePortCheck"><c>true</c> to ensure the port is unused; otherwise, <c>false</c>.</param> /// <exception cref="System.ArgumentNullException"><paramref name="virtualPath"/> is <c>null</c>.</exception> /// <exception cref="System.ArgumentException"><paramref name="port"/> is already in use.</exception> /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="port"/> exceeds the allows TCP port range.</exception> /// <exception cref="System.IO.DirectoryNotFoundException"><paramref name="physicalPath"/> does not exist.</exception> public NettyServer(string physicalPath, string virtualPath, int port, bool enforcePortCheck) { if (virtualPath == null) { throw new ArgumentNullException("virtualPath"); } if (NetworkUtility.IsPortBeingUsed(port)) { throw new ArgumentException(ErrorMessages.PortInUse, "port"); } if (port > NetworkUtility.MaximumPort || port < NetworkUtility.MinimumPort) { throw new ArgumentOutOfRangeException("port"); } var di = new DirectoryInfo(physicalPath); if (!di.Exists) { throw new DirectoryNotFoundException(); } physicalPath = di.FullName; _webConfigFile = Path.Combine(physicalPath, "Web.config"); _originalWebConfig = File.Exists(_webConfigFile) ? File.ReadAllText(_webConfigFile) : null; _webConfigAltered = false; virtualPath = virtualPath[0] == '/' ? virtualPath : "/" + virtualPath; virtualPath = virtualPath[virtualPath.Length - 1] == '/' ? virtualPath : virtualPath + "/"; _config = new AspServerConfiguration() { Initializer = typeof(WebsiteInitializer), PhysicalPath = physicalPath, Port = port, VirtualPath = virtualPath }; }
/// <summary> /// Initializes a new instance of the <see cref="T:Netty.NettyServer" /> class. /// </summary> /// <param name="physicalPath">The physical path to the website.</param> /// <param name="virtualPath">The virtual path the website runs on.</param> /// <param name="port">The port the website runs on.</param> /// <param name="enforcePortCheck"><c>true</c> to ensure the port is unused; otherwise, <c>false</c>.</param> /// <exception cref="System.ArgumentNullException"><paramref name="virtualPath"/> is <c>null</c>.</exception> /// <exception cref="System.ArgumentException"><paramref name="port"/> is already in use.</exception> /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="port"/> exceeds the allows TCP port range.</exception> /// <exception cref="System.IO.DirectoryNotFoundException"><paramref name="physicalPath"/> does not exist.</exception> public NettyServer(string physicalPath, string virtualPath, int port, bool enforcePortCheck) { if (virtualPath == null) { throw new ArgumentNullException("virtualPath"); } if (NetworkUtility.IsPortBeingUsed(port)) { throw new ArgumentException(ErrorMessages.PortInUse, "port"); } if (port > NetworkUtility.MaximumPort || port < NetworkUtility.MinimumPort) { throw new ArgumentOutOfRangeException("port"); } var di = new DirectoryInfo(physicalPath); if (!di.Exists) { throw new DirectoryNotFoundException(); } physicalPath = di.FullName; _webConfigFile = Path.Combine(physicalPath, "Web.config"); _originalWebConfig = File.Exists(_webConfigFile) ? File.ReadAllText(_webConfigFile) : null; _webConfigAltered = false; virtualPath = virtualPath[0] == '/' ? virtualPath : "/" + virtualPath; virtualPath = virtualPath[virtualPath.Length - 1] == '/' ? virtualPath : virtualPath + "/"; _config = new AspServerConfiguration() { Initializer = typeof(WebsiteInitializer), PhysicalPath = physicalPath, Port = port, VirtualPath = virtualPath }; }