/// <summary> /// Fires <see cref="BeforeCommandProcessed"/> event, passing <paramref name="session"/> and <paramref name="parameter"/> to subscribers /// </summary> /// <param name="session"></param> /// <param name="parameter"></param> protected virtual void OnBeforeCommandProcessed(Session session, object parameter) { BeforeCommandProcessed?.Invoke(this, new CommandProcessedEventArgs() { Session = session, Parameter = parameter }); }
private async Task RunGameLoop() { while (IsRunning) { var input = await Commander.ReadCommand(); if (string.IsNullOrWhiteSpace(input)) { continue; } try { _serviceScope = _gameServices.CreateScope(); var command = GetCommand(input); if (command == null) { OnCommandNotFound?.Invoke(input); } else { var parameters = input.Split(' ').Where((item, index) => index != 0).ToArray(); BeforeCommandProcessed?.Invoke(command, parameters); command.ProcessByGame(parameters); AfterCommandProcessed?.Invoke(command, parameters); } } catch (Exception) { throw; } finally { _serviceScope.Dispose(); _serviceScope = null; } } OnStop.Invoke(CurrentCommand, _currentParameters); }