Esempio n. 1
0
        public void Parse(UserEventData userEvent)
        {
            userEvent.IsTablet = false;
            userEvent.IsMobile = false;
            userEvent.IsAndroid = false;
            userEvent.IsiOS = false;

                var uaString = userEvent.UserAgent;

                if (!string.IsNullOrWhiteSpace(uaString))
                {
                    uaString = WebUtility.HtmlEncode(uaString.ReplaceInvalidChars());

                    using (var client = new WebClient())
                    {
                        var jsonString = client.DownloadString(string.Format(_parseServiceUrl, uaString));
                        var result = JsonConvert.DeserializeObject<ParseResult>(jsonString) as ParseResult;

                        userEvent.IsTablet = result.IsTablet;
                        userEvent.IsMobile = result.IsMobile;
                        userEvent.IsAndroid = result.IsAndroid;
                        userEvent.IsiOS = result.IsiOS;
                    }
                }
        }
Esempio n. 2
0
        public void Handle(UserEventData userEvent)
        {
            try
            {
                _logger.Info(userEvent.UserEventActionId == UserEventData.UserEventType.Open ? OpenEventReceivedMsg : ClickEventReceivedMsg, userEvent.batch_id, userEvent.subscriber_id, userEvent.list_id);

                //
                // Notes:
                // - We want to count even missing / invalid UserAgent requests
                //
                if (string.IsNullOrEmpty(userEvent.UserAgent))
                {
                    userEvent.UserAgent = InvalidOrMissingUserAgentMsg;
                    userEvent.IsMobile = false;
                    userEvent.IsTablet = false;
                    userEvent.IsiOS = false;
                    userEvent.IsAndroid = false;
                    
                    _logger.Info(InvalidOrMissingUserAgentMsg);
                }
                else
                {
                    //
                    // Notes:
                    //  DO NOT stop the process / message processing because of incorrect User Agent Strings !
                    try
                    {
                        var parser = new UserAgentParser(string.Format("{0}&requestedCapabilities={1}", _settings.ParsingServiceUrl, _settings.ParsingRequestedCapabilities));
                        parser.Parse(userEvent);
                        userEvent.ValidateUserAgent();
                    }
                    catch (Exception e)
                    {
                        _logger.Error(ErrorParsingUserAgentMsg, userEvent.UserAgent, e.Message);
                    }
                }

                using (var context = new UserEventContext())
                {
                    var repository = new Repository<UserEventContext>(context);
                    repository.Create(userEvent);

                    using (var uow = new UnitOfWork<UserEventContext>(context))
                    {
                        uow.Commit();
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error("Error(s) found during a user event processing: {0}", e.Dump());
                throw;
            }
        }
Esempio n. 3
0
 private void ProcessUserEventData(UserEventData userEvent)
 {
     new UserEventHandler(_logger, _settings).Handle(userEvent);
 }