public ICollection<IPointToLaceProvider> GetResponses(ICollection<IPointToLaceRequest> request) { _buildSourceChain = new CreateSourceChain(); _bootstrap = new Initialize(new Collection<IPointToLaceProvider>(), request, _bus, _buildSourceChain); _bootstrap.Execute(ChainType.All); return _bootstrap.DataProviderResponses ?? EmptyResponse; }
/// <summary> /// Setups the specified root config. /// </summary> /// <param name="bootstrap">The bootstrap.</param> /// <param name="config">The socket server instance config.</param> /// <param name="factories">The factories.</param> /// <returns></returns> public bool Setup(IBootstrap bootstrap, IServerConfig config, ProviderFactoryInfo[] factories) { m_Bootstrap = bootstrap; m_ServerConfig = config; m_Factories = factories; return true; }
public IsolationBootstrap(IConfigSource configSource) : base(GetSerializableConfigSource(configSource)) // make the configuration source serializable { HandleConfigSource(configSource); m_RemoteBootstrapWrap = new RemoteBootstrapProxy(this); m_RecycleTriggers = AppDomain.CurrentDomain.GetCurrentAppDomainExportProvider().GetExports<IRecycleTrigger, IProviderMetadata>(); }
private ICollection<IPointToLaceProvider> Execute(ICollection<IPointToLaceRequest> request, ChainType chain) { try { Init(request.First().Request.RequestId); _logCommand.LogBegin(request); _dataProviderChain = new CreateSourceChain(); _logCommand.LogEntryPointRequest(request, DataProviderNoRecordState.Billable); _bootstrap = new Initialize(new Collection<IPointToLaceProvider>(), request, _bus, _dataProviderChain); _bootstrap.Execute(chain); LogResponse(request); CreateTransaction(request, _bootstrap.DataProviderResponses.State()); _logCommand.LogEnd(_bootstrap.DataProviderResponses ?? EmptyResponse); return _bootstrap.DataProviderResponses ?? EmptyResponse; } catch (Exception ex) { _logCommand.LogFault(ex.Message, request); _logCommand.LogEnd(request); Log.ErrorFormat("Error occurred receiving request {0}", ex, request.ObjectToJson()); LogResponse(request); CreateTransaction(request, DataProviderResponseState.TechnicalError); return EmptyResponse; } }
public virtual bool Setup(IBootstrap bootstrap, IServerConfig config) { Bootstrap = bootstrap; var loggerProvider = bootstrap as ILoggerProvider; if (loggerProvider != null) Logger = loggerProvider.Logger; State = ServerState.Initializing; Config = config; Name = config.Name; State = ServerState.NotStarted; AppWorkingDir = config.Options.Get("appWorkingDir") ?? GetAppWorkingDir(Name); if (!Directory.Exists(AppWorkingDir)) Directory.CreateDirectory(AppWorkingDir); var appConfigFilePath = GetAppConfigFile(); // use the application's own config file if it has //AppRoot\AppName\App.config if (!string.IsNullOrEmpty(appConfigFilePath)) StartupConfigFile = appConfigFilePath; m_NotStartedStatus = new Lazy<StatusInfoCollection>(() => { var status = new StatusInfoCollection(m_Metadata.Name); status[StatusInfoKeys.IsRunning] = false; return status; }); return true; }
public void Setup() { m_Bootstrap = BootstrapFactory.CreateBootstrapFromConfigFile("SuperSocket.config"); Assert.IsTrue(m_Bootstrap.Initialize()); m_Port = ((IAppServer) m_Bootstrap.AppServers.FirstOrDefault()).Config.Port; Assert.AreEqual(StartResult.Success, m_Bootstrap.Start()); }
protected IConfigurationSource CreateBootstrap(string configFile) { IBootstrap newBootstrap; var configSrc = CreateBootstrap(configFile, out newBootstrap); m_BootStrap = newBootstrap; return configSrc; }
public void ClearBootstrap() { if(m_BootStrap != null) { m_BootStrap.Stop(); m_BootStrap = null; } }
public when_initializing_lace_handlers_for_ivid_request() { _command = BusFactory.WorkflowBus(); _request = new LicensePlateRequestBuilder().ForIvid(); _buildSourceChain = new CreateSourceChain(); //_buildSourceChain = new CreateSourceChain(_request.GetFromRequest<IPointToLaceRequest>().Package); //_buildSourceChain.Build(); _initialize = new Initialize(new Collection<IPointToLaceProvider>(), _request, _command, _buildSourceChain); }
static bool ListCommand(IBootstrap bootstrap, string[] arguments) { foreach (var s in bootstrap.AppServers) { Console.WriteLine("{0} - {1}", s.Name, s.State); } return false; }
protected override void OnBootstrapCleared() { if (m_ActiveServerBootstrap != null) { m_ActiveServerBootstrap.Stop(); m_ActiveServerBootstrap = null; AppDomain.CurrentDomain.SetData("Bootstrap", null); } }
public ICollection<IPointToLaceProvider> GetResponsesForCarId(ICollection<IPointToLaceRequest> request) { _buildSourceChain = new FakeSourceChain(); if (_checkForDuplicateRequests.IsRequestDuplicated(request.First())) return null; _bootstrap = new Initialize(new Collection<IPointToLaceProvider>(), request, _bus, _buildSourceChain); _bootstrap.Execute(ChainType.CarId); return _bootstrap.DataProviderResponses; }
public void ClearBootstrap() { if (m_BootStrap != null) { m_BootStrap.Stop(); (m_BootStrap as IDisposable).Dispose(); m_BootStrap = null; OnBootstrapCleared(); GC.Collect(); GC.WaitForFullGCComplete(); } }
protected IConfigurationSource CreateBootstrap(string configFile, out IBootstrap newBootstrap) { var fileMap = new ExeConfigurationFileMap(); var filePath = Path.Combine(@"Config", configFile); fileMap.ExeConfigFilename = filePath; var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var configSource = config.GetSection("superSocket") as IConfigurationSource; newBootstrap = BootstrapFactory.CreateBootstrap(configSource); return configSource; }
public override bool Setup(IBootstrap bootstrap, IServerConfig config) { if (!base.Setup(bootstrap, config)) return false; var metadata = GetMetadata() as ExternalProcessAppServerMetadata; var appFile = metadata.AppFile; if(string.IsNullOrEmpty(appFile)) { OnExceptionThrown(new ArgumentNullException("appFile")); return false; } var workDir = AppWorkingDir; if (!string.IsNullOrEmpty(metadata.AppDir)) appFile = Path.Combine(metadata.AppDir, appFile); if(!Path.IsPathRooted(appFile)) { appFile = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, appFile)); } if (!File.Exists(appFile)) { OnExceptionThrown(new FileNotFoundException("The app file was not found.", appFile)); return false; } workDir = Path.GetDirectoryName(appFile); m_ExternalAppDir = workDir; var args = metadata.AppArgs; var startInfo = new ProcessStartInfo(appFile, args); startInfo.WorkingDirectory = workDir; startInfo.CreateNoWindow = true; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.UseShellExecute = false; startInfo.RedirectStandardError = true; startInfo.RedirectStandardInput = true; m_StartInfo = startInfo; m_ExitCommand = config.Options.Get("exitCommand"); m_Status = new StatusInfoCollection { Name = config.Name }; return true; }
public RemoteBootstrapProxy() { m_Bootstrap = (IBootstrap)AppDomain.CurrentDomain.GetData("Bootstrap"); foreach (var s in m_Bootstrap.AppServers) { if (s is MarshalByRefObject) m_Servers.Add(s); else m_Servers.Add(new ServerProxy(s)); } }
public bool Setup(IBootstrap bootstrap, IServerConfig config) { Config = config; foreach (var item in Items) { if (!item.Setup(bootstrap, config)) return false; } return true; }
public NotifyWinService() { //File.AppendAllText(@"D:\345.txt", "aa"); InitializeComponent(); InitConfig(); logger.Debug("OO"); m_Bootstrap = BootstrapFactory.CreateBootstrap(); serviceHelper = new WcfServiceHelper(); m_Dispacher = new System.Timers.Timer(); m_Dispacher.Interval = 500; m_Dispacher.Elapsed += M_Dispacher_Elapsed; }
public RemoteBootstrapProxy(IBootstrap innerBootstrap) { m_Bootstrap = innerBootstrap; m_ManagedApps = new List<IManagedApp>(); foreach (var s in m_Bootstrap.AppServers) { if (s is MarshalByRefObject) m_ManagedApps.Add(s); else m_ManagedApps.Add(new ServerProxy(s)); } }
public static void Start() { bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize()) { Console.WriteLine("Failed to initialize!"); return; } ouSrv = (OpcUserServer)bootstrap.AppServers.First(); ouSrv.NewSessionConnected += new SessionHandler<OpcUserSession>(SessionConnected); ouSrv.SessionClosed += new SessionHandler<OpcUserSession, CloseReason>(SessionClosed); StartResult result = bootstrap.Start(); }
public override bool OnStart() { Trace.TraceInformation("WorkerRole1 is starting"); NewRelic.Api.Agent.NewRelic.SetTransactionName("Worker", "OnStart"); var watch = Stopwatch.StartNew(); // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 200; // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. m_Bootstrap = BootstrapFactory.CreateBootstrap(); var endpoints = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints.ToDictionary (p => p.Key, p => p.Value.IPEndpoint); if (!m_Bootstrap.Initialize(endpoints)) { Trace.WriteLine("Failed to initialize SuperSocket!", "Error"); NewRelic.Api.Agent.NewRelic.RecordResponseTimeMetric("OnStart", watch.ElapsedMilliseconds); return false; } var result = m_Bootstrap.Start(); switch (result) { case (StartResult.None): Trace.WriteLine("No server is configured, please check you configuration!"); NewRelic.Api.Agent.NewRelic.RecordResponseTimeMetric("OnStart", watch.ElapsedMilliseconds); return false; case (StartResult.Success): Trace.WriteLine("The server has been started!"); break; case (StartResult.Failed): Trace.WriteLine("Failed to start SuperSocket server! Please check error log for more information!"); NewRelic.Api.Agent.NewRelic.RecordResponseTimeMetric("OnStart", watch.ElapsedMilliseconds); return false; case (StartResult.PartialSuccess): Trace.WriteLine("Some server instances were started successfully, but the others failed to start! Please check error log for more information!"); break; } Trace.TraceInformation("WorkerRole1 has started"); NewRelic.Api.Agent.NewRelic.RecordResponseTimeMetric("OnStart", watch.ElapsedMilliseconds); return base.OnStart(); }
public void StartSuperWebSocketByProgramming() { var socketServer = new WebSocketServer(); socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(socketServer_NewMessageReceived); socketServer.NewSessionConnected += socketServer_NewSessionConnected; socketServer.SessionClosed += socketServer_SessionClosed; socketServer.Setup(port); m_Bootstrap = new DefaultBootstrap(new RootConfig(), new IWorkItem[] { socketServer }); m_Bootstrap.Start(); }
public virtual void Setup() { m_Bootstrap = new DefaultBootstrap(); m_WebSocketServer = new WebSocketServer(new BasicSubProtocol("Basic", new List<Assembly> { this.GetType().Assembly })); m_WebSocketServer.NewDataReceived += new SessionEventHandler<WebSocketSession, byte[]>(m_WebSocketServer_NewDataReceived); m_Bootstrap.Initialize(new RootConfig { DisablePerformanceDataCollector = true }, new IAppServer[] { m_WebSocketServer }, new IServerConfig[] { new ServerConfig { Port = 2012, Ip = "Any", MaxConnectionNumber = 100, Mode = SocketMode.Tcp, Name = "SuperWebSocket Server" }}, new ConsoleLogFactory()); }
public void Setup() { m_Bootstrap = new DefaultBootstrap(); m_Config = new ServerConfig { Port = 555, Ip = "Any", MaxConnectionNumber = 10, Mode = SocketMode.Tcp, Name = "GPSServer" }; m_Server = new GPSServer(); m_Bootstrap.Initialize(new RootConfig(), new IAppServer[] { m_Server }, new IServerConfig[] { m_Config }, new ConsoleLogFactory()); }
void StartSuperWebSocketByConfig() { m_Bootstrap = BootstrapFactory.CreateBootstrap(); if (!m_Bootstrap.Initialize()) return; var socketServer = m_Bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals("SuperWebSocket")) as WebSocketServer; socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(socketServer_NewMessageReceived); socketServer.NewSessionConnected += socketServer_NewSessionConnected; socketServer.SessionClosed += socketServer_SessionClosed; m_WebSocketServer = socketServer; m_Bootstrap.Start(); }
public virtual bool Setup(IBootstrap bootstrap, IServerConfig config, ProviderFactoryInfo[] factories) { State = ServerState.Initializing; Name = config.Name; Bootstrap = bootstrap; ServerConfig = config; Factories = factories; if (!bootstrap.Config.DisablePerformanceDataCollector) { if (!LoadServerStatusMetadata()) { return(false); } } State = ServerState.NotStarted; return(true); }
/// <summary> /// Initializes a new instance of the <see cref="AppDomainBootstrap"/> class. /// </summary> public AppDomainBootstrap(IConfigurationSource config) { string startupConfigFile = string.Empty; if (config == null) throw new ArgumentNullException("config"); var configSectionSource = config as ConfigurationSection; if (configSectionSource != null) startupConfigFile = configSectionSource.GetConfigSource(); //Keep serializable version of configuration if(!config.GetType().IsSerializable) config = new ConfigurationSource(config); //Still use raw configuration type to bootstrap m_InnerBootstrap = new DefaultBootstrapAppDomainWrap(this, config, startupConfigFile); }
public virtual void Setup() { m_Bootstrap = new DefaultBootstrap(); m_WebSocketServer = new WebSocketServer(new BasicSubProtocol("Basic", new List <Assembly> { this.GetType().Assembly })); m_WebSocketServer.NewDataReceived += new SessionEventHandler <WebSocketSession, byte[]>(m_WebSocketServer_NewDataReceived); m_Bootstrap.Initialize(new RootConfig { DisablePerformanceDataCollector = true }, new IAppServer[] { m_WebSocketServer }, new IServerConfig[] { new ServerConfig { Port = 2012, Ip = "Any", MaxConnectionNumber = 100, Mode = SocketMode.Tcp, Name = "SuperWebSocket Server" } }, new ConsoleLogFactory()); }
private static void OnConfigFileUpdated(string filePath, string sectionName, IBootstrap bootstrap) { var fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = filePath; System.Configuration.Configuration config; try { config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); } catch (Exception e) { var loggerProvider = bootstrap as ILoggerProvider; if (loggerProvider != null) { var logger = loggerProvider.Logger; if (logger != null) logger.Error("Configuraton loading error.", e); } return; } var configSource = config.GetSection(sectionName) as IConfigurationSource; if (configSource == null) return; foreach (var serverConfig in configSource.Servers) { var server = bootstrap.AppServers.FirstOrDefault(x => x.Name.Equals(serverConfig.Name, StringComparison.OrdinalIgnoreCase)); if (server == null) continue; server.ReportPotentialConfigChange(serverConfig); } }
public void TestActiveConnect() { StartBootstrap(DefaultServerConfig); IBootstrap activeServerBootstrap; var activeTargetServerConfig = CreateBootstrap("ActiveConnectServer.config", out activeServerBootstrap); Assert.IsTrue(activeServerBootstrap.Initialize()); var serverConfig = activeTargetServerConfig.Servers.FirstOrDefault(); var serverAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), serverConfig.Port); m_ActiveServerBootstrap = AppDomain.CurrentDomain.GetData("Bootstrap") as IBootstrap; Assert.AreEqual(StartResult.Success, m_ActiveServerBootstrap.Start()); var appServer = BootStrap.AppServers.FirstOrDefault() as TestServer; var task = appServer.ActiveConnectRemote(serverAddress); if (!task.Wait(5000)) { Assert.Fail("Active connect the server timeout"); } Assert.AreEqual(TaskStatus.RanToCompletion, task.Status); Assert.AreEqual(true, task.Result.Result); Assert.IsNotNull(task.Result.Session); Assert.AreEqual(1, m_ActiveServerBootstrap.AppServers.FirstOrDefault().SessionCount); var session = task.Result.Session as TestSession; var rd = new Random(); var a = rd.Next(1, 1000); var b = rd.Next(1, 1000); session.Send("ADDR " + a + " " + b); Thread.Sleep(500); Assert.AreEqual((a + b).ToString(), RESU.Result); }
public void CreateStartServer() { ActiveServerBootstrap = BootstrapFactory.CreateBootstrap(); if (!ActiveServerBootstrap.Initialize()) { Console.WriteLine(string.Format("서버 초기화 실패"), LOG_LEVEL.ERROR); return; } else { var refAppServer = ActiveServerBootstrap.AppServers.FirstOrDefault() as MainServer; MainLogger = refAppServer.Logger; WriteLog("서버 초기화 성공", LOG_LEVEL.INFO); } var result = ActiveServerBootstrap.Start(); if (result != StartResult.Success) { MainServer.WriteLog(string.Format("서버 시작 실패"), LOG_LEVEL.ERROR); return; } else { WriteLog("서버 시작 성공", LOG_LEVEL.INFO); } WriteLog(string.Format("서버 생성 및 시작 성공"), LOG_LEVEL.INFO); ChatServerEnvironment.Setting(); StartRemoteConnect(); var appServer = ActiveServerBootstrap.AppServers.FirstOrDefault() as MainServer; InnerMessageHostProgram.ServerStart(ChatServerEnvironment.ChatServerUniqueID, appServer.Config.Port); ClientSession.CreateIndexPool(appServer.Config.MaxConnectionNumber); }
static bool StartServer() { m_Bootstrap = BootstrapFactory.CreateBootstrap(); if (!m_Bootstrap.Initialize()) { Console.WriteLine("游戏服务器初始化失败!"); return(false); } if (m_Bootstrap.Start() != StartResult.Success) { Console.WriteLine("游戏服务器启动失败!"); return(false); } else { Console.WriteLine("游戏服务器启动成功!"); return(true); } }
static void Main(string[] args) { IBootstrap bootstrap = BootstrapFactory.CreateBootstrapFromConfigFile("SuperSocket.config"); if (!bootstrap.Initialize()) { Console.WriteLine("Failed to initialize!"); Console.ReadKey(); return; } var result = bootstrap.Start(); //Console.WriteLine("Start result: {0}!", result); if (result == StartResult.Failed) { Console.WriteLine("Failed to start!"); Console.ReadKey(); return; } //foreach (var s in bootstrap.AppServers) //{ // Console.WriteLine($"{s.Config.Ip}:{s.Config.Port}"); //} //Console.WriteLine("Press key 'q' to stop it!"); while (Console.ReadKey().KeyChar != 'q') { Console.WriteLine(); continue; } Console.WriteLine(); //Stop the appServer bootstrap.Stop(); Console.WriteLine("The server was stopped!"); }
private static void ReadConsoleCommand(IBootstrap bootstrap) { string str = Console.ReadLine(); if (string.IsNullOrEmpty(str)) { Program.ReadConsoleCommand(bootstrap); } else { if ("quit".Equals(str, StringComparison.OrdinalIgnoreCase)) { return; } string[] strArray = str.Split(new char[1] { ' ' }); ControlCommand controlCommand; if (!Program.m_CommandHandlers.TryGetValue(strArray[0], out controlCommand)) { Console.WriteLine("Unknown command"); Program.ReadConsoleCommand(bootstrap); } else { try { if (controlCommand.Handler(bootstrap, strArray)) { Console.WriteLine("Ok"); } } catch (Exception ex) { Console.WriteLine("Failed. " + ex.Message + Environment.NewLine + ex.StackTrace); } Program.ReadConsoleCommand(bootstrap); } } }
public virtual bool Setup(IBootstrap bootstrap, IServerConfig config) { Bootstrap = bootstrap; var loggerProvider = bootstrap as ILoggerProvider; if (loggerProvider != null) { Logger = loggerProvider.Logger; } State = ServerState.Initializing; Config = config; Name = config.Name; State = ServerState.NotStarted; AppWorkingDir = GetAppWorkingDir(Name); if (!Directory.Exists(AppWorkingDir)) { Directory.CreateDirectory(AppWorkingDir); } var appConfigFilePath = GetAppConfigFile(); // use the application's own config file if it has //AppRoot\AppName\App.config if (!string.IsNullOrEmpty(appConfigFilePath)) { StartupConfigFile = appConfigFilePath; } m_NotStartedStatus = new Lazy <StatusInfoCollection>(() => { var status = new StatusInfoCollection(m_Metadata.Name); status[StatusInfoKeys.IsRunning] = false; return(status); }); return(true); }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 100; // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. var serverConfig = ConfigurationManager.GetSection("socketServer") as SocketServiceConfig; m_Bootstrap = BootstrapFactory.CreateBootstrap(serverConfig); if (!m_Bootstrap.Initialize(ResolveServerConfig)) { Trace.WriteLine("Failed to initialize SuperSocket!", "Error"); return false; } var result = m_Bootstrap.Start(); switch (result) { case (StartResult.None): Trace.WriteLine("No server is configured, please check you configuration!"); return false; case (StartResult.Success): Trace.WriteLine("The server has been started!"); break; case (StartResult.Failed): Trace.WriteLine("Failed to start SuperSocket server! Please check error log for more information!"); return false; case (StartResult.PartialSuccess): Trace.WriteLine("Some server instances were started successfully, but the others failed to start! Please check error log for more information!"); break; } return base.OnStart(); }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 100; // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. m_Bootstrap = new DefaultBootstrap(); var serverConfig = ConfigurationManager.GetSection("socketServer") as SocketServiceConfig; if (!m_Bootstrap.Initialize(serverConfig, ResolveServerConfig)) { Trace.WriteLine("Failed to initialize SuperSocket!", "Error"); return(false); } var result = m_Bootstrap.Start(); switch (result) { case (StartResult.None): Trace.WriteLine("No server is configured, please check you configuration!"); return(false); case (StartResult.Success): Trace.WriteLine("The server has been started!"); break; case (StartResult.Failed): Trace.WriteLine("Failed to start SuperSocket server! Please check error log for more information!"); return(false); case (StartResult.PartialSuccess): Trace.WriteLine("Some server instances were started successfully, but the others failed to start! Please check error log for more information!"); break; } return(base.OnStart()); }
public virtual void Setup() { var rootConfig = new RootConfig { DisablePerformanceDataCollector = true }; m_WebSocketServer = new WebSocketServer(); m_WebSocketServer.NewMessageReceived += new SessionEventHandler<WebSocketSession, string>(m_WebSocketServer_NewMessageReceived); m_WebSocketServer.NewSessionConnected += m_WebSocketServer_NewSessionConnected; m_WebSocketServer.SessionClosed += m_WebSocketServer_SessionClosed; m_WebSocketServer.Setup(rootConfig, new ServerConfig { Port = 2012, Ip = "Any", MaxConnectionNumber = 100, Mode = SocketMode.Tcp, Name = "SuperWebSocket Server" }); m_Bootstrap = new DefaultBootstrap(rootConfig, new IWorkItem[] { m_WebSocketServer }, new ConsoleLogFactory()); }
public static void SetAppServer(string appServerName) { if (apps.ContainsKey(appServerName)) { return; } IBootstrap m_Bootstrap = BootstrapFactory.CreateBootstrap(); if (!m_Bootstrap.Initialize()) { return; } TripAppServer socketServer = m_Bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals(appServerName)) as TripAppServer; socketServer.RegisterEvents(); m_Bootstrap.Start(); apps.Add(appServerName, socketServer); }
public static void Startup() { if (bootstrap != null) { return; } bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize()) { typeof(SuperSocketBootstrap).Error(MethodBase.GetCurrentMethod().Name, new Exception("初始化失败!")); return; } var result = bootstrap.Start(); typeof(SuperSocketBootstrap).Info(MethodBase.GetCurrentMethod().Name, $"服务正在启动: {result}!"); if (result == StartResult.Failed) { typeof(SuperSocketBootstrap).Error(MethodBase.GetCurrentMethod().Name, new Exception("服务启动失败!")); return; } }
void StartSuperWebSocketByConfig() { m_Bootstrap = BootstrapFactory.CreateBootstrap(); if (!m_Bootstrap.Initialize()) { return; } var socketServer = m_Bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals("SuperWebSocket")) as WebSocketServer; socketServer.NewMessageReceived += new SessionHandler <WebSocketSession, string>(socketServer_NewMessageReceived); socketServer.NewDataReceived += new SessionHandler <WebSocketSession, byte[]>(socketServer_NewBufferReceived); socketServer.NewSessionConnected += socketServer_NewSessionConnected; socketServer.SessionClosed += socketServer_SessionClosed; //socketServer.Session += socketServer_SessionClosed; m_WebSocketServer = socketServer; m_Bootstrap.Start(); }
/// <summary>运行socket</summary> public void RunBootstrap() { bootstrap = BootstrapFactory.CreateBootstrap(); var msg = string.Empty; if (!bootstrap.Initialize()) { msg = "无法初始化SuperSocket ServiceEngine!请检查错误日志的详细信息!"; DisplayGlobal.log.Write(msg); return; } var result = bootstrap.Start(); foreach (var server in bootstrap.AppServers) { msg = string.Format(server.State == ServerState.Running ? "- {0} 已经启动" : "- {0} 启动失败", server.Name); } switch (result) { case (StartResult.None): msg = "无服务器配置,请检查你的配置!"; DisplayGlobal.log.Write(msg); return; case (StartResult.Success): { //日志记录 (new Share.Log()).WriteServerLog((int)LogType.Run); msg = "SuperSocket ServiceEngine已经启动!"; break; } case (StartResult.Failed): msg = "无法启动SuperSocket ServiceEngine!请检查错误日志的详细信息!"; DisplayGlobal.log.Write(msg); return; case (StartResult.PartialSuccess): msg = "一些服务器实例都成功启动,但其他人失败了!请检查错误日志的详细信息!"; break; } DisplayGlobal.log.Write(msg); }
static void ReadConsoleCommand(IBootstrap bootstrap) { var line = Console.ReadLine(); if (string.IsNullOrEmpty(line)) { ReadConsoleCommand(bootstrap); return; } if ("quit".Equals(line, StringComparison.OrdinalIgnoreCase)) { return; } var cmdArray = line.Split(' '); ControlCommand cmd; if (!m_CommandHandlers.TryGetValue(cmdArray[0], out cmd)) { Console.WriteLine("Unknown command"); ReadConsoleCommand(bootstrap); return; } try { if (cmd.Handler(bootstrap, cmdArray)) { Console.WriteLine("Ok"); } } catch (Exception e) { Console.WriteLine("Failed. " + e.Message + Environment.NewLine + e.StackTrace); } ReadConsoleCommand(bootstrap); }
static bool StartCommand(IBootstrap bootstrap, string[] arguments) { var name = arguments[1]; if (string.IsNullOrEmpty(name)) { Console.WriteLine("Server name is required!"); return(false); } var server = bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (server == null) { Console.WriteLine("The server was not found!"); return(false); } server.Start(); return(true); }
/// <summary> /// 停止服务命令 /// </summary> /// <param name="bootstrap"></param> /// <param name="arguments"></param> /// <returns></returns> static bool StopCommand(IBootstrap bootstrap, string[] arguments) { var name = arguments[1]; if (string.IsNullOrWhiteSpace(name)) { Console.WriteLine("服务名称为空"); return(false); } var server = bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (server == null) { Console.WriteLine("服务不存在"); return(false); } server.Stop(); return(true); }
public override bool OnStart() { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 100; // For information on handling configuration changes // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357. m_Bootstrap = BootstrapFactory.CreateBootstrap(); if (!m_Bootstrap.Initialize(RoleEnvironment.CurrentRoleInstance.InstanceEndpoints.ToDictionary(p => p.Key, p => p.Value.IPEndpoint))) { Trace.WriteLine("Failed to initialize SuperSocket!", "Error"); return(false); } var result = m_Bootstrap.Start(); switch (result) { case (StartResult.None): Trace.WriteLine("No server is configured, please check you configuration!"); return(false); case (StartResult.Success): Trace.WriteLine("The server has been started!"); break; case (StartResult.Failed): Trace.WriteLine("Failed to start SuperSocket server! Please check error log for more information!"); return(false); case (StartResult.PartialSuccess): Trace.WriteLine("Some server instances were started successfully, but the others failed to start! Please check error log for more information!"); break; } return(base.OnStart()); }
public override void ExecuteCommand(TCPSocketSession session, StringRequestInfo requestInfo) { IBootstrap bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize()) { //SetConsoleColor(ConsoleColor.Red); Console.WriteLine("初始化失败"); Console.ReadKey(); return; } Console.WriteLine("启动中..."); var result = bootstrap.Start(); Console.WriteLine("-------------------------------------------------------------------"); foreach (var server in bootstrap.AppServers) { server.Stop(); } } // end of start
/// <summary> /// Initializes a new instance of the <see cref="AppDomainBootstrap"/> class. /// </summary> /// <param name="config">The config.</param> /// <param name="serviceProvider">A container for service objects.</param> public AppDomainBootstrap(SocketBase.Config.IConfigurationSource config, IServiceProvider serviceProvider) { ServiceProvider = serviceProvider; string startupConfigFile = string.Empty; if (config == null) { throw new ArgumentNullException("config"); } #if !NETSTANDARD2_0 var configSectionSource = config as ConfigurationSection; if (configSectionSource != null) { startupConfigFile = configSectionSource.GetConfigSource(); } //Keep serializable version of configuration if (!config.GetType().IsSerializable) { config = new ConfigurationSource(config); } #else var configurationRoot = new ConfigurationBuilder() .AddInMemoryCollection() .SetBasePath(Directory.GetCurrentDirectory()) .AddXmlFile("App.config", optional: true, reloadOnChange: true) .Build(); config = new ConfigurationSource(new SocketServiceConfig(configurationRoot)); #endif //Still use raw configuration type to bootstrap m_InnerBootstrap = CreateBootstrapWrap(this, config, startupConfigFile); AppDomain.CurrentDomain.SetData("Bootstrap", this); }
private bool StartServer() { try { bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize()) { return(false); } var result = bootstrap.Start(); if (result == StartResult.Failed) { return(false); } } catch (Exception e) { MessageBox.Show("采集服务启动失败"); return(false); } ds = new DeviceService(bootstrap); return(true); }
private void restartSuperSocketServer() { defaultBootstrap?.Stop(); defaultBootstrap = null; var bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize()) { NoticeAdmin($"{nameof(restartSuperSocketServer) } :Supersocket initlialize failed!"); } RemoteSuperSocketPort = bootstrap.AppServers.ElementAtOrDefault(0).Config.Port; var result = bootstrap.Start(); Console.WriteLine("Start result: {0}!", result); if (result == StartResult.Failed) { NoticeAdmin($"{nameof(restartSuperSocketServer) } :Supersocket start failed! result:{result.ToString()}"); } if (result == StartResult.Success) { defaultBootstrap = bootstrap; } }
private static void Main(string[] args) { Console.WriteLine("Press any key to start the server!"); Console.ReadKey(); Console.WriteLine(); IBootstrap bootstrap = BootstrapFactory.CreateBootstrap(); if (!bootstrap.Initialize()) { Console.WriteLine("Failed to initialize!"); Console.ReadKey(); } else { StartResult result = bootstrap.Start(); Console.WriteLine("Start result: {0}!", result); if (result == StartResult.Failed) { Console.WriteLine("Failed to start!"); Console.ReadKey(); } else { Console.WriteLine("Press key 'q' to stop it!"); while (Console.ReadKey().KeyChar != 'q') { Console.WriteLine(); } Console.WriteLine(); bootstrap.Stop(); foreach (var item in bootstrap.AppServers) { } Console.WriteLine("The server was stopped!"); } } }
private static bool StartCommand(IBootstrap bootstrap, string[] arguments) { string name = arguments[1]; if (string.IsNullOrEmpty(name)) { Console.WriteLine("Server name is required!"); return(false); } else { IWorkItem workItem = Enumerable.FirstOrDefault <IWorkItem>(bootstrap.AppServers, (Func <IWorkItem, bool>)(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase))); if (workItem == null) { Console.WriteLine("The server was not found!"); return(false); } else { workItem.Start(); return(true); } } }
public async void TryConnect(IBootstrap activeServerBootstrap) { IsTryConnecting = true; var appServer = activeServerBootstrap.AppServers.FirstOrDefault() as MainServer; var activeConnector = appServer as SuperSocket.SocketBase.IActiveConnector; try { var task = await activeConnector.ActiveConnect(Address); if (task.Result) { Session = task.Session; } } catch { } finally { IsTryConnecting = false; } }
void StartSuperWebSocketByConfig() { m_Bootstrap = BootstrapFactory.CreateBootstrap(); if (!m_Bootstrap.Initialize()) { return; } var socketServer = m_Bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals("SuperWebSocket")) as WebSocketServer; var secureSocketServer = m_Bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals("SecureSuperWebSocket")) as WebSocketServer; Application["WebSocketPort"] = socketServer.Config.Port; Application["SecureWebSocketPort"] = secureSocketServer.Config.Port; socketServer.NewMessageReceived += new SessionHandler <WebSocketSession, string>(socketServer_NewMessageReceived); socketServer.NewSessionConnected += socketServer_NewSessionConnected; socketServer.SessionClosed += socketServer_SessionClosed; secureSocketServer.NewSessionConnected += secureSocketServer_NewSessionConnected; secureSocketServer.SessionClosed += secureSocketServer_SessionClosed; m_Bootstrap.Start(); }
private void startSuperSocketServer() { var bootstrap = BootstrapFactory.CreateBootstrap(); defaultBootstrap = bootstrap; if (!bootstrap.Initialize()) { Program.Exit("Supersocket initlialize failed!"); } var server = bootstrap.AppServers.ElementAt(0) as SocketServer; RemoteSuperSocketPort = server.Listeners[0].EndPoint.Port; var result = bootstrap.Start(); Console.WriteLine("Start result: {0}!", result); if (result == StartResult.Failed) { Program.Exit("Start Socket message service failed!"); } initClient(); }
public DefaultBootstrapAppDomainWrap(IBootstrap bootstrap, IConfigurationSource config, string startupConfigFile) : base(config, startupConfigFile) { m_Bootstrap = bootstrap; }
protected virtual IBootstrap CreateBootstrapWrap(IBootstrap bootstrap, IConfigurationSource config, string startupConfigFile) { return(new DefaultBootstrapAppDomainWrap(this, config, startupConfigFile)); }
/// <summary> /// Initializes a new instance of the <see cref="BootingEventArgs"/> class. /// </summary> /// <param name="bootstrap">The boot class that is booting.</param> /// <param name="application">The application instance.</param> public BootingEventArgs(IBootstrap bootstrap, IApplication application) : base(application) { IsSkip = false; this.bootstrap = bootstrap; }
public IotService() { InitializeComponent(); bootstrap = BootstrapFactory.CreateBootstrap(); }
/// <summary> /// 初始化 /// </summary> public void InitEasyClient() { //通过读取配置文件启动 _bootstrap = BootstrapFactory.CreateBootstrap(); bool isSucc = _bootstrap.Initialize(); if (isSucc) { var result = _bootstrap.Start(); foreach (var server in _bootstrap.AppServers) { switch (server.State) { case ServerState.Running: Console.WriteLine($"{server.Name} 运行中"); break; case ServerState.NotInitialized: break; case ServerState.Initializing: break; case ServerState.NotStarted: break; case ServerState.Starting: break; case ServerState.Stopping: break; default: Console.WriteLine($"{server.Name} 启动失败"); break; } } switch (result) { case StartResult.Failed: Console.WriteLine("无法启动服务,更多错误信息请查看日志"); break; case StartResult.None: Console.WriteLine("没有服务器配置,请检查你的配置!"); break; case StartResult.PartialSuccess: Console.WriteLine("一些服务启动成功,但是还有一些启动失败,更多错误信息请查看日志"); break; case StartResult.Success: break; default: throw new ArgumentOutOfRangeException(); } } else { Console.WriteLine("初始化失败!"); } }