static void Main(string[] args) { bool createdProcessWait; EventWaitHandle processWait = new EventWaitHandle(false, EventResetMode.ManualReset, "AutoCSer.Web.DeployServer", out createdProcessWait); if (createdProcessWait) { using (processWait) { try { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetVerifyTcpServerAttribute(typeof(AutoCSer.Deploy.Server)); serverAttribute.Host = AutoCSer.Web.Config.Pub.ServerListenIp; serverAttribute.IsServer = true; using (AutoCSer.Deploy.Server.TcpInternalServer server = new AutoCSer.Deploy.Server.TcpInternalServer(serverAttribute)) { if (server.IsListen) { Console.WriteLine("部署服务 启动成功"); AutoCSer.Diagnostics.ProcessCopyClient.Guard(); AutoCSer.Web.Config.Pub.ConsoleCommand(); AutoCSer.Diagnostics.ProcessCopyClient.Remove(); return; } Console.WriteLine("部署服务 启动失败"); } } catch (Exception error) { Console.WriteLine(error.ToString()); } Console.ReadKey(); } } }
/// <summary> /// 部署服务 /// </summary> private static void createDeployServer() { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetVerifyTcpServerAttribute(typeof(AutoCSer.Deploy.Server)); serverAttribute.Host = AutoCSer.Web.Config.Pub.ServerListenIp; serverAttribute.IsServer = true; AutoCSer.Deploy.Server serverTarget = new AutoCSer.Deploy.Server(); serverTarget.BeforeSwitch += () => { switchEvent.Set(); exitEvent.WaitOne(); }; serverTarget.SetCustomTask(new ServerCustomTask()); using (AutoCSer.Deploy.Server.TcpInternalServer server = new AutoCSer.Deploy.Server.TcpInternalServer(serverAttribute, null, serverTarget)) { if (server.IsListen) { Console.WriteLine("部署服务 启动成功 " + serverAttribute.Host + ":" + serverAttribute.Port.toString()); switchEvent.WaitOne(); } else { Console.WriteLine("部署服务 启动失败 " + serverAttribute.Host + ":" + serverAttribute.Port.toString()); } } }
/// <summary> /// 创建搜索服务 /// </summary> internal static void CreateSearchServer() { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetTcpStaticRegisterAttribute(typeof(AutoCSer.Web.SearchServer.Server), false); if (new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Name == AutoCSer.Deploy.Server.DefaultSwitchDirectoryName) { serverAttribute.Port += 10000; } do { try { searchServer = new AutoCSer.Web.SearchServer.TcpStaticServer.SearchServer(AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute)); if (searchServer.IsListen) { Console.WriteLine("Search 服务启动成功 " + serverAttribute.Host + ":" + searchServer.Port.toString()); return; } Console.WriteLine("Search 服务启动失败 " + serverAttribute.Host + ":" + searchServer.Port.toString()); } catch (Exception error) { Console.WriteLine(error.ToString()); } Thread.Sleep(1000); }while (true); }
static void Main(string[] args) { #if DotNetStandard Console.WriteLine("WARN : Linux .NET Core not support name EventWaitHandle"); #else bool createdProcessWait; EventWaitHandle processWait = new EventWaitHandle(false, EventResetMode.ManualReset, "AutoCSer.TestCase.CacheServerPerformance", out createdProcessWait); if (createdProcessWait) { using (processWait) { #endif Console.WriteLine(@"http://www.AutoCSer.com/CacheServer/Index.html "); DirectoryInfo messageQueueDirectory = new DirectoryInfo("MessageQueue"); if (messageQueueDirectory.Exists) { foreach (DirectoryInfo directory in messageQueueDirectory.GetDirectories()) { directory.Delete(true); } } CacheServer.MasterServerConfig fileConfig = new CacheServer.MasterServerConfig { FileName = "PerformanceTest", IsIgnoreFileEndError = true }; deleteFile(fileConfig.FileName + ".amc"); deleteFile(fileConfig.FileName + ".amcs"); AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Metadata.TypeAttribute.GetAttribute <AutoCSer.Net.TcpInternalServer.ServerAttribute>(typeof(AutoCSer.CacheServer.MasterServer), false); serverAttribute.VerifyString = "!2#4%6&8QwErTyAsDfZx"; AutoCSer.Net.TcpInternalServer.ServerAttribute fileServerAttribute = AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute); fileServerAttribute.Port -= 1; using (AutoCSer.CacheServer.MasterServer.TcpInternalServer server = new AutoCSer.CacheServer.MasterServer.TcpInternalServer(serverAttribute)) using (AutoCSer.CacheServer.MasterServer.TcpInternalServer fileServer = new AutoCSer.CacheServer.MasterServer.TcpInternalServer(fileServerAttribute, null, new AutoCSer.CacheServer.MasterServer(fileConfig))) { if (server.IsListen && fileServer.IsListen) { if (!startProcess("CacheClientPerformance", "AutoCSer.TestCase.CacheClientPerformance")) { Console.WriteLine("未找到缓存服务性能测试服务 客户端程序"); } Console.WriteLine("Press quit to exit."); while (Console.ReadLine() != "quit") { ; } } else { Console.WriteLine("缓存服务性能测试服务 启动失败"); Console.ReadKey(); } } #if !DotNetStandard } } #endif }
static void Main(string[] args) { bool createdProcessWait; EventWaitHandle processWait = new EventWaitHandle(false, EventResetMode.ManualReset, "AutoCSer.Web.TcpRegister", out createdProcessWait); if (createdProcessWait) { using (processWait) { try { AutoCSer.Net.TcpInternalServer.ServerAttribute readerServerAttribute = AutoCSer.Web.Config.Pub.GetVerifyTcpServerAttribute(typeof(AutoCSer.Net.TcpRegister.ReaderServer)); AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetVerifyTcpServerAttribute(typeof(AutoCSer.Net.TcpRegister.Server)); AutoCSer.Net.TcpRegister.ReaderServer reader = AutoCSer.Net.TcpRegister.ReaderServer.Create(); using (AutoCSer.Net.TcpRegister.Server.TcpInternalServer registerServer = new AutoCSer.Net.TcpRegister.Server.TcpInternalServer(serverAttribute, null, reader.Server)) using (AutoCSer.Net.TcpRegister.ReaderServer.TcpInternalServer registerReaderServer = new AutoCSer.Net.TcpRegister.ReaderServer.TcpInternalServer(readerServerAttribute, null, reader)) { if (registerServer.IsListen && registerReaderServer.IsListen) { Console.WriteLine("TCP 注册服务启动成功"); AutoCSer.Threading.ThreadPool.TinyBackground.Start(processCopy); FileInfo httpServer = new FileInfo(@"..\..\..\HttpServer\bin\Release\AutoCSer.Web.HttpServer.exe"); if (httpServer.Exists) { ProcessStartInfo start = new ProcessStartInfo(httpServer.FullName); start.WorkingDirectory = httpServer.Directory.FullName; Process.Start(start); } FileInfo deployServer = new FileInfo(@"..\..\..\DeployServer\bin\Release\AutoCSer.Web.DeployServer.exe"); if (deployServer.Exists) { ProcessStartInfo start = new ProcessStartInfo(deployServer.FullName); start.WorkingDirectory = deployServer.Directory.FullName; Process.Start(start); } AutoCSer.Web.Config.Pub.ConsoleCommand(); isExit = true; if (processCopyServer != null) { processCopyServer.Dispose(); } return; } } Console.WriteLine("TCP 注册服务启动失败"); } catch (Exception error) { Console.WriteLine(error.ToString()); } Console.ReadKey(); } } }
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); }
/// <summary> /// AutoCSer.TestCase.Nuget.Server TCP调用服务端 /// </summary> /// <param name="attribute">TCP 调用服务器端配置信息</param> /// <param name="verify">套接字验证委托</param> /// <param name="log">日志接口</param> /// <param name="onCustomData">自定义数据包处理</param> public TcpInternalServer(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null) : base(attribute ?? (attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig("AutoCSer.TestCase.Nuget.Server", typeof(AutoCSer.TestCase.Nuget.Server))), verify, onCustomData, log, false) { Value = new AutoCSer.TestCase.Nuget.Server(); setCommandData(1); setCommand(0); if (attribute.IsAutoServer) { Start(); } }
/// <summary> /// 部署服务客户端 /// </summary> /// <param name="client"></param> /// <param name="name"></param> /// <param name="attribute"></param> internal TcpClient(Client client, string name, AutoCSer.Net.TcpInternalServer.ServerAttribute attribute) { this.Client = client; this.name = name; #if NoAutoCSer throw new Exception(); #else TcpInternalClient = new Server.TcpInternalClient(attribute); TcpInternalClient._TcpClient_.OnSetSocket(onClientSocket); #endif }
/// <summary> /// ITestServer TCP调用服务端 /// </summary> /// <param name="attribute">TCP 调用服务器端配置信息</param> /// <param name="verify">套接字验证委托</param> /// <param name="value">TCP 服务目标对象</param> /// <param name="extendCommandBits">扩展服务命令二进制位数</param> /// <param name="onCustomData">自定义数据包处理</param> /// <param name="log">日志接口</param> public TcpInternalServer(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null, AutoCSer.Example.TcpRegisterClient.RegisterClientTestServer value = null, byte extendCommandBits = 0, Action <SubArray <byte> > onCustomData = null, AutoCSer.ILog log = null) : base(attribute ?? (attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig("ITestServer", typeof(AutoCSer.Example.TcpRegisterClient.RegisterClientTestServer))), verify, null, extendCommandBits, onCustomData, log, 0, false, false) { Value = value ?? new AutoCSer.Example.TcpRegisterClient.RegisterClientTestServer(); setCommandData(1); setCommand(0); if (attribute.IsAutoServer) { Start(); } }
/// <summary> /// 部署服务客户端 /// </summary> /// <param name="client"></param> /// <param name="name"></param> /// <param name="attribute"></param> /// <param name="verifyMethod"></param> internal TcpClient(Client client, string name, AutoCSer.Net.TcpInternalServer.ServerAttribute attribute, Func <Server.TcpInternalClient, AutoCSer.Net.TcpInternalServer.ClientSocketSender, bool> verifyMethod) { this.Client = client; this.name = name; #if NoAutoCSer throw new Exception(); #else TcpInternalClient = new Server.TcpInternalClient(attribute, verifyMethod); checkSocketVersion = TcpInternalClient._TcpClient_.CreateCheckSocketVersion(onClientSocket); #endif }
/// <summary> /// TCP调用服务端 /// </summary> /// <param name="attribute">TCP调用服务器端配置信息</param> /// <param name="verify">TCP验证实例</param> /// <param name="log">日志接口</param> /// <param name="onCustomData">自定义数据包处理</param> public SearchServer(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null) : base(attribute ?? (attribute = AutoCSer.Net.TcpStaticServer.ServerAttribute.GetConfig("SearchServer", typeof(AutoCSer.Web.SearchServer.Server), true)), verify, onCustomData, log, false) { setCommandData(3); setCommand(0); setVerifyCommand(1); setCommand(2); if (attribute.IsAutoServer) { Start(); } }
/// <summary> /// TCP调用客户端 /// </summary> /// <param name="attribute">TCP 调用服务器端配置信息</param> /// <param name="clientRoute">TCP 客户端路由</param> /// <param name="onCustomData">自定义数据包处理</param> /// <param name="log">日志接口</param> public TcpInternalClient(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, AutoCSer.Net.TcpServer.ClientLoadRoute <AutoCSer.Net.TcpInternalServer.ClientSocketSender> clientRoute = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null) { if (attribute == null) { attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig("AutoCSer.TestCase.Nuget.Server", typeof(AutoCSer.TestCase.Nuget.Server)); } _TcpClient_ = new AutoCSer.Net.TcpInternalServer.Client <TcpInternalClient>(this, attribute, onCustomData, log, clientRoute); if (attribute.IsAuto) { _TcpClient_.TryCreateSocket(); } }
/// <summary> /// TCP调用客户端 /// </summary> /// <param name="attribute">TCP 调用服务器端配置信息</param> /// <param name="onCustomData">自定义数据包处理</param> /// <param name="log">日志接口</param> public TcpInternalClient(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null) { if (attribute == null) { attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig("ITestServer", typeof(AutoCSer.Example.TcpRegisterClient.RegisterClientTestServer)); } _TcpClient_ = new AutoCSer.Net.TcpInternalServer.Client <TcpInternalClient>(this, attribute, onCustomData, log); if (attribute.IsAuto) { _TcpClient_.TryCreateSocket(); } }
/// <summary> /// 创建磁盘块服务 /// </summary> /// <param name="block">磁盘块处理接口</param> /// <returns>磁盘块服务</returns> public static TcpInternalServer Create(IBlock block) { AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig(ServerName, typeof(AutoCSer.DiskBlock.Server)); int index = block.Index; if (index != 0) { attribute = AutoCSer.MemberCopy.Copyer <Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(attribute); attribute.Name += index.toString(); } return(new TcpInternalServer(attribute, null, new Server(block))); }
static void Main(string[] args) { FileInfo switchFile = AutoCSer.Deploy.Server.GetSwitchFile(); if (switchFile != null) { switchFile.StartProcessDirectory(); return; } EventWaitHandle processWait = AutoCSer.Deploy.Server.TryCreateProcessEventWaitHandle(); if (processWait != null) { using (processWait) { try { AutoCSer.Threading.ThreadPool.TinyBackground.Start(() => { AutoCSer.Web.Config.Pub.ConsoleCommand(() => exitEvent.Set()); }); AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetVerifyTcpServerAttribute(typeof(AutoCSer.Deploy.Server)); serverAttribute.Host = AutoCSer.Web.Config.Pub.ServerListenIp; serverAttribute.IsServer = true; AutoCSer.Deploy.Server serverTarget = new AutoCSer.Deploy.Server(); serverTarget.BeforeSwitch += () => exitEvent.Set(); serverTarget.SetCustomTask(new ServerCustomTask()); using (AutoCSer.Deploy.Server.TcpInternalServer server = new AutoCSer.Deploy.Server.TcpInternalServer(serverAttribute, null, serverTarget)) { if (server.IsListen) { Console.WriteLine("部署服务 启动成功 " + serverAttribute.Host + ":" + serverAttribute.Port.toString()); AutoCSer.Diagnostics.ProcessCopyClient.Guard(); exitEvent.WaitOne(); } else { Console.WriteLine("部署服务 启动失败 " + serverAttribute.Host + ":" + serverAttribute.Port.toString()); } } } catch (Exception error) { Console.WriteLine(error.ToString()); } } } AutoCSer.Diagnostics.ProcessCopyClient.Remove(); Thread.Sleep(1000); }
/// <summary> /// TcpRegister TCP调用服务端 /// </summary> /// <param name="attribute">TCP 调用服务器端配置信息</param> /// <param name="verify">套接字验证委托</param> /// <param name="value">TCP 服务目标对象</param> /// <param name="onCustomData">自定义数据包处理</param> /// <param name="log">日志接口</param> public TcpInternalServer(AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, Func <System.Net.Sockets.Socket, bool> verify = null, AutoCSer.Net.TcpRegister.Server value = null, Action <SubArray <byte> > onCustomData = null, AutoCSer.Log.ILog log = null) : base(attribute ?? (attribute = AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig("TcpRegister", typeof(AutoCSer.Net.TcpRegister.Server))), verify, null, onCustomData, log, 1, true, false) { Value = value ?? new AutoCSer.Net.TcpRegister.Server(); setCommandData(4); setVerifyCommand(1); setCommand(2); setCommand(3); Value.SetTcpServer(this); if (attribute.IsAutoServer) { Start(); } }
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 ClientPool() { ClientConfig config = ConfigLoader.GetUnion(typeof(ClientConfig)).ClientConfig ?? new ClientConfig(); (clients = new Server.TcpInternalClient[Math.Max(config.Count, 1)])[0] = new Server.TcpInternalClient(); AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = (AutoCSer.Net.TcpInternalServer.ServerAttribute)clients[0]._TcpClient_.Attribute; for (var index = clients.Length; index != 1;) { Net.TcpInternalServer.ServerAttribute copyAttribute = AutoCSer.MemberCopy.Copyer <Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(attribute); copyAttribute.Name = attribute.Name + (--index).toString(); copyAttribute.Host = null; copyAttribute.Port = 0; clients[index] = new Server.TcpInternalClient(copyAttribute); } }
static void Main(string[] args) { #if DotNetStandard Console.WriteLine("WARN : Linux .NET Core not support name EventWaitHandle"); #else bool createdProcessWait; EventWaitHandle processWait = new EventWaitHandle(false, EventResetMode.ManualReset, "AutoCSer.TestCase.CacheClientPerformance", out createdProcessWait); if (createdProcessWait) { using (processWait) { #endif Console.WriteLine(@"http://www.AutoCSer.com/CacheServer/Index.html "); AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Metadata.TypeAttribute.GetAttribute <AutoCSer.Net.TcpInternalServer.ServerAttribute>(typeof(AutoCSer.CacheServer.MasterServer), false); serverAttribute.VerifyString = "!2#4%6&8QwErTyAsDfZx"; AutoCSer.Net.TcpInternalServer.ServerAttribute fileServerAttribute = AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute); fileServerAttribute.Port -= 1; using (AutoCSer.CacheServer.Client client = new AutoCSer.CacheServer.Client(new AutoCSer.CacheServer.MasterServer.TcpInternalClient(serverAttribute))) using (AutoCSer.CacheServer.Client fileClient = new AutoCSer.CacheServer.Client(new AutoCSer.CacheServer.MasterServer.TcpInternalClient(fileServerAttribute))) { do { new MessageQueue(fileClient).Test(); new MesssageDistributor(fileClient).Test(); new Dictionary(client, false).Test(); new Dictionary(fileClient, true).Test(); new Array(client, false).Test(); new Array(fileClient, true).Test(); new Binary(client, false).Test(); new Binary(fileClient, true).Test(); new Json(client, false).Test(); new Json(fileClient, true).Test(); }while (true); } #if !DotNetStandard } } #endif }
/// <summary> /// 部署服务 /// </summary> private static void createDeployServer() { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetVerifyTcpServerAttribute(typeof(AutoCSer.Deploy.Server)); serverAttribute.Host = AutoCSer.Web.Config.Pub.ServerListenIp; serverAttribute.IsServer = true; using (AutoCSer.Deploy.Server.TcpInternalServer server = new AutoCSer.Deploy.Server.TcpInternalServer(serverAttribute, null, new Server(switchEvent, exitEvent))) { if (server.IsListen) { Console.WriteLine("部署服务 启动成功 " + serverAttribute.Host + ":" + serverAttribute.Port.toString()); //AutoCSer.Deploy.Server.DeleteBakDirectory(Date.UtcNow.AddDays(-30)); switchEvent.WaitOne(); } else { Console.WriteLine("部署服务 启动失败 " + serverAttribute.Host + ":" + serverAttribute.Port.toString()); } } }
static void Main(string[] args) { foreach (KeyValue <HashString, AutoCSer.Search.StaticSearcher <DataKey> .QueryResult> result in Searcher.Default.Search("AutoCSer")) { Console.WriteLine(result.Key.ToString() + " " + result.Value.Count.ToString()); } AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetTcpStaticRegisterAttribute(typeof(AutoCSer.Web.SearchServer.Server)); do { try { try { Console.WriteLine(TcpCall.Server.StopListen(AutoCSer.Web.SearchServer.Server.CurrentProcessId).Type.ToString()); } catch (Exception error) { Console.WriteLine(error.ToString()); } using (AutoCSer.Web.SearchServer.TcpStaticServer.SearchServer server = new AutoCSer.Web.SearchServer.TcpStaticServer.SearchServer(AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute))) { if (server.IsListen) { AutoCSer.Web.SearchServer.Server.CurrentServer = server; Console.WriteLine("Search 服务启动成功"); AutoCSer.Diagnostics.ProcessCopyClient.Guard(); AutoCSer.Web.Config.Pub.ConsoleCommand(); AutoCSer.Diagnostics.ProcessCopyClient.Remove(); return; } Console.WriteLine("Search 服务启动失败"); } } catch (Exception error) { Console.WriteLine(error.ToString()); } Thread.Sleep(1000); }while (true); }
/// <summary> /// 创建搜索服务 /// </summary> internal static void CreateSearchServer() { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetTcpStaticRegisterAttribute(typeof(AutoCSer.Web.SearchServer.Server)); do { try { searchServer = new AutoCSer.Web.SearchServer.TcpStaticServer.SearchServer(AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(serverAttribute)); if (searchServer.IsListen) { Console.WriteLine("Search 服务启动成功 " + serverAttribute.Host + ":" + searchServer.Port.toString()); return; } Console.WriteLine("Search 服务启动失败 " + serverAttribute.Host + ":" + searchServer.Port.toString()); } catch (Exception error) { Console.WriteLine(error.ToString()); } Thread.Sleep(1000); }while (true); }
static void Main(string[] args) { bool createdProcessWait; EventWaitHandle processWait = new EventWaitHandle(false, EventResetMode.ManualReset, "AutoCSer.Web.TcpRegister", out createdProcessWait); if (createdProcessWait) { using (processWait) { try { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetVerifyTcpServerAttribute(typeof(AutoCSer.Net.TcpRegister.Server)); using (AutoCSer.Net.TcpRegister.Server.TcpInternalServer registerServer = new AutoCSer.Net.TcpRegister.Server.TcpInternalServer(serverAttribute)) { if (registerServer.IsListen) { Console.WriteLine("TCP 注册服务启动成功 " + serverAttribute.Host + ":" + registerServer.Port.toString()); AutoCSer.Threading.ThreadPool.TinyBackground.Start(processCopy); AutoCSer.Web.Config.Pub.ConsoleCommand(); isExit = true; if (processCopyServer != null) { processCopyServer.Dispose(); } return; } } Console.WriteLine("TCP 注册服务启动失败"); } catch (Exception error) { Console.WriteLine(error.ToString()); } Console.ReadKey(); } } }
/// <summary> /// 启动进程复制重启服务 /// </summary> private static void processCopy() { do { try { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Metadata.TypeAttribute.GetAttribute <AutoCSer.Net.TcpInternalServer.ServerAttribute>(typeof(AutoCSer.Diagnostics.ProcessCopyServer), false); serverAttribute.VerifyString = AutoCSer.Web.Config.Pub.TcpVerifyString; AutoCSer.Diagnostics.ProcessCopyServer.TcpInternalServer server = new AutoCSer.Diagnostics.ProcessCopyServer.TcpInternalServer(serverAttribute); if (server.IsListen) { Console.WriteLine("进程复制重启服务启动成功"); processCopyServer = server; return; } } catch (Exception error) { Console.WriteLine(error.ToString()); } Thread.Sleep(1000); }while (!isExit); }
/// <summary> /// 缓存服务客户端 /// </summary> /// <param name="serverAttribute">缓存服务端配置</param> public SlaveClient(AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute) { client = new SlaveServer.TcpInternalClient(serverAttribute); }
internal static AutoCSer.Net.TcpInternalServer.ServerAttribute CreateStaticRouteAttribute(int index, AutoCSer.Net.TcpInternalServer.ServerAttribute attribute) { (attribute = AutoCSer.MemberCopy.Copyer <AutoCSer.Net.TcpInternalServer.ServerAttribute> .MemberwiseClone(attribute)).Name += "_" + index.toString(); return(attribute); }
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 }
/// <summary> /// 创建缓存服务静态路由集群节点 /// </summary> /// <param name="index">节点编号</param> /// <param name="attribute">TCP 调用服务器端配置信息</param> /// <param name="value">TCP 服务目标对象</param> /// <param name="log">日志接口</param> public static TcpInternalServer CreateStaticRoute(int index, AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, MasterServer value = null, AutoCSer.Log.ILog log = null) { return(new TcpInternalServer(CreateStaticRouteAttribute(index, attribute ?? AutoCSer.Net.TcpInternalServer.ServerAttribute.GetConfig(ServerName, typeof(MasterServer))), null, value, null, log)); }
/// <summary> /// 创建缓存服务静态路由集群节点 /// </summary> /// <param name="index">节点编号</param> /// <param name="attribute">TCP 调用服务器端配置信息</param> /// <param name="log">日志接口</param> public TcpInternalServer CreateStaticRoute(int index, AutoCSer.Net.TcpInternalServer.ServerAttribute attribute = null, AutoCSer.Log.ILog log = null) { return(CreateStaticRoute(index, attribute, this, log)); }
static void Main(string[] args) { bool createdProcessWait; EventWaitHandle processWait = new EventWaitHandle(false, EventResetMode.ManualReset, "AutoCSer.Web.DeployClient", out createdProcessWait); if (createdProcessWait) { using (processWait) { AutoCSer.Net.TcpInternalServer.ServerAttribute serverAttribute = AutoCSer.Web.Config.Pub.GetVerifyTcpServerAttribute(typeof(AutoCSer.Deploy.Server)); serverAttribute.Host = AutoCSer.Web.Config.Deploy.ServerIp; DirectoryInfo webReleaseDirectory = new DirectoryInfo(@"..\..\..\www.AutoCSer.com\bin\Release\"); string serverWebPath = AutoCSer.Web.Config.Deploy.ServerPath + @"www.AutoCSer.com\"; AutoCSer.Deploy.ClientTask[] htmlTasks = new AutoCSer.Deploy.ClientTask[] { new AutoCSer.Deploy.ClientTask { Type = AutoCSer.Deploy.TaskType.WebFile, ClientPath = webReleaseDirectory.Parent.Parent.FullName, ServerPath = serverWebPath, }, new AutoCSer.Deploy.ClientTask { Type = AutoCSer.Deploy.TaskType.File, ClientPath = webReleaseDirectory.Parent.Parent.FullName, ServerPath = serverWebPath, FileSearchPatterns = new string[] { "*.png" }, } }; AutoCSer.Deploy.ClientTask[] webTasks = new AutoCSer.Deploy.ClientTask[] { htmlTasks[0], htmlTasks[1], new AutoCSer.Deploy.ClientTask { Type = AutoCSer.Deploy.TaskType.Run, ClientPath = webReleaseDirectory.FullName, ServerPath = AutoCSer.Web.Config.Deploy.ServerPath + @"www.AutoCSer.com\bin\Release\", RunFileName = "AutoCSer.Web.exe", } }; AutoCSer.Deploy.ClientTask[] httpTasks = new AutoCSer.Deploy.ClientTask[] { webTasks[0], webTasks[1], webTasks[2], new AutoCSer.Deploy.ClientTask { Type = AutoCSer.Deploy.TaskType.AssemblyFile, ClientPath = webReleaseDirectory.FullName, ServerPath = AutoCSer.Web.Config.Deploy.ServerPath + @"www.AutoCSer.com\bin\Release\" }, new AutoCSer.Deploy.ClientTask { Type = AutoCSer.Deploy.TaskType.Run, ClientPath = new DirectoryInfo(@"..\..\..\HttpServer\bin\Release\").FullName, ServerPath = AutoCSer.Web.Config.Deploy.ServerPath + @"HttpServer\bin\Release\", RunFileName = "AutoCSer.Web.HttpServer.exe", } }; AutoCSer.Deploy.ClientTask[] exampleTasks = new AutoCSer.Deploy.ClientTask[] { new AutoCSer.Deploy.ClientTask { Type = AutoCSer.Deploy.TaskType.File, ClientPath = new DirectoryInfo(@"..\..\..\www.AutoCSer.com\Download\").FullName, ServerPath = AutoCSer.Web.Config.Deploy.ServerPath + @"www.AutoCSer.com\Download\", }, new AutoCSer.Deploy.ClientTask { Type = AutoCSer.Deploy.TaskType.File, ClientPath = new DirectoryInfo(@"..\..\..\..\Example\").FullName, ServerPath = AutoCSer.Web.Config.Deploy.ServerPath + @"Example\", FileSearchPatterns = new string[] { "*.cs", "*.html", "*.ts", "*.js", "*.css", "*.json" }, }, new AutoCSer.Deploy.ClientTask { Type = AutoCSer.Deploy.TaskType.File, ClientPath = new DirectoryInfo(@"..\..\..\..\TestCase\").FullName, ServerPath = AutoCSer.Web.Config.Deploy.ServerPath + @"TestCase\", FileSearchPatterns = new string[] { "*.cs", "*.html", "*.ts", "*.js" }, } }; AutoCSer.Deploy.ClientDeploy[] deploys = new AutoCSer.Deploy.ClientDeploy[] { new AutoCSer.Deploy.ClientDeploy { Name = "HTML", ServerName = AutoCSer.Deploy.Server.ServerName, Tasks = htmlTasks }, new AutoCSer.Deploy.ClientDeploy { Name = "Web", ServerName = AutoCSer.Deploy.Server.ServerName, Tasks = webTasks }, new AutoCSer.Deploy.ClientDeploy { Name = "Web/Http", ServerName = AutoCSer.Deploy.Server.ServerName, Tasks = httpTasks }, new AutoCSer.Deploy.ClientDeploy { Name = "Example", ServerName = AutoCSer.Deploy.Server.ServerName, Tasks = exampleTasks } }; AutoCSer.Deploy.ClientConfig config = new Deploy.ClientConfig { //RunFilePaths = new string[] { webReleaseDirectory.FullName }, ServerAttributes = new KeyValue <string, Net.TcpInternalServer.ServerAttribute>[] { new KeyValue <string, Net.TcpInternalServer.ServerAttribute>(AutoCSer.Deploy.Server.ServerName, serverAttribute) }, Deploys = deploys }; AutoCSer.Deploy.Client client = new AutoCSer.Deploy.Client(config, serverName => Console.WriteLine(serverName + " Ready.")); do { int index = 0; foreach (AutoCSer.Deploy.ClientDeploy deployInfo in deploys) { Console.ForegroundColor = (index & 1) == 0 ? ConsoleColor.Red : ConsoleColor.White; Console.WriteLine((index++).toString() + " -> " + toString(deployInfo)); } Console.ForegroundColor = (index & 1) == 0 ? ConsoleColor.Red : ConsoleColor.White; Console.WriteLine((index++).toString() + " -> create Open Example"); Console.ForegroundColor = (index & 1) == 0 ? ConsoleColor.Red : ConsoleColor.White; Console.WriteLine((index++).toString() + " -> create AutoCSer.Example.zip"); Console.ResetColor(); Console.WriteLine("press quit to exit."); string command = Console.ReadLine(); if (command == "quit") { return; } if (int.TryParse(command, out index)) { if ((uint)index < (uint)deploys.Length) { try { Console.WriteLine("正在启动部署 " + toString(deploys[index])); AutoCSer.Deploy.DeployResult result = client.Deploy(index); if (result.State == AutoCSer.Deploy.DeployState.Success) { Console.WriteLine("部署启动完毕 " + toString(deploys[index]) + " => " + result.Index.toString()); } else { Console.WriteLine("部署启动失败 [" + result.State.ToString() + "] " + toString(deploys[index])); } } catch (Exception error) { Console.WriteLine(error.ToString()); } } else if (index == deploys.Length) { openDirectory(@"..\..\..\..\TestCase\TcpServerPerformance\bin\Release\"); openDirectory(@"..\..\..\..\TestCase\WebPerformance\bin\Release\"); openProcess(@"..\..\..\..\Example\BinarySerialize\bin\Release\AutoCSer.Example.BinarySerialize.exe"); openProcess(@"..\..\..\..\Example\Json\bin\Release\AutoCSer.Example.Json.exe"); openProcess(@"..\..\..\..\Example\Xml\bin\Release\AutoCSer.Example.Xml.exe"); openProcess(@"..\..\..\..\Example\TcpInterfaceOpenServer\bin\Release\AutoCSer.Example.TcpInterfaceOpenServer.exe"); openProcess(@"..\..\..\..\Example\TcpInterfaceServer\bin\Release\AutoCSer.Example.TcpInterfaceServer.exe"); openProcess(@"..\..\..\..\Example\TcpInternalServer\bin\Release\AutoCSer.Example.TcpInternalServer.exe"); openProcess(@"..\..\..\..\Example\TcpOpenServer\bin\Release\AutoCSer.Example.TcpOpenServer.exe"); openProcess(@"..\..\..\..\Example\TcpStaticServer\bin\Release\AutoCSer.Example.TcpStaticServer.exe"); openProcess(@"..\..\..\..\Example\TcpRegisterServer\bin\Release\AutoCSer.Example.TcpRegisterServer.exe"); openProcess(@"..\..\..\..\Example\WebView\bin\Release\AutoCSer.Example.WebView.exe"); openProcess(@"..\..\..\..\TestCase\TestCase\bin\Release\AutoCSer.TestCase.exe"); //openProcess(@"..\..\..\..\TestCase\TcpServerPerformance\bin\Release\AutoCSer.TestCase.TcpInternalServerPerformance.Emit.exe"); //openProcess(@"..\..\..\..\TestCase\TcpServerPerformance\bin\Release\AutoCSer.TestCase.TcpInternalServerPerformance.exe"); //openProcess(@"..\..\..\..\TestCase\TcpServerPerformance\bin\Release\AutoCSer.TestCase.TcpOpenServerPerformance.Emit.exe"); //openProcess(@"..\..\..\..\TestCase\TcpServerPerformance\bin\Release\AutoCSer.TestCase.TcpOpenServerPerformance.exe"); //openProcess(@"..\..\..\..\TestCase\WebPerformance\bin\Release\AutoCSer.TestCase.HttpFilePerformance.exe"); //openProcess(@"..\..\..\..\TestCase\WebPerformance\bin\Release\AutoCSer.TestCase.WebPerformance.exe"); } else if (index == deploys.Length + 1) { openProcess(@"..\..\..\..\Web\ExamplePack\bin\Release\AutoCSer.Web.ExamplePack.exe"); } else { index = -1; } } else { index = -1; } if (index == -1) { Console.WriteLine("Error Command"); } Console.WriteLine(); }while (true); } } }