/// <summary> /// 停止域名服务 /// </summary> /// <param name="httpClient"></param> public void Stop(AutoCSer.Net.HttpRegister.Server.TcpInternalClient httpClient) { if (!isStop) { isStop = true; httpClient.stop(Domains); } }
/// <summary> /// 启动域名服务 /// </summary> /// <returns></returns> public bool Start(AutoCSer.Net.HttpRegister.Server.TcpInternalClient httpClient) { if (!isStart) { AutoCSer.Net.TcpServer.ReturnValue <AutoCSer.Net.HttpRegister.RegisterState> state = httpClient.start(ServerType.Assembly.Location, ServerType.FullName, Domains, true); if (state.Type == AutoCSer.Net.TcpServer.ReturnType.Success) { if (state.Value == AutoCSer.Net.HttpRegister.RegisterState.Success) { return(isStart = true); } Console.WriteLine(ServerType.Name + " " + state.Value.ToString()); } else { Console.WriteLine(ServerType.Name + " " + state.Type.ToString()); } return(false); } return(true); }
static void Main(string[] args) { #if DOTNET2 AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetTcpRegisterAttribute(typeof(AutoCSer.Net.HttpRegister.Server)); AutoCSer.Net.HostPort serverListen = new AutoCSer.Net.HostPort { Host = AutoCSer.Web.Config.Pub.ServerListenIp, Port = 80 }; HttpDomain main = new HttpDomain { ServerType = typeof(WebServer), Domains = new AutoCSer.Net.HttpRegister.Domain[] { new AutoCSer.Net.HttpRegister.Domain { Host = serverListen, DomainName = AutoCSer.Web.Config.Web.MainDomain }, } }; HttpDomain file = new HttpDomain { ServerType = typeof(FileServer), Domains = new AutoCSer.Net.HttpRegister.Domain[] { new AutoCSer.Net.HttpRegister.Domain { Host = serverListen, DomainName = AutoCSer.Web.Config.Web.StaticFileDomain }, } }; HttpDomain location = new HttpDomain { ServerType = typeof(LocationServer), Domains = AutoCSer.Web.Config.Web.LocationDomains.getArray(domain => new AutoCSer.Net.HttpRegister.Domain { Host = serverListen, DomainName = domain }) }; do { try { using (AutoCSer.Net.HttpRegister.Server.TcpInternalClient httpClient = new AutoCSer.Net.HttpRegister.Server.TcpInternalClient(AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute))) { location.Stop(httpClient); file.Stop(httpClient); main.Stop(httpClient); if (main.Start(httpClient) && file.Start(httpClient) && location.Start(httpClient)) { return; } } } catch (Exception error) { Console.WriteLine(error.ToString()); } Thread.Sleep(1000); }while (true); #else Console.WriteLine(@"由于 www.AutoCSer.com 部署于 .NET 2.0 环境,当前项目仅用于编译 TypeScript"); Console.ReadKey(); #endif }
static void Main(string[] args) { //System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)1; AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetTcpRegisterAttribute(typeof(AutoCSer.Net.HttpRegister.Server)); byte isStopListen = 0; do { try { using (AutoCSer.Net.HttpRegister.Server serverValue = new AutoCSer.Net.HttpRegister.Server()) { serverValue.OnLoadCacheDomain += () => { if (isStopListen == 0) { isStopListen = 1; try { using (AutoCSer.Net.HttpRegister.Server.TcpInternalClient client = new AutoCSer.Net.HttpRegister.Server.TcpInternalClient(AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute))) { client.stopListen(false); client.stopListen(true); } } catch { } } }; serverValue.OnStopListen += exit; using (AutoCSer.Net.HttpRegister.Server.TcpInternalServer server = new AutoCSer.Net.HttpRegister.Server.TcpInternalServer(AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute), null, serverValue)) { if (server.IsListen) { Console.WriteLine("HTTP 服务启动成功 " + serverAttribute.Host + ":" + server.Port.toString()); AutoCSer.Diagnostics.ProcessCopyClient.Guard(); AutoCSer.Web.Config.Pub.ConsoleCommand(); AutoCSer.Diagnostics.ProcessCopyClient.Remove(); return; } } } } catch (Exception error) { Console.WriteLine(error.ToString()); } Thread.Sleep(1000); }while (true); }
static void Main(string[] args) { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetTcpRegisterAttribute(typeof(AutoCSer.Net.HttpRegister.Server)); byte isStopListen = 0; do { try { using (AutoCSer.Net.HttpRegister.Server serverValue = new AutoCSer.Net.HttpRegister.Server()) { serverValue.OnLoadCacheDomain += () => { if (isStopListen == 0) { isStopListen = 1; try { using (AutoCSer.Net.HttpRegister.Server.TcpInternalClient client = new AutoCSer.Net.HttpRegister.Server.TcpInternalClient(AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute))) { client.stopListen(false); client.stopListen(true); } } catch { } } }; serverValue.OnStopListen += () => { AutoCSer.Diagnostics.ProcessCopyClient.Remove(); AutoCSer.Threading.ThreadPool.TinyBackground.Start(() => { Thread.Sleep(1000); Environment.Exit(-1); }); }; using (AutoCSer.Net.HttpRegister.Server.TcpInternalServer server = new AutoCSer.Net.HttpRegister.Server.TcpInternalServer(AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute), null, serverValue)) { if (server.IsListen) { Console.WriteLine("HTTP 服务启动成功"); AutoCSer.Diagnostics.ProcessCopyClient.Guard(); AutoCSer.Web.Config.Pub.ConsoleCommand(); AutoCSer.Diagnostics.ProcessCopyClient.Remove(); return; } } } } catch (Exception error) { Console.WriteLine(error.ToString()); } Thread.Sleep(1000); }while (true); }