public async Task ShowAllReminder(long groupId, long userId) { var builder = new MessageBuilder(); builder.Append(new AtMessage(userId)); try { if (Events.Count == 0) { builder.Append((SimpleMessage)"配置文件不存在!"); return; } var thisGroup = (from reminderEvent in Events where reminderEvent.GroupId == groupId && reminderEvent.DeadLine > DateTime.Now orderby reminderEvent.DeadLine select reminderEvent).ToList(); if (!thisGroup.Any()) { builder.Append((SimpleMessage)"本群无提醒事项!"); } else { builder.Append((SimpleMessage)"本群有以下提醒事项:\n"); foreach (var reminderEvent in thisGroup) { builder.Append((SimpleMessage)$"{reminderEvent}\n"); } } } finally { await _messageSender.SendGroupAsync(groupId, builder.ToMessage()); } }
public HealthMonitorResult(string name, HealthType healthType, ResultStatus status, string message = "") : this(name, healthType) { Status = status; if (!string.IsNullOrEmpty(message)) { MessageBuilder.Append(message); } }
public void CommandGenerateMessages(CommandModel cmd, IChatView chat) { Trace.Call(cmd, chat); var count = 0; Int32.TryParse(cmd.Parameter, out count); var builder = new MessageBuilder(); var sender = new ContactModel("msg-tester", "msg-tester", "test", "test"); builder.AppendMessage(sender, "time for a messsage generator command so I can test speed and memory usage"); var text = builder.CreateText(" *formatted text* "); text.Bold = true; builder.Append(text); builder.AppendUrl("https://www.smuxi.org/"); var msgs = new List <MessageModel>(count); for (var i = 0; i < count; i++) { var msg = builder.ToMessage(); msgs.Add(msg); } DateTime start, stop; start = DateTime.UtcNow; foreach (var msg in msgs) { chat.AddMessage(msg); } stop = DateTime.UtcNow; builder = new MessageBuilder(); builder.AppendText( "IChatView.AddMessage(): count: {0} took: {1:0} ms avg: {2:0.00} ms", count, (stop - start).TotalMilliseconds, (stop - start).TotalMilliseconds / count ); chat.AddMessage(builder.ToMessage()); }
/// <summary> /// Worker, runs until the thread stops /// </summary> public void Work() { while (!_stopWorking) { if (_serialPortObject.SerialPort.IsOpen && _serialPortObject.SerialPort.BytesToRead > 0) { try { var dataFromSocket = _serialPortObject.SerialPort.ReadExisting(); _messageBuilder.Append(dataFromSocket); ProcessMessages(); } catch (Exception exception) // Not very nice to catch Exception...but for now it's good enough. { Console.WriteLine("Could not read from serial port: " + exception.Message); } } } }
public void ShowMessage(TLogger entity) { #if SERVER if (entity.FLogLevel != this.LogLevel) { return; } #endif if (!CanShow(this.LogLevel)) { return; } MessageBuilder.Clear(); var last = entity.FStackInfo.LastIndexOf('\\'); string lastString = null; if (!string.IsNullOrEmpty(entity.FStackInfo) && last < entity.FStackInfo.Length) { lastString = entity.FStackInfo.Substring(entity.FStackInfo.LastIndexOf('\\') + 1); } MessageBuilder.Append($"{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss ")}{Enum.GetName(typeof(LogLevel), this.LogLevel)} {lastString}"); if (!string.IsNullOrEmpty(entity.FMessage)) { MessageBuilder.Append($" {entity.FMessage}"); } if (!string.IsNullOrEmpty(entity.FArgs)) { MessageBuilder.Append($" args:{entity.FArgs}"); } if (!string.IsNullOrEmpty(entity.FExceptionName)) { MessageBuilder.AppendLine(); MessageBuilder.AppendLine($"name:{entity.FExceptionName}"); MessageBuilder.AppendLine($"message:{entity.FExceptionMessage}"); MessageBuilder.AppendLine($"exception:{entity.FExceptionInfo.Trim()}"); } ConsoleLogger.ShowMessage(MessageBuilder.ToString()); }
public async Task Remind() { var currentHour = DateTime.Now.Hour; var events = from remindEvent in Events where remindEvent.DeadLine > DateTime.Now && remindEvent.RemindHours.Contains(currentHour) orderby remindEvent.DeadLine group remindEvent by remindEvent.GroupId into newGroup orderby newGroup.Key select newGroup; foreach (var grouping in events) { var builder = new MessageBuilder(); foreach (var reminder in grouping) { builder.Append((SimpleMessage)$"{reminder}\n"); } await _messageSender.SendGroupAsync(grouping.Key, builder.ToMessage()); await _messageSender.SendGroupAsync(grouping.Key, (SimpleMessage)"我也要做加把劲骑士了!"); } }