Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x | import { ContainerConstants } from '@medjaibot/framework/constants/ContainerConstants'; import { EventManager } from '@medjaibot/framework/event/EventManager'; import { IsNullOrUndefined } from '@medjaibot/framework/Extras'; import { Logger } from '@medjaibot/framework/logger/Logger'; import { Plugin } from '@medjaibot/framework/plugin/Plugin'; import { PluginManager } from '@medjaibot/framework/plugin/PluginManager'; import { Container, inject, injectable } from 'inversify'; /** * The server application which will * be runned when the server starts * * @export * @class Application * @since 0.0.1 * @version 0.0.1 * @author Yannick Fricke <yannickfricke@googlemail.com> * @license MIT * @copyright MedjaiBot https://github.com/MedjaiBot/server */ @injectable() export class Application { /** * Contains the application logger * * @protected * @type {Logger} * @memberof Application */ protected logger: Logger; /** * The plugin manager which will be used for all plugins * * @protected * @type {PluginManager} * @memberof Application */ protected pluginManager: PluginManager; /** * The event manager to use * * @protected * @type {EventManager} * @memberof Application */ protected eventManager: EventManager; /** * The container which will be used to initialize the plugins * * @protected * @type {Container} * @memberof Application */ protected container: Container; /** * When is set to true the application is currently running * * @protected * @type {boolean} * @memberof Application */ protected running: boolean; /** * Creates an instance of Application. * @param {Logger} logger The logger to use * @param {PluginManager} pluginManager The plugin manager for the application * @param {EventManager} eventManager The event manager which will be used * @throws When one of the parameters is null or undefined * @memberof Application */ constructor( @inject(ContainerConstants.LOGGING.LOGGER) logger: Logger, @inject(ContainerConstants.SYSTEMS.PLUGIN.PLUGINMANAGER) pluginManager: PluginManager, @inject(ContainerConstants.SYSTEMS.EVENT.EVENTMANAGER) eventManager: EventManager, @inject(ContainerConstants.DI.CONTAINER) container: Container, ) { Iif (IsNullOrUndefined(logger)) { throw new Error('The logger is not set'); } Iif (IsNullOrUndefined(pluginManager)) { throw new Error('The plugin manager is not set'); } Iif (IsNullOrUndefined(eventManager)) { throw new Error('The event manager is not set'); } Iif (IsNullOrUndefined(container)) { throw new Error('The container is not set'); } this.logger = logger; this.pluginManager = pluginManager; this.eventManager = eventManager; this.container = container; this.running = false; } /** * Runs the application and loads all the available plugins * from the './plugins' file directory * * @memberof Application */ public async run() { this.running = true; this.logger.info(`Starting up!`); // Dispatch the startup event this.eventManager.broadcast('System.Server.Application.Run.Startup'); // Loads all plugins from the plugins directory this.pluginManager.loadPlugins('./plugins'); // Dumps the loaded plugins this.logger.info( `Loaded ${this.pluginManager.plugins.length} plugin${this.pluginManager.plugins.length === 1 ? '' : 's'}`, ); this.pluginManager.plugins.forEach((plugin: Plugin) => { this.logger.info(`Loaded plugin ${plugin.name} v${plugin.version}`); }); // Starts the server // const workerId = setInterval(() => { // if (!this.running) { // clearInterval(workerId); // this.logger.info('Shutting down the server!'); // return; // } // this.eventManager.broadcast('System.Server.Application.Run.Tick'); // }, 1000); } /** * Stops the server * * @memberof Application */ public stop() { this.running = false; } } |