コード例 #1
0
        public virtual void Initialize()
        {
            InstanceAsBase = this;
            Initializing   = true;

            Version = ((AssemblyInformationalVersionAttribute)System.Reflection.Assembly.GetExecutingAssembly()
                       .GetCustomAttributes <AssemblyInformationalVersionAttribute>().FirstOrDefault())
                      .InformationalVersion;

            /* Initialize Logger */
            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();
            logger = LogManager.GetCurrentClassLogger();

            if (!Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
                TaskScheduler.UnobservedTaskException      += OnUnobservedTaskException;
                Contract.ContractFailed += OnContractFailed;
            }
            else
            {
                logger.Warn("Exceptions not handled cause Debugger is attatched");
            }

            PreLoadReferences(Assembly.GetCallingAssembly());
            LoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToDictionary(entry => entry.GetName().Name);
            AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;

            if (Environment.GetCommandLineArgs().Contains("-config"))
            {
                UpdateConfigFiles();
            }

            ConsoleBase.DrawAsciiLogo();
            Console.WriteLine();

            InitializeGarbageCollector();

            logger.Info("Initializing Configuration...");
            /* Initialize Config File */
            Config = new XmlConfig(ConfigFilePath);
            Config.AddAssemblies(LoadedAssemblies.Values.ToArray());

            if (!File.Exists(ConfigFilePath))
            {
                Config.Create();
                logger.Info("Config file created");
            }
            else
            {
                Config.Load();
            }

            logger.Info("Initialize Task Pool");
            IOTaskPool = new BenchmarkedTaskPool(IOTaskInterval, "IO Task Pool");

            CommandManager = CommandManager.Instance;
            CommandManager.RegisterAll(Assembly.GetExecutingAssembly());

            logger.Info("Initializing Network Interfaces...");
            ClientManager = ClientManager.Instance;
            ClientManager.Initialize(CreateClient);

            if (Settings.InactivityDisconnectionTime.HasValue)
            {
                IOTaskPool.CallPeriodically(Settings.InactivityDisconnectionTime.Value / 4 * 1000, DisconnectAfkClient);
            }

            ClientManager.ClientConnected    += OnClientConnected;
            ClientManager.ClientDisconnected += OnClientDisconnected;

            logger.Info("Register Plugins...");
            // the plugins add them themself to the initializer
            InitializationManager = InitializationManager.Instance;
            InitializationManager.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());

            PluginManager                = PluginManager.Instance;
            PluginManager.PluginAdded   += OnPluginAdded;
            PluginManager.PluginRemoved += OnPluginRemoved;

            logger.Info("Loading Plugins...");
            PluginManager.Instance.LoadAllPlugins();

            if (IsExceptionLoggerEnabled)
            {
                ExceptionLogger         = new RavenClient(ExceptionLoggerDSN);
                ExceptionLogger.Release = Version;
#if DEBUG
                ExceptionLogger.Environment = "DEBUG";
#else
                ExceptionLogger.Environment = "RELEASE";
#endif
            }
        }
コード例 #2
0
        public virtual void Initialize()
        {
            ServerBase.InstanceAsBase = this;
            this.Initializing         = true;
            NLogHelper.DefineLogProfile(true, true);
            NLogHelper.EnableLogging();
            this.logger = LogManager.GetCurrentClassLogger();
            if (!Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.OnUnhandledException);
                TaskScheduler.UnobservedTaskException      += new EventHandler <UnobservedTaskExceptionEventArgs>(this.OnUnobservedTaskException);
                Contract.ContractFailed += new EventHandler <ContractFailedEventArgs>(this.OnContractFailed);
            }
            else
            {
                this.logger.Warn("Exceptions not handled cause Debugger is attatched");
            }
            ServerBase.PreLoadReferences(Assembly.GetCallingAssembly());
            this.LoadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToDictionary((Assembly entry) => entry.GetName().Name);
            AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(this.OnAssemblyLoad);
            if (Environment.GetCommandLineArgs().Contains("-config"))
            {
                this.UpdateConfigFiles();
            }
            ConsoleBase.DrawAsciiLogo();
            Console.WriteLine();
            ServerBase.InitializeGarbageCollector();
            this.logger.Info("Initializing Configuration...");
            this.Config = new XmlConfig(this.ConfigFilePath);
            this.Config.AddAssemblies(this.LoadedAssemblies.Values.ToArray <Assembly>());
            if (!File.Exists(this.ConfigFilePath))
            {
                this.Config.Create(false);
                this.logger.Info("Config file created");
            }
            else
            {
                this.Config.Load();
            }
            this.logger.Info("Initialize Task Pool");
            this.IOTaskPool     = new SelfRunningTaskPool(ServerBase.IOTaskInterval, "IO Task Pool");
            this.CommandManager = Singleton <CommandManager> .Instance;
            this.CommandManager.RegisterAll(Assembly.GetExecutingAssembly());
            this.logger.Info("Initializing Network Interfaces...");
            this.ClientManager = Singleton <ClientManager> .Instance;
            this.ClientManager.Initialize(new ClientManager.CreateClientHandler(this.CreateClient));
            if (Settings.InactivityDisconnectionTime.HasValue)
            {
                this.IOTaskPool.CallPeriodically(Settings.InactivityDisconnectionTime.Value / 4 * 1000, new Action(this.DisconnectAfkClient));
            }
            this.ClientManager.ClientConnected    += new Action <BaseClient>(this.OnClientConnected);
            this.ClientManager.ClientDisconnected += new Action <BaseClient>(this.OnClientDisconnected);
            this.logger.Info("Register Plugins...");
            this.InitializationManager = Singleton <InitializationManager> .Instance;
            this.InitializationManager.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies());
            this.PluginManager                = Singleton <PluginManager> .Instance;
            this.PluginManager.PluginAdded   += new PluginManager.PluginContextHandler(this.OnPluginAdded);
            this.PluginManager.PluginRemoved += new PluginManager.PluginContextHandler(this.OnPluginRemoved);
            this.logger.Info("Loading Plugins...");
            Singleton <PluginManager> .Instance.LoadAllPlugins();

            this.CommandManager.LoadOrCreateCommandsInfo(ServerBase.CommandsInfoFilePath);
        }