/// <summary> /// Method to broadcast message to all connected clients /// </summary> /// <param name="chatMessage">Message object with text and Writter</param> public async void SendAll(ChatMessage chatMessage) { if (_commandService.IsCommand(chatMessage.Text)) { CommandInfos infos = _commandService.GetCommandInfos(chatMessage.Text); /* Im broadcasting user command, but not saving it to database */ await Broadcast(chatMessage); if (infos.Error != null) { await Broadcast(AdminMessage(infos.Error)); } else { _userBotQueueProducer.SearchStock(infos.Parameter); } } else { /* If is not a command, save to database and broadcast */ string userId = chatMessage.UserID; ChatUser chatUser = _userService.GetUser(userId); Message message = new Message(chatMessage.Text, chatUser); _messageService.AddMessage(message); chatMessage.SentAt = message.SentAt; await Broadcast(chatMessage); } }
/// <summary>Saves a control configuration to disk</summary> /// <param name="FileOrNull">An absolute file path if we are exporting the controls, or a null reference to save to the default configuration location</param> /// <param name="controlsToSave">The list of controls to save</param> internal static void SaveControls(string FileOrNull, Control[] controlsToSave) { CultureInfo Culture = CultureInfo.InvariantCulture; System.Text.StringBuilder Builder = new System.Text.StringBuilder(); Builder.AppendLine("; Current control configuration"); Builder.AppendLine("; ============================="); Builder.AppendLine("; This file was automatically generated. Please modify only if you know what you're doing."); Builder.AppendLine("; This file is INCOMPATIBLE with versions older than 1.4.4."); Builder.AppendLine(); for (int i = 0; i < controlsToSave.Length; i++) { CommandInfo Info = CommandInfos.TryGetInfo(controlsToSave[i].Command); Builder.Append(Info.Name + ", "); switch (controlsToSave[i].Method) { case ControlMethod.Keyboard: Builder.Append("keyboard, " + controlsToSave[i].Key + ", " + ((int)controlsToSave[i].Modifier).ToString(Culture)); break; case ControlMethod.Joystick: Builder.Append("joystick, " + controlsToSave[i].Device.ToString(Culture) + ", "); switch (controlsToSave[i].Component) { case JoystickComponent.Axis: Builder.Append("axis, " + controlsToSave[i].Element.ToString(Culture) + ", " + controlsToSave[i].Direction.ToString(Culture)); break; case JoystickComponent.Ball: Builder.Append("ball, " + controlsToSave[i].Element.ToString(Culture) + ", " + controlsToSave[i].Direction.ToString(Culture)); break; case JoystickComponent.Hat: Builder.Append("hat, " + controlsToSave[i].Element.ToString(Culture) + ", " + controlsToSave[i].Direction.ToString(Culture)); break; case JoystickComponent.Button: Builder.Append("button, " + controlsToSave[i].Element.ToString(Culture)); break; default: Builder.Append("invalid"); break; } break; case ControlMethod.RailDriver: Builder.Append("raildriver, 0, "); switch (controlsToSave[i].Component) { case JoystickComponent.Axis: Builder.Append("axis, " + controlsToSave[i].Element.ToString(Culture) + ", " + controlsToSave[i].Direction.ToString(Culture)); break; case JoystickComponent.Button: Builder.Append("button, " + controlsToSave[i].Element.ToString(Culture)); break; default: Builder.Append("invalid"); break; } break; } Builder.Append("\n"); } string File; if (FileOrNull == null) { File = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "1.5.0/controls.cfg"); } else { File = FileOrNull; } System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true)); }