public override Task TextMessageRecieved(string login, string message, ResultOfOperation result, ContactForm form = null, bool userIsAuth = true) { try { if (!userIsAuth) { result.OperationWasFinishedSuccessful = false; result.ErrorMessage = "Аутентификация не была проведена."; return(Task.CompletedTask); } if (form == null) { form = ContactsF.First(userForm => userForm.Login.Equals(login)); } var args = new TextMessageRecievedEventArgs() { Message = message, Contact = form }; result.OperationWasFinishedSuccessful = true; return(OnTextMessageRecieved(args)); } catch (InvalidOperationException ex) { result.OperationWasFinishedSuccessful = false; result.ErrorMessage = "Пользователь не зарегистрирован."; return(Task.CompletedTask); } }
protected override Task OnTextMessageRecieved(TextMessageRecievedEventArgs args) { Func <object, TextMessageRecievedEventArgs, Task> handlerEvent = TextMessageRecievedEvent; if (handlerEvent == null) { return(Task.FromResult(false)); } try { Delegate[] invocationList = handlerEvent.GetInvocationList(); var handlerTasks = invocationList.Select( delegatee => ((Func <object, TextMessageRecievedEventArgs, Task>)delegatee)(this, args)); return(Task.WhenAll(handlerTasks)); } catch (Exception ex) { return(Task.CompletedTask); } }
protected abstract Task OnTextMessageRecieved(TextMessageRecievedEventArgs args);