public static IControlCommand BuildCommand(AddOptions addOptions) { DateTime?at = null; TimeSpan?after = null; var id = addOptions.ReqId; var alarm = addOptions.Sound; var maintainTimes = addOptions.Times; if (!string.IsNullOrEmpty(addOptions.At)) { at = DateTime.Parse(addOptions.At); } if (!string.IsNullOrEmpty(addOptions.After)) { after = ParsePeriod(addOptions.After); } if (after != null || at != null) { //没有传计时 if (after != null) { at ??= DateTime.Now.Add(after.Value); } after ??= TimeSpan.Zero; var cmd = new TimingCommand(id, at.Value, new Times(maintainTimes), after.Value, alarm, addOptions.Message); return(new TimingCreatedNotification(cmd)); } throw new ArgumentException("参数无法转换"); }
private async Task RunAsync(TimingCommand c) { try { await _mediator.Publish(c); } catch (Exception e) { Console.WriteLine(e.Message); } }
public TimerZ(TimingCommand command, IMediator mediator) { _mediator = mediator; Command = command; var sec = command.RemainTime.TotalMilliseconds; _timer = new Timer { Interval = sec, AutoReset = false }; _timer.Elapsed += async(_, _) => await RunAsync(Command).ConfigureAwait(false); _timer.Start(); }
public TimingCreatedNotification(TimingCommand command) { Id = command.Id; AlertCommand = command; }