private async Task <bool> ResponseAsync(ControllerParameter parameter, Message message) { void append() { var profile = parameter.SenderProfile; var messages = profile.MessageCollection; if (messages.Any(r => r.Id == message.Id)) { return; } messages.Add(message); var eventArgs = new MessageEventArgs(this, profile, message); NewMessage?.Invoke(this, eventArgs); if (eventArgs.Handled) { return; } profile.Hint++; } var success = parameter.SenderProfile != null; if (success) { await UpdateUIAsync(append); } var data = new { status = success ? "ok" : "refused" }; await parameter.ResponseAsync(data); return(success); }
internal async Task HandleDirectoryAsync(ControllerParameter parameter) { var profile = parameter.SenderProfile; var handler = NewDirectoryReceiver; if (profile == null || handler == null || parameter.ConnectionType != LinkConnectionType.Tcp) { return; } var data = parameter.Packet.Data; var name = data["name"].As <string>(); using (var receiver = new DirectoryReceiver(this, profile, parameter.Stream, name)) { await parameter.ResponseAsync(new { status = "wait" }); await UpdateUIAsync(() => handler.Invoke(receiver)); await receiver.LoopAsync(); } }