async Task <MqttApplicationMessageInterceptorContext> InterceptApplicationMessageAsync(MqttClientConnection senderConnection, MqttApplicationMessage applicationMessage) { var interceptor = _options.ApplicationMessageInterceptor; if (interceptor == null) { return(null); } string senderClientId; IDictionary <object, object> sessionItems; var messageIsFromServer = senderConnection == null; if (messageIsFromServer) { senderClientId = _options.ClientId; sessionItems = _serverSessionItems; } else { senderClientId = senderConnection.ClientId; sessionItems = senderConnection.Session.Items; } var interceptorContext = new MqttApplicationMessageInterceptorContext(senderClientId, sessionItems, applicationMessage); await interceptor.InterceptApplicationMessagePublishAsync(interceptorContext).ConfigureAwait(false); return(interceptorContext); }
async Task <MqttApplicationMessageInterceptorContext> InterceptApplicationMessageAsync(IMqttServerApplicationMessageInterceptor interceptor, MqttClientConnection clientConnection, MqttApplicationMessage applicationMessage) { string senderClientId; IDictionary <object, object> sessionItems; var messageIsFromServer = clientConnection == null; if (messageIsFromServer) { senderClientId = _options.ClientId; sessionItems = _serverSessionItems; } else { senderClientId = clientConnection.ClientId; sessionItems = clientConnection.Session.Items; } var interceptorContext = new MqttApplicationMessageInterceptorContext(senderClientId, sessionItems, _logger) { AcceptPublish = true, ApplicationMessage = applicationMessage, CloseConnection = false }; await interceptor.InterceptApplicationMessagePublishAsync(interceptorContext).ConfigureAwait(false); return(interceptorContext); }
private MqttApplicationMessage InterceptApplicationMessage(MqttClientSession senderClientSession, MqttApplicationMessage applicationMessage) { if (_options.ApplicationMessageInterceptor == null) { return(applicationMessage); } var interceptorContext = new MqttApplicationMessageInterceptorContext( senderClientSession.ClientId, applicationMessage); _options.ApplicationMessageInterceptor(interceptorContext); return(interceptorContext.ApplicationMessage); }
private MqttApplicationMessageInterceptorContext InterceptApplicationMessage(MqttClientSession sender, MqttApplicationMessage applicationMessage) { var interceptor = _options.ApplicationMessageInterceptor; if (interceptor == null) { return(null); } var interceptorContext = new MqttApplicationMessageInterceptorContext(sender?.ClientId, applicationMessage); interceptor(interceptorContext); return(interceptorContext); }
public Task InterceptApplicationMessagePublishAsync(MqttApplicationMessageInterceptorContext context) { Task.Run(async() => { try { await _callback.Invoke(context).ConfigureAwait(false); } catch (Exception exception) { context.Logger.Error(exception, "Error while intercepting application message."); } }).RunInBackground(); return(PlatformAbstractionLayer.CompletedTask); }
public Task InterceptApplicationMessagePublishAsync(MqttApplicationMessageInterceptorContext context) { Task.Run(async() => { try { await _callback.Invoke(context).ConfigureAwait(false); } catch (Exception exception) { var exceptionHandler = ExceptionHandler; if (exceptionHandler != null) { await exceptionHandler.Invoke(context, exception).ConfigureAwait(false); } } }).RunInBackground(); return(PlatformAbstractionLayer.CompletedTask); }
private async Task <MqttApplicationMessageInterceptorContext> InterceptApplicationMessageAsync(MqttClientConnection sender, MqttApplicationMessage applicationMessage) { var interceptor = _options.ApplicationMessageInterceptor; if (interceptor == null) { return(null); } var senderClientId = sender?.ClientId; if (sender == null) { senderClientId = _options.ClientId; } var interceptorContext = new MqttApplicationMessageInterceptorContext(senderClientId, applicationMessage); await interceptor.InterceptApplicationMessagePublishAsync(interceptorContext).ConfigureAwait(false); return(interceptorContext); }
public Task InterceptApplicationMessagePublishAsync(MqttApplicationMessageInterceptorContext context) { return(_callback(context)); }