public async Task <OneononeEntity> Update(OneononeEntity oneonone) { var requestErrors = new string[] { Guid.TryParse(oneonone.Id, out var _) ? null : GlobalMessages.InvalidId(oneonone.Id), Enum.IsDefined(typeof(FrequencyEnum), oneonone.Frequency) ? null : OneononesMessages.InvalidFrequency((int)oneonone.Frequency), }.Where(e => e != null);
public async Task <HistoricalEntity> Update(HistoricalEntity historical) { var requestErrors = new string[] { Guid.TryParse(historical.Id, out var _) ? null : GlobalMessages.InvalidId(historical.Id), historical.Occurrence == DateTime.MinValue ? HistoricalsMessages.InvalidOccurrence(historical.Occurrence) : null, }.Where(e => e != null);
private async Task ReadyAsync() { ChannelData.PopulateChannels(); await GlobalMessages.ClearData(); await UpdateStatus(); }
public async Task <(EmployeeEntity, EmployeeEntity)> ObtainPair(string leaderId, string ledId) { var requestErrors = new string[] { Guid.TryParse(leaderId, out var _) ? null : GlobalMessages.InvalidId(leaderId), Guid.TryParse(ledId, out var _) ? null : GlobalMessages.InvalidId(ledId), leaderId == ledId ? EmployeesMessages.Same : null, }.Where(e => e != null);
public void AddTrainer(string name) { var exam = GenerateExam(); this.trainers.Add(this.trainerFactory.CreateCurrentYearTrainer(name, exam)); logger.WriteLine(GlobalMessages.TrainerWasAdded(name)); // this.trainerFactory.CreateTrainer(trainer); }
private void HandleGlobalMessage(BinaryReader buffer) { var message = (GlobalMessage)serializer.Deserialize(buffer.ReadBytes(BUFFERSIZE)); this.InvokeOnUI( () => { GlobalMessages.AppendText(string.Format(messageFormat, message.User.Name, message.Message)); GlobalMessageBox.Clear(); }); }
public void AddStudent(string name) { IPet pet = this.petFactory.CreatePet(); IStudent student = this.studentFactory.CreateStudent(name, pet); this.students.Add(student); student.CantPassExam += this.ExamFailsObserver; logger.WriteLine(GlobalMessages.StudentWasAded(name)); // logger.WriteLine(student.Pet.HelpMe(student)); // NE TUK!!! }
public IExecutionResult Update(ArticleModifyViewModel model, string currentLoggedUserId) { if (model.AuthorId == currentLoggedUserId) { return(base.Update(model)); } return(new ExecutionResult() { Succeded = false, Message = GlobalMessages.NoAccess("article") }); }
/// <summary> /// Sends a global request. /// </summary> /// <param name="request"></param> /// <param name="wantreply"></param> /// <returns></returns> public bool SendGlobalRequest(GlobalRequest request, bool wantreply) { try { SSHPacket packet = GetPacket(); packet.WriteByte(SSH_MSG_GLOBAL_REQUEST); packet.WriteString(request.Name); packet.WriteBool(wantreply); if (request.Data != null) { packet.WriteBytes(request.Data); } #if DEBUG System.Diagnostics.Trace.WriteLine("Sending SSH_MSG_GLOBAL_REQUEST"); System.Diagnostics.Trace.WriteLine(request.Name); #endif SendMessage(packet); if (wantreply) { packet = GlobalMessages.NextMessage(GLOBAL_REQUEST_MESSAGES); if (packet.MessageID == SSH_MSG_REQUEST_SUCCESS) { if (packet.Available > 1) { byte[] tmp = new byte[packet.Available]; packet.ReadBytes(tmp); request.Data = tmp; } else { request.Data = null; } return(true); } else { return(false); } } else { return(true); } } catch (System.IO.IOException ex) { throw new SSHException(ex.Message, SSHException.INTERNAL_ERROR); } }
public static bool Prefix(ref ZRoutedRpc __instance, ref RoutedRPCData data) { if (ZNet.m_isServer && data?.m_methodHash == GlobalMessages.TalkerSayHashCode) { // Read local say chat messages for users not connected to VChat. // Messages that fit the global chat command name will be redirected as global chat messages. if (GreetingMessage.PeerInfo.TryGetValue(data.m_senderPeerID, out GreetingMessagePeerInfo peerInfo) && !peerInfo.HasReceivedGreeting) { try { var senderPeer = ZNet.instance.GetPeer(data.m_senderPeerID); var package = new ZPackage(data.m_parameters.GetArray()); var ctype = package.ReadInt(); var playerName = package.ReadString(); var text = package.ReadString(); if (ctype == (int)Talker.Type.Normal) { var globalChatCommand = VChatPlugin.CommandHandler.FindCommand(PluginCommandType.SendGlobalMessage); if (VChatPlugin.CommandHandler.IsValidCommandString(text, globalChatCommand, out text)) { VChatPlugin.Log($"Redirecting local message to global chat from peer {data.m_senderPeerID} \"({senderPeer?.m_playerName})\" with message \"{text}\"."); // Redirect this message to the global chat channel. foreach (var peer in ZNet.instance.GetConnectedPeers()) { // Exclude the sender, otherwise it'd probably just be annoying. if (peer.m_uid != data.m_senderPeerID) { GlobalMessages.SendGlobalMessageToPeer(peer.m_uid, (int)GlobalMessageType.RedirectedGlobalMessage, senderPeer?.m_refPos ?? new Vector3(), senderPeer?.m_playerName ?? playerName, text); } } // Intercept message so that other connected users won't receive the same message twice. data.m_methodHash = GlobalMessages.InterceptedSayHashCode; return(false); } } } catch (Exception ex) { VChatPlugin.LogError($"Error reading Talker.Say message for unconnected VChat user ({data.m_senderPeerID}): {ex}"); } } } return(true); }
public IExecutionResult Delete(int id, string currentLoggedUserId) { var repo = unitOfWork.GetRepository <Article>(); var item = repo.FirstOrDefault(i => i.Id == id); if (item.AuthorId == currentLoggedUserId) { return(base.Delete(item)); } return(new ExecutionResult() { Succeded = false, Message = GlobalMessages.NoAccess("article") }); }
public async Task <EmployeeEntity> Obtain(string id) { if (!Guid.TryParse(id, out var _)) { throw new ApiException(HttpStatusCode.BadRequest, GlobalMessages.InvalidId(id)); } var employee = await employeesRepository.Obtain(id); if (employee == null) { throw new ApiException(HttpStatusCode.NotFound, EmployeesMessages.NotFoundId(id)); } return(employee); }
private static bool Prefix(ref Chat __instance) { var text = __instance.m_input.text; // Add the message to the chat history. if (VChatPlugin.Settings.MaxPlayerMessageHistoryCount > 0) { if (VChatPlugin.MessageSendHistory.Count > VChatPlugin.Settings.MaxPlayerMessageHistoryCount) { VChatPlugin.MessageSendHistory.RemoveAt(0); } VChatPlugin.MessageSendHistory.Add(text); VChatPlugin.MessageSendHistoryIndex = 0; } // Attempt to parse a command. if (VChatPlugin.CommandHandler.TryFindAndExecuteCommand(text, __instance, out PluginCommand _)) { return(false); } // Otherwise send the message to the last used channel. // Only when not starting with a slash, because that's the default for commands. We still want /sit and such to work :) if (!text.StartsWith("/")) { if (VChatPlugin.LastChatType.IsDefaultType()) { __instance.SendText(VChatPlugin.LastChatType.DefaultTypeValue.Value, text); return(false); } else { switch (VChatPlugin.LastChatType.CustomTypeValue) { case CustomMessageType.Global: GlobalMessages.SendGlobalMessageToServer(text); break; } return(false); } } return(true); }
public async Task <HistoricalEntity> Obtain(string id) { if (!Guid.TryParse(id, out var _)) { throw new ApiException(HttpStatusCode.BadRequest, GlobalMessages.InvalidId(id)); } var historical = await historicalsRepository.Obtain(id); if (historical == null) { throw new ApiException(HttpStatusCode.NotFound, HistoricalsMessages.NotFound(id)); } await FillEmployees(historical); return(historical); }
public async Task <OneononeEntity> Obtain(string id) { if (!Guid.TryParse(id, out var _)) { throw new ApiException(HttpStatusCode.BadRequest, GlobalMessages.InvalidId(id)); } var oneonone = await oneononesRepository.Obtain(id); if (oneonone == null) { throw new ApiException(HttpStatusCode.NotFound, OneononesMessages.NotFound(id)); } await FillEmployees(oneonone); return(oneonone); }
public Course(string name, string lecturesPerWeek, string startingDate) { this.Name = name; try { this.LecturesPerWeek = int.Parse(lecturesPerWeek); } catch (Exception) { throw new ArgumentException(GlobalMessages.LecturesPerWeeek()); } try { this.StartingDate = DateTime.ParseExact(startingDate, "yyyy-MM-d", CultureInfo.CurrentCulture); } catch (Exception) { throw new ArgumentException("Invalid DateTime format!"); } }
public void StartExam(string trainerName) { ICurrentYearTrainer trainer = null; foreach (var tr in this.trainers) { if (tr.Name == trainerName) { trainer = tr as ICurrentYearTrainer; } } if (trainer != null && trainer.IsAlive) { logger.WriteLine(GlobalMessages.TrainerThrowsExam(trainer.Name)); var result = trainer.ThrowExam(this.students); logger.WriteLine(result); } else { logger.WriteLine($"There is no alive trainer with name {trainerName}"); } }
private async Task ReadyAsync() { await GlobalMessages.ClearData(); await UpdateStatus(); }
private void InitialiseCommands() { CommandHandler.ClearCommands(); const string changedColorMessageSuccess = "Changed the {0} color to <color={1}>{2}</color>."; const string errorParseColorMessage = "Could not parse the color \"{0}\"."; const string errorParseNumber = "Could not convert \"{0}\" to a valid number."; var writeErrorMessage = new Action <string>((string message) => { Chat.instance.AddString($"<color=red>[{Name}][Error] {message}</color>"); }); var writeSuccessMessage = new Action <string>((string message) => { Chat.instance.AddString($"<color=#23ff00>[{Name}] {message}</color>"); }); var applyChannelColorCommand = new Func <string, CombinedMessageType, Color?>((string text, CombinedMessageType messageType) => { text = text?.Trim(); var color = text?.ToColor(); // Get default color if text is empty. if (string.IsNullOrEmpty(text)) { text = "default"; color = GetTextColor(messageType, true); } // Write the response message. if (color != null) { writeSuccessMessage(string.Format(changedColorMessageSuccess, messageType.ToString().ToLower(), color?.ToHtmlString(), text)); } else { writeErrorMessage(string.Format(errorParseColorMessage, text)); } return(color); }); CommandHandler.AddCommands( new PluginCommand(PluginCommandType.SendLocalMessage, Settings.LocalChatCommandName, (text, instance) => { LastChatType.Set(Talker.Type.Normal); if (!string.IsNullOrEmpty(text)) { ((Chat)instance).SendText(Talker.Type.Normal, text); } }), new PluginCommand(PluginCommandType.SendShoutMessage, Settings.ShoutChatCommandName, (text, instance) => { LastChatType.Set(Talker.Type.Shout); if (!string.IsNullOrEmpty(text)) { ((Chat)instance).SendText(Talker.Type.Shout, text); } }), new PluginCommand(PluginCommandType.SendWhisperMessage, Settings.WhisperChatCommandName, (text, instance) => { LastChatType.Set(Talker.Type.Whisper); if (!string.IsNullOrEmpty(text)) { ((Chat)instance).SendText(Talker.Type.Whisper, text); } }), new PluginCommand(PluginCommandType.SendGlobalMessage, Settings.GlobalChatCommandName, (text, instance) => { LastChatType.Set(CustomMessageType.Global); if (!string.IsNullOrEmpty(text)) { GlobalMessages.SendGlobalMessageToServer(text); } }), new PluginCommand(PluginCommandType.SetLocalColor, Settings.SetLocalChatColorCommandName, (text, instance) => { var color = applyChannelColorCommand(text, new CombinedMessageType(Talker.Type.Normal)); if (color != null) { Settings.LocalChatColor = color; } }), new PluginCommand(PluginCommandType.SetShoutColor, Settings.SetShoutChatColorCommandName, (text, instance) => { var color = applyChannelColorCommand(text, new CombinedMessageType(Talker.Type.Shout)); if (color != null) { Settings.ShoutChatColor = color; } }), new PluginCommand(PluginCommandType.SetWhisperColor, Settings.SetWhisperChatColorCommandName, (text, instance) => { var color = applyChannelColorCommand(text, new CombinedMessageType(Talker.Type.Whisper)); if (color != null) { Settings.WhisperChatColor = color; } }), new PluginCommand(PluginCommandType.SetGlobalColor, Settings.GlobalWhisperChatColorCommandName, (text, instance) => { var color = applyChannelColorCommand(text, new CombinedMessageType(CustomMessageType.Global)); if (color != null) { Settings.GlobalChatColor = color; } }), new PluginCommand(PluginCommandType.ToggleShowChatWindow, "showchat", (text, instance) => { Settings.AlwaysShowChatWindow = !Settings.AlwaysShowChatWindow; writeSuccessMessage($"{(Settings.AlwaysShowChatWindow ? "Always displaying" : "Auto hiding")} chat window."); }), new PluginCommand(PluginCommandType.ToggleShowChatWindowOnMessage, Settings.ShowChatOnMessageCommandName, (text, instance) => { Settings.ShowChatWindowOnMessageReceived = !Settings.ShowChatWindowOnMessageReceived; writeSuccessMessage($"{(Settings.ShowChatWindowOnMessageReceived ? "Displaying" : "Not displaying")} chat window when receiving a message."); }), new PluginCommand(PluginCommandType.ToggleChatWindowClickThrough, Settings.ChatClickThroughCommandName, (text, instance) => { Settings.EnableClickThroughChatWindow = !Settings.EnableClickThroughChatWindow; writeSuccessMessage($"{(Settings.EnableClickThroughChatWindow ? "Enabled" : "Disabled")} clicking through the chat window."); ((Chat)instance).m_chatWindow?.ChangeClickThroughInChildren(!Settings.EnableClickThroughChatWindow); }), new PluginCommand(PluginCommandType.SetMaxPlayerHistory, Settings.MaxPlayerChatHistoryCommandName, (text, instance) => { if (string.IsNullOrEmpty(text)) { writeSuccessMessage($"The number of stored player messages is set to {Settings.MaxPlayerMessageHistoryCount}."); } else { if (ushort.TryParse(text, out ushort value)) { Settings.MaxPlayerMessageHistoryCount = value; if (value > 0) { writeSuccessMessage($"Changed the maximum stored player messages to {value}."); } else { writeSuccessMessage($"Disabled capturing player chat history."); MessageSendHistory.Clear(); } // Readjust buffer size while (MessageSendHistory.Count > 0 && MessageSendHistory.Count < Settings.MaxPlayerMessageHistoryCount) { MessageSendHistory.RemoveAt(0); } } else { writeErrorMessage(string.Format(errorParseNumber, text)); } } }), new PluginCommand(PluginCommandType.SetHideDelay, Settings.SetChatHideDelayCommandName, (text, instance) => { if (float.TryParse(text, out float delay) && !float.IsNaN(delay)) { if (delay > 0) { Settings.ChatHideDelay = delay; ((Chat)instance).m_hideDelay = delay; writeSuccessMessage($"Updated the chat hide delay to {delay} seconds."); } else { writeErrorMessage($"Hide delay must be greater than 0."); } } else { writeErrorMessage(string.Format(errorParseNumber, text)); } }), new PluginCommand(PluginCommandType.SetFadeTime, Settings.SetChatFadeTimeCommandName, (text, instance) => { if (float.TryParse(text, out float time) && !float.IsNaN(time)) { time = Math.Max(0f, time); writeSuccessMessage($"Updated the chat fade timer to {time} seconds."); Settings.ChatFadeTimer = time; } else { writeErrorMessage(string.Format(errorParseNumber, text)); } }), new PluginCommand(PluginCommandType.SetActiveOpacity, Settings.SetOpacityCommandName, (text, instance) => { if (uint.TryParse(text, out uint opacity)) { opacity = Math.Min(100, Math.Max(0, opacity)); writeSuccessMessage($"Updated the chat opacity to {opacity}."); Settings.ChatOpacity = opacity; } else { writeErrorMessage(string.Format(errorParseNumber, text)); } }), new PluginCommand(PluginCommandType.SetInactiveOpacity, Settings.SetInactiveOpacityCommandName, (text, instance) => { if (uint.TryParse(text, out uint opacity)) { opacity = Math.Min(100, Math.Max(0, opacity)); writeSuccessMessage($"Updated the chat inactive opacity to {opacity}."); Settings.InactiveChatOpacity = opacity; } else { writeErrorMessage(string.Format(errorParseNumber, text)); } }), new PluginCommand(PluginCommandType.SetDefaultChatChannel, Settings.SetDefaultChatChannelCommandName, (text, instance) => { var type = new CombinedMessageType(CustomMessageType.Global); bool success = false; if (Enum.TryParse(text, true, out Talker.Type talkerType) && talkerType != Talker.Type.Ping) { type.Set(talkerType); success = true; } else { if (Enum.TryParse(text, true, out CustomMessageType customType)) { type.Set(customType); success = true; } } if (success) { writeSuccessMessage($"Updated the default chat channel to {text}."); Settings.DefaultChatChannel = type; } else { writeErrorMessage($"Failed to convert \"{text}\" into a chat channel name. Accepted values: {string.Join(", ", Enum.GetNames(typeof(Talker.Type)).Except(new[] { nameof(Talker.Type.Ping) }).Concat(Enum.GetNames(typeof(CustomMessageType))).Distinct().Select(x => x.ToLower()))}."); } }) ); }
public Form1() { InitializeComponent(); GlobalMessages.Register(this); }
private static void Postfix(ref ZNet __instance) { // Register our custom defined messages. GlobalMessages.Register(); GreetingMessage.Register(); }