public ResponseMessage Calculate(RequestMessage req) { Stopwatch stopwatch = Stopwatch.StartNew(); _log.Info($"[request catch '{req.UserChannel} - Value {req.Value}']"); IMiddleware pipeline = _container.GetMiddlewarePipeline(); try { var res = pipeline.Invoke(req); stopwatch.Stop(); _log.Info($"[Message ended - Took {stopwatch.ElapsedMilliseconds} milliseconds]"); _averageResponse.Log(stopwatch.ElapsedMilliseconds); return(res); } catch (Exception ex) { _log.Error($"ERROR WHILE PROCESSING MESSAGE: {ex}"); } stopwatch.Stop(); _log.Info($"[Message ended - Took {stopwatch.ElapsedMilliseconds} milliseconds]"); _averageResponse.Log(stopwatch.ElapsedMilliseconds); return(null); }
public async Task MessageReceived(SlackMessage message) { Stopwatch stopwatch = Stopwatch.StartNew(); _logger.LogInformation($"[Message found from '{message.User.Name}']"); IMiddleware pipeline = _container.GetMiddlewarePipeline(); var incomingMessage = new IncomingMessage { RawText = message.Text, FullText = message.Text, UserId = message.User.Id, Username = GetUsername(message), UserEmail = message.User.Email, Channel = message.ChatHub.Id, ChannelType = message.ChatHub.Type == SlackChatHubType.DM ? ResponseType.DirectMessage : ResponseType.Channel, UserChannel = await GetUserChannel(message), BotName = _connection.Self.Name, BotId = _connection.Self.Id, BotIsMentioned = message.MentionsBot }; DataAccess dataAccess = new DataAccess("Server=(localdb)\\mssqllocaldb; Database=Reczept"); User user = new User() { MemberId = incomingMessage.UserId, Name = incomingMessage.Username }; dataAccess.CheckIfExistingUser(user); _logger.LogInformation($"[User Created]"); incomingMessage.TargetedText = incomingMessage.GetTargetedText(); try { foreach (ResponseMessage responseMessage in pipeline.Invoke(incomingMessage)) { await SendMessage(responseMessage); } } catch (Exception ex) { _logger.LogError($"ERROR WHILE PROCESSING MESSAGE: {ex}"); } stopwatch.Stop(); _logger.LogInformation($"[Message ended - Took {stopwatch.ElapsedMilliseconds} milliseconds]"); _averageResponse.Log(stopwatch.ElapsedMilliseconds); }
public async Task MessageReceived(SlackMessage message) { Stopwatch stopwatch = Stopwatch.StartNew(); _log.Log($"[Message found from '{message.User.Name}']"); IMiddleware pipeline = _container.GetMiddlewarePipeline(); var incomingMessage = new IncomingMessage { RawText = message.Text, FullText = message.Text, UserId = message.User.Id, Username = GetUsername(message), Channel = message.ChatHub.Id, ChannelType = message.ChatHub.Type == SlackChatHubType.DM ? ResponseType.DirectMessage : ResponseType.Channel, UserChannel = await GetUserChannel(message), BotName = _connection.Self.Name, BotId = _connection.Self.Id, BotIsMentioned = message.MentionsBot }; incomingMessage.TargetedText = incomingMessage.GetTargetedText(); try { foreach (ResponseMessage responseMessage in pipeline.Invoke(incomingMessage)) { await SendMessage(responseMessage); } } catch (Exception ex) { try { await SendMessage(incomingMessage.ReplyToChannel($"@{incomingMessage.Username} Uh Oh! Something went on fire!")); } catch { _log.Log("Unable to send error code to chat"); } _log.Log($"ERROR WHILE PROCESSING MESSAGE: {ex}"); } stopwatch.Stop(); _log.Log($"[Message ended - Took {stopwatch.ElapsedMilliseconds} milliseconds]"); _averageResponse.Log(stopwatch.ElapsedMilliseconds); }