Ejemplo n.º 1
0
        private void recordStatistic(Url url)
        {
            var stat = new UrlStatistic
            {
                ShortUrlId = url.id.ToString(),
                IpAddress  = Request.HttpContext.Connection.RemoteIpAddress.ToString(),
                RefererUrl = url.OriginalUrl,
                CreatedAt  = DateTime.Now
            };

            ilogger.LogInformation
            (
                $"Short : {url.shortUrl}\n" +
                $"Origin : {stat.RefererUrl}\n" +
                $"Accessed from {stat.IpAddress}"
            );

            db.UrlStatistic.Add(stat);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        public static UrlStatistic build(ClientInfo clientInfo, HttpContext context)
        {
            UrlStatistic urlStatistic = new UrlStatistic();

            //add basic info about user browser,device and OS
            urlStatistic.BrowserFamily       = clientInfo.UserAgent.Family;
            urlStatistic.BrowserMajorVersion = clientInfo.UserAgent.Major;
            urlStatistic.OSFamily            = clientInfo.OS.Family;
            urlStatistic.OSMajorVersion      = clientInfo.OS.Major;
            urlStatistic.OSMinorVersion      = clientInfo.OS.Minor;
            urlStatistic.DeviceBrand         = clientInfo.Device.Brand;
            urlStatistic.DeviceModel         = clientInfo.Device.Model;

            //add info about bot services
            urlStatistic.BotService = clientInfo.Device.IsSpider;

            //ad some network info
            urlStatistic.IPAddress = context.Connection.RemoteIpAddress.ToString();

            //add info about date and time of event
            urlStatistic.EventDate = DateTime.UtcNow.ToLocalTime();

            return(urlStatistic);
        }