Ejemplo n.º 1
0
        public bool NewAlertRequest(IActivityMonitor activityMonitor, AlertExpressionModel alertExpression)
        {
            _memoryStream.Seek(0, SeekOrigin.Begin);
            _memoryStream.Flush();

            try
            {
                foreach (var sender in alertExpression.Senders)
                {
                    switch (sender.SenderType)
                    {
                    case "Mail":
                        sender.Configuration = JObject.FromObject(sender.Configuration).ToObject <MailSenderConfiguration>();
                        break;

                    case "Http":
                        sender.Configuration = JObject.FromObject(sender.Configuration).ToObject <HttpSenderConfiguration>();
                        break;

                    default:
                        return(false);
                    }
                }
            }
            catch (Exception exception)
            {
                activityMonitor.Error("Alert initialization failed.", exception);
                return(false);
            }

            _formatter.Serialize(_memoryStream, alertExpression);
            _controlChannelClient.SendAsync("AddAlertSender", _memoryStream.ToArray()).GetAwaiter().GetResult();

            return(true);
        }
Ejemplo n.º 2
0
        public object AddAlert([FromBody] AlertExpressionModel alertExpressionModel)
        {
            var activityMonitor = HttpContext.GetRequestMonitor();

            if (_alertService.NewAlertRequest(activityMonitor, alertExpressionModel))
            {
                return(NoContent());
            }
            return(BadRequest());
        }