Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 protected abstract Task OnTextMessageRecieved(TextMessageRecievedEventArgs args);