Ejemplo n.º 1
0
        public static EventMessage Create(MessageUserData userData, Dictionary <string, string> headers, MessageAction action, MessageTarget target, params string[] description)
        {
            try
            {
                var message = new EventMessage
                {
                    Date        = DateTime.UtcNow,
                    TenantId    = userData == null?CoreContext.TenantManager.GetCurrentTenant().TenantId : userData.TenantId,
                    UserId      = userData == null ? SecurityContext.CurrentAccount.ID                   : userData.UserId,
                    Action      = action,
                    Description = description,
                    Target      = target
                };

                if (headers != null)
                {
                    var ip        = MessageSettings.GetIP(headers);
                    var userAgent = MessageSettings.GetUAHeader(headers);
                    var referer   = MessageSettings.GetReferer(headers);

                    message.IP       = ip;
                    message.UAHeader = userAgent;
                    message.Page     = referer;
                }

                return(message);
            }
            catch (Exception ex)
            {
                log.Error(string.Format("Error while parse Http Message for \"{0}\" type of event: {1}", action, ex));
                return(null);
            }
        }
Ejemplo n.º 2
0
 public EventMessage Create(HttpRequest request, string initiator, MessageAction action, MessageTarget target, params string[] description)
 {
     try
     {
         return(new EventMessage
         {
             IP = request != null ? request.Headers[forwardedHeader].ToString() ?? request.GetUserHostAddress() : null,
             Initiator = initiator,
             Date = DateTime.UtcNow,
             TenantId = TenantManager.GetCurrentTenant().TenantId,
             UserId = AuthContext.CurrentAccount.ID,
             Page = request?.GetTypedHeaders().Referer?.ToString(),
             Action = action,
             Description = description,
             Target = target,
             UAHeader = request.Headers[userAgentHeader].FirstOrDefault()
         });
     }
     catch (Exception ex)
     {
         log.ErrorFormat("Error while parse Http Request for {0} type of event: {1}", action, ex);
         return(null);
     }
 }
 public static void Send(Dictionary <string, string> httpHeaders, MessageAction action, MessageTarget target, IEnumerable <string> d1)
 {
     SendHeadersMessage(null, httpHeaders, action, target, d1 != null ? d1.ToArray() : null);
 }
 public static void Send(MessageInitiator initiator, MessageAction action, MessageTarget target, params string[] description)
 {
     SendInitiatorMessage(null, initiator.ToString(), action, target, description);
 }
 public static void Send(HttpRequest request, string loginName, MessageAction action, MessageTarget target, string d1)
 {
     SendRequestMessage(request, loginName, action, target, d1);
 }
 public static void Send(MessageUserData userData, Dictionary <string, string> httpHeaders, MessageAction action, MessageTarget target)
 {
     SendHeadersMessage(userData, httpHeaders, action, target);
 }
Ejemplo n.º 7
0
 public static void Send(HttpRequest request, DateTime?dateTime, MessageAction action, MessageTarget target, string d1)
 {
     SendRequestMessage(request, null, dateTime, action, target, d1);
 }
 public static void Send(HttpRequest request, MessageAction action, MessageTarget target, string d1, string d2, string d3, string d4)
 {
     SendRequestMessage(request, null, action, target, d1, d2, d3, d4);
 }
Ejemplo n.º 9
0
 public void Send(IDictionary <string, StringValues> httpHeaders, MessageAction action, MessageTarget target, string d1)
 {
     SendHeadersMessage(null, httpHeaders, action, target, d1);
 }
Ejemplo n.º 10
0
 public void Send(IDictionary <string, StringValues> httpHeaders, MessageAction action, MessageTarget target, IEnumerable <string> d1)
 {
     SendHeadersMessage(null, httpHeaders, action, target, d1?.ToArray());
 }
Ejemplo n.º 11
0
 public void Send(MessageUserData userData, IDictionary <string, StringValues> httpHeaders, MessageAction action, MessageTarget target)
 {
     SendHeadersMessage(userData, httpHeaders, action, target);
 }
Ejemplo n.º 12
0
        public static EventMessage Create(MessageUserData userData, Dictionary <string, string> headers, MessageAction action, MessageTarget target, params string[] description)
        {
            try
            {
                var message = new EventMessage
                {
                    Date        = DateTime.UtcNow,
                    TenantId    = userData == null?CoreContext.TenantManager.GetCurrentTenant().TenantId : userData.TenantId,
                    UserId      = userData == null ? SecurityContext.CurrentAccount.ID                   : userData.UserId,
                    Action      = action,
                    Description = description,
                    Target      = target
                };

                if (headers != null)
                {
                    var userAgent = headers.ContainsKey(userAgentHeader) ? headers[userAgentHeader] : null;
                    var forwarded = headers.ContainsKey(forwardedHeader) ? headers[forwardedHeader] : null;
                    var host      = headers.ContainsKey(hostHeader) ? headers[hostHeader] : null;
                    var referer   = headers.ContainsKey(refererHeader) ? headers[refererHeader] : null;

                    var        uaParser = Parser.GetDefault();
                    ClientInfo clientInfo;

                    try
                    {
                        clientInfo = userAgent != null?uaParser.Parse(userAgent) : null;
                    }
                    catch (Exception)
                    {
                        clientInfo = null;
                    }

                    message.IP       = forwarded ?? host;
                    message.Browser  = GetBrowser(clientInfo);
                    message.Platform = GetPlatform(clientInfo);
                    message.Page     = referer;
                }

                return(message);
            }
            catch (Exception ex)
            {
                log.Error(string.Format("Error while parse Http Message for \"{0}\" type of event: {1}", action, ex));
                return(null);
            }
        }
Ejemplo n.º 13
0
        public static EventMessage Create(HttpRequest request, string initiator, MessageAction action, MessageTarget target, params string[] description)
        {
            try
            {
                var clientInfo = (ClientInfo)null;
                if (request != null)
                {
                    try
                    {
                        var uaParser  = Parser.GetDefault();
                        var userAgent = request.Headers[userAgentHeader];
                        clientInfo = userAgent != null?uaParser.Parse(userAgent) : null;
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                }

                return(new EventMessage
                {
                    IP = request != null ? request.Headers[forwardedHeader] ?? request.UserHostAddress : null,
                    Initiator = initiator,
                    Browser = GetBrowser(clientInfo),
                    Platform = GetPlatform(clientInfo),
                    Date = DateTime.UtcNow,
                    TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId,
                    UserId = SecurityContext.CurrentAccount.ID,
                    Page = request != null && request.UrlReferrer != null?request.UrlReferrer.ToString() : null,
                               Action = action,
                               Description = description,
                               Target = target
                });
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Error while parse Http Request for {0} type of event: {1}", action, ex);
                return(null);
            }
        }
Ejemplo n.º 14
0
        public EventMessage Create(MessageUserData userData, IDictionary <string, StringValues> headers, MessageAction action, MessageTarget target, params string[] description)
        {
            try
            {
                var message = new EventMessage
                {
                    Date        = DateTime.UtcNow,
                    TenantId    = userData == null?TenantManager.GetCurrentTenant().TenantId : userData.TenantId,
                    UserId      = userData == null ? AuthContext.CurrentAccount.ID           : userData.UserId,
                    Action      = action,
                    Description = description,
                    Target      = target
                };

                if (headers != null)
                {
                    var userAgent = headers.ContainsKey(userAgentHeader) ? headers[userAgentHeader].ToString() : null;
                    var forwarded = headers.ContainsKey(forwardedHeader) ? headers[forwardedHeader].ToString() : null;
                    var host      = headers.ContainsKey(hostHeader) ? headers[hostHeader].ToString() : null;
                    var referer   = headers.ContainsKey(refererHeader) ? headers[refererHeader].ToString() : null;

                    message.IP       = forwarded ?? host;
                    message.UAHeader = userAgent;
                    message.Page     = referer;
                }

                return(message);
            }
            catch (Exception ex)
            {
                log.Error(string.Format("Error while parse Http Message for \"{0}\" type of event: {1}", action, ex));
                return(null);
            }
        }
Ejemplo n.º 15
0
 public void Send(MessageAction action, MessageTarget target)
 {
     SendRequestMessage(null, action, target);
 }
 public static void Send(HttpRequest request, MessageAction action, MessageTarget target)
 {
     SendRequestMessage(request, null, action, target);
 }
Ejemplo n.º 17
0
 public void Send(MessageAction action, MessageTarget target, string d1)
 {
     SendRequestMessage(null, action, target, d1);
 }
 public static void Send(HttpRequest request, MessageAction action, MessageTarget target, IEnumerable <string> d1)
 {
     SendRequestMessage(request, null, action, target, string.Join(", ", d1));
 }
Ejemplo n.º 19
0
 public void Send(MessageAction action, MessageTarget target, string d1, string d2, string d3, string d4)
 {
     SendRequestMessage(null, action, target, d1, d2, d3, d4);
 }
        private static void SendRequestMessage(HttpRequest request, string loginName, MessageAction action, MessageTarget target, params string[] description)
        {
            if (sender == null)
            {
                return;
            }

            if (request == null)
            {
                log.Debug(string.Format("Empty Http Request for \"{0}\" type of event", action));
                return;
            }

            var message = MessageFactory.Create(request, loginName, action, target, description);

            if (!MessagePolicy.Check(message))
            {
                return;
            }

            sender.Send(message);
        }
Ejemplo n.º 21
0
 public void Send(MessageAction action, MessageTarget target, string d1, string d2, IEnumerable <string> d3)
 {
     SendRequestMessage(null, action, target, d1, d2, string.Join(", ", d3));
 }
 public static void Send(Dictionary <string, string> httpHeaders, MessageAction action, MessageTarget target, string d1)
 {
     SendHeadersMessage(null, httpHeaders, action, target, d1);
 }
Ejemplo n.º 23
0
 public void Send(string loginName, MessageAction action, MessageTarget target, string d1)
 {
     SendRequestMessage(loginName, action, target, d1);
 }
        private static void SendHeadersMessage(MessageUserData userData, Dictionary <string, string> httpHeaders, MessageAction action, MessageTarget target, params string[] description)
        {
            if (sender == null)
            {
                return;
            }

            var message = MessageFactory.Create(userData, httpHeaders, action, target, description);

            if (!MessagePolicy.Check(message))
            {
                return;
            }

            sender.Send(message);
        }
Ejemplo n.º 25
0
 public static EventMessage Create(HttpRequest request, string initiator, MessageAction action, MessageTarget target, params string[] description)
 {
     try
     {
         return(new EventMessage
         {
             IP = request != null ? request.Headers[forwardedHeader] ?? request.UserHostAddress : null,
             Initiator = initiator,
             Date = DateTime.UtcNow,
             TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId,
             UserId = SecurityContext.CurrentAccount.ID,
             Page = request != null && request.UrlReferrer != null?request.UrlReferrer.ToString() : null,
                        Action = action,
                        Description = description,
                        Target = target,
                        UAHeader = request != null ? request.Headers[userAgentHeader] : null
         });
     }
     catch (Exception ex)
     {
         log.ErrorFormat("Error while parse Http Request for {0} type of event: {1}", action, ex);
         return(null);
     }
 }
        private static void SendInitiatorMessage(HttpRequest request, string initiator, MessageAction action, MessageTarget target, params string[] description)
        {
            if (sender == null)
            {
                return;
            }

            var message = MessageFactory.Create(request, initiator, action, target, description);

            if (!MessagePolicy.Check(message))
            {
                return;
            }

            sender.Send(message);
        }
Ejemplo n.º 27
0
 public static EventMessage Create(HttpRequest request, string initiator, DateTime?dateTime, MessageAction action, MessageTarget target, params string[] description)
 {
     try
     {
         return(new EventMessage
         {
             IP = MessageSettings.GetIP(request),
             Initiator = initiator,
             Date = dateTime.HasValue ? dateTime.Value : DateTime.UtcNow,
             TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId,
             UserId = SecurityContext.CurrentAccount.ID,
             Page = MessageSettings.GetUrlReferer(request),
             Action = action,
             Description = description,
             Target = target,
             UAHeader = MessageSettings.GetUAHeader(request)
         });
     }
     catch (Exception ex)
     {
         log.ErrorFormat("Error while parse Http Request for {0} type of event: {1}", action, ex);
         return(null);
     }
 }