/// <summary>
        /// Creates the bootstrap.
        /// </summary>
        /// <param name="config">The config.</param>
        /// <returns></returns>
        public static IBootstrap CreateBootstrap(SocketBase.Config.IConfigurationSource config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            IBootstrap bootstrap;

            if (config.Isolation == IsolationMode.AppDomain)
            {
                bootstrap = new AppDomainBootstrap(config);
            }
            else if (config.Isolation == IsolationMode.Process)
            {
                bootstrap = new ProcessBootstrap(config);
            }
            else
            {
                bootstrap = new DefaultBootstrap(config);
            }


#if !NETSTANDARD2_0
            var section = config as ConfigurationSection;

            if (section != null)
            {
                ConfigurationWatcher.Watch(section, bootstrap);
            }
#endif

            return(bootstrap);
        }
예제 #2
0
        void IDynamicBootstrap.Remove(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            var server = m_AppServers.FirstOrDefault(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

            if (server == null)
            {
                throw new Exception("The server is not found.");
            }

            if (server.State != ServerState.NotStarted)
            {
                throw new Exception("The server is running now, you cannot remove it. Please stop it at first.");
            }

            m_AppServers.Remove(server);

            ResetPerfMoniter();

            var section = m_Config as SocketServiceConfig;

            if (section != null) //file configuration
            {
                section.Servers.Remove(name);
                ConfigurationWatcher.Pause();
                section.GetCurrentConfiguration().Save(ConfigurationSaveMode.Minimal);
                ConfigurationWatcher.Resume();
            }
        }
예제 #3
0
        IWorkItem AddNewServer(IServerConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (string.IsNullOrEmpty(config.Name))
            {
                throw new ArgumentException("The new server's name cannot be empty.", "config");
            }

            if (!m_Initialized)
            {
                throw new Exception("The bootstrap must be initialized already!");
            }

            if (m_AppServers.Any(s => config.Name.Equals(s.Name, StringComparison.OrdinalIgnoreCase)))
            {
                m_GlobalLog.ErrorFormat("The new server's name '{0}' has been taken by another server.", config.Name);
                return(null);
            }

            var configSource = new ConfigurationSource(m_Config);

            configSource.Servers = new IServerConfig[] { new ServerConfig(config) };

            IEnumerable <WorkItemFactoryInfo> workItemFactories;

            using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(configSource, null))
            {
                try
                {
                    workItemFactories = factoryInfoLoader.LoadResult((c) => c);
                }
                catch (Exception e)
                {
                    if (m_GlobalLog.IsErrorEnabled)
                    {
                        m_GlobalLog.Error(e);
                    }

                    return(null);
                }
            }

            var server = InitializeAndSetupWorkItem(workItemFactories.FirstOrDefault());

            if (server != null)
            {
                m_AppServers.Add(server);

                if (!m_Config.DisablePerformanceDataCollector)
                {
                    ResetPerfMoniter();
                }

                var section = m_Config as SocketServiceConfig;

                if (section != null) //file configuration
                {
                    var serverConfig = new Server();
                    serverConfig.LoadFrom(config);
                    section.Servers.AddNew(serverConfig);
                    ConfigurationWatcher.Pause();
                    section.GetCurrentConfiguration().Save(ConfigurationSaveMode.Minimal);
                    ConfigurationWatcher.Resume();
                }
            }

            return(server);
        }