protected override DeviceInformation DoGetDeviceInformation(string userAgent)
        {
            Assert.ArgumentNotNull(userAgent, "userAgent");

            using (new ReadScope(_readerWriterLockSlim))
            {
                var dd = new DeviceDetector(userAgent);
                dd.Parse();

                var        browserMatchResult = dd.GetBrowserClient().Match;
                DeviceType deviceType         = DeviceType.Computer;
                if (dd.IsMobile())
                {
                    deviceType = DeviceType.MobilePhone;
                }

                DeviceInformation deviceInformation = new DeviceInformation
                {
                    Browser            = browserMatchResult?.Name ?? "desktop",
                    DeviceIsSmartphone = dd.IsMobile(),
                    DeviceModelName    = dd.GetDeviceName(),
                    DeviceType         = deviceType,
                    DeviceVendor       = dd.GetModel()
                };

                return(deviceInformation);
            }
        }
Beispiel #2
0
        /// <summary>
        /// this library get device and user related details to perform first level authentication
        /// </summary>
        /// <param name="userAgent"></param>
        /// <returns>DeviceInfo</returns>
        public static DeviceInfo Get(string userAgent)
        {
            var deviceInfo = new DeviceInfo();
            var client     = new ClientModel();
            var bot        = new BotModel();
            var os         = new OsInfo();
            var device     = new DeviceDetector(userAgent);

            device.SetCache(new DictionaryCache());
            device.Parse();
            if (device.IsBot())
            {
                // checks if the user is a bot or crawler and retrieve the info
                var botInfo = device.GetBot();
                bot.Success     = botInfo.Success;
                bot.Name        = botInfo.Matches[0].Name ?? botInfo.Match?.Name;
                bot.Producer    = botInfo.Matches[0].Producer.Name ?? botInfo.Match?.Producer.Name;
                bot.ProducerUrl = botInfo.Matches[0].Producer.Url ?? botInfo.Match?.Producer.Url;
                bot.Url         = botInfo.Matches[0].Url ?? botInfo.Match?.Url;
            }

            else
            {//if its not a bot get client info
                var clientInfo = device.GetClient();
                client.Name    = clientInfo.Matches[0]?.Name ?? clientInfo.Match?.Name;
                client.Type    = clientInfo.Matches[0]?.Type ?? clientInfo.Match?.Type;
                client.Version = clientInfo.Matches[0]?.Version ?? clientInfo.Match?.Version;
                client.Success = clientInfo.Success;


                // holds information about browser, feed reader, media player, ...
                var osInfo = device.GetOs();
                os.Name                = osInfo.Matches[0]?.Name ?? osInfo.Match?.Name;
                os.Version             = osInfo.Match?.Version ?? osInfo.Matches[0]?.Version ?? osInfo.Match?.Version;
                os.PlatForm            = osInfo.Match?.Platform ?? osInfo.Matches[0]?.Platform ?? osInfo.Match?.Platform;
                os.ShortName           = osInfo.Match?.ShortName ?? osInfo.Matches[0]?.ShortName ?? osInfo.Match?.ShortName;
                os.Success             = osInfo.Success;
                client.DeviceName      = device.GetDeviceName();
                client.DeviceBrandName = device.GetBrandName();
                client.DeviceModel     = device.GetModel();
            }

            client.IsDesktop  = device.IsDesktop();
            client.IsMobile   = device.IsMobile();
            deviceInfo.Bot    = bot;
            deviceInfo.Client = client;
            deviceInfo.OsInfo = os;
            return(deviceInfo);
        }
        public UserAgentDetectorItem getInfo(string userAgent)
        {
            DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);
            DeviceDetector deviceDetector = new DeviceDetector(userAgent);

            deviceDetector.Parse();
            UserAgentDetectorItem userAgentItem        = new UserAgentDetectorItem();
            DeviceDetectorResult  deviceDetectorResult = ((DeviceDetectorResult)DeviceDetector.GetInfoFromUserAgent(userAgent).Match);

            ClientMatchResult client = deviceDetector.GetClient().Match;

            userAgentItem.client_summary = client.Name + " " + client.Version;

            userAgentItem.ua_family  = deviceDetectorResult.BrowserFamily;
            userAgentItem.ua_version = client.Version;

            userAgentItem.os_family  = deviceDetectorResult.Os.Name;
            userAgentItem.os_version = deviceDetectorResult.Os.Version;

            userAgentItem.ua_type  = deviceDetector.GetClient().Match.Type;
            userAgentItem.bot_info = deviceDetector.IsBot();

            userAgentItem.os_meta            = new Os_meta();
            userAgentItem.os_meta.name       = deviceDetectorResult.Os.Name;
            userAgentItem.os_meta.short_name = deviceDetectorResult.Os.ShortName;
            userAgentItem.os_meta.version    = deviceDetectorResult.Os.Version;
            userAgentItem.os_meta.platform   = deviceDetectorResult.Os.Platform;

            /* String[] info = client.ToString().Split("\n");
             * userAgentItem.ua_rendering_engine = info.Length > 4 ? info[4] : "";
             * userAgentItem.ua_rendering_engine_version = info.Length > 5 ? info[5] : "";*/

            userAgentItem.device            = new Device();
            userAgentItem.device.is_mobile  = deviceDetector.IsMobile();
            userAgentItem.device.is_tablet  = deviceDetector.IsTablet();
            userAgentItem.device.is_desktop = deviceDetector.IsDesktop();
            userAgentItem.device.brand      = deviceDetectorResult.DeviceBrand;
            userAgentItem.device.model      = deviceDetectorResult.DeviceModel;

            userAgentItem.client      = new Client();
            userAgentItem.client.bot  = deviceDetector.IsBot();
            userAgentItem.client.user = !deviceDetector.IsBot();
            return(userAgentItem);
        }
Beispiel #4
0
        public ParsedUA ParseUA()
        {
            string ua;

            if (string.IsNullOrEmpty(UserAgent))
            {
                ua = Request.Headers["User-Agent"].ToString();
            }
            else
            {
                ua = UserAgent;
            }

            ParsedUA result = new ParsedUA();

            var dd = new DeviceDetector(ua);

            dd.Parse();

            if (dd.IsBot())
            {
                result.IsBot = true;
                result.Bot   = dd.GetBot().Match;
            }
            else
            {
                result.Client            = dd.GetClient().Match;
                result.Os                = dd.GetOs().Match;
                result.Device.DeviceName = dd.GetDeviceName();
                result.Device.Model      = dd.GetModel();
                result.Device.IsDesktop  = dd.IsDesktop();
                result.Device.IsMobile   = dd.IsMobile();
            }

            return(result);
        }