/// <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);
        }
예제 #2
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[] { config };

            IEnumerable<WorkItemFactoryInfo> workItemFactories;

            using (var factoryInfoLoader = GetWorkItemFactoryInfoLoader(configSource, LogFactory))
            {
                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);
                    section.CurrentConfiguration.Save(ConfigurationSaveMode.Minimal);
                }
            }

            return server;
        }