Exemplo n.º 1
0
        protected virtual async Task OnMessageReceived(YateMessageEventArgs message, CancellationToken cancellationToken)
        {
            var handler = MessageReceivedAsync;

            if (handler != null)
            {
                try
                {
                    await handler(message).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    await LogAsync(ex.Message, cancellationToken).ConfigureAwait(false);
                }
            }
            var commands = new List <string>
            {
                YateConstants.RMessage,
                message.Id,
                message.Handled ? YateConstants.True : YateConstants.False,
                message.Name,
                message.Result
            };

            if (handler != null)
            {
                commands.AddRange(message.NewParameter.Select(x => _serializer.Encode(x)));
            }
            var response = Command(commands.ToArray());

            await SendAsync(response, cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 2
0
 private void InvokeWatchCallbacks(object sender, YateMessageEventArgs e)
 {
     if (_watchCallbacks.TryGetValue(e.Name, out var bag))
     {
         foreach (var callback in bag)
         {
             callback(e);
         }
     }
 }
Exemplo n.º 3
0
        protected virtual void OnWatch(YateMessageEventArgs message)
        {
            var handler = Watched;

            try
            {
                handler?.Invoke(this, message);
            }
            catch (Exception ex)
            {
                LogAsync(ex.Message, CancellationToken.None).GetAwaiter().GetResult();
            }
        }