예제 #1
0
        private static DeviceInfo ParseAndroidTablet(string userAgent, string[] platformInfo)
        {
            var result = new DeviceInfo
            {
                PlarformType = PlarformType.Android,
                FormFactor = FormFactor.Tablet,
                OsVersion = null
            };

            var browserDataString = userAgent.SubstringFromChar(')', 1);


            if (browserDataString == null)
            {
                browserDataString = userAgent.SubstringFromChar(')');

                var bd = browserDataString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var bi = bd.FirstOrDefault(itm => itm.StartsWith("Firefox"));
                if (bi != null)
                {
                    result.AppHost = ApplicationHost.Firefox;
                    result.AppVersion = bi.SubstringFromChar('/');
                    return result;
                }

                return UnknownPlatform;
            }



            var browserData = browserDataString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("Chrome"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Chrome;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }

            browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("Version"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Android;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }

            return result;
        }
예제 #2
0
        private static DeviceInfo ParseLG_P503(string userAgent)
        {

            var data = userAgent.Split(' ');

            var result = new DeviceInfo
            {
                PlarformType = PlarformType.Android,
                FormFactor = FormFactor.Mobile,
                AppHost = ApplicationHost.Android,
            };


            var androidData = data.FirstOrDefault(itm => itm.StartsWith("Android"));
            if (androidData != null)
            {
                result.OsVersion = androidData.SubstringFromString("Android/");
            }

            return result;

        }
예제 #3
0
        private static DeviceInfo ParseNative(string userAgent)
        {
            var platformInfo = userAgent.SubstringBetween('(', ')').Split(';').Select(itm => itm.Trim()).ToArray();

            var result = new DeviceInfo
            {
                FormFactor = FormFactor.Mobile,
                AppHost = ApplicationHost.Native
            };


            if (platformInfo.Any(itm => itm.StartsWith("WinPhone")))
            {  
               result.PlarformType = PlarformType.Windows; 
            }
            else if (platformInfo.Any(itm => itm.StartsWith("Android")))
            {
                result.PlarformType = PlarformType.Android;
            }

            return result;

        }
예제 #4
0
        private static DeviceInfo ParseMacintosh(string userAgent, string[] platformInfo)
        {
            var result = new DeviceInfo
            {
                PlarformType = PlarformType.Apple,
                FormFactor = FormFactor.Desktop,
                OsVersion = WindowsOsNumberToName(platformInfo.FirstOrDefault(itm => itm.Contains("Mac OS X")))
            };



            var browserData = userAgent.SubstringFromChar(')', 1)
               .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("Chrome"));

            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Chrome;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }

            browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("Version"));

            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Safari;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }

            return result;

        }
예제 #5
0
        private static DeviceInfo ParseWindowsPhone(string userAgent, string[] platformInfo)
        {
            var result = new DeviceInfo
            {
                PlarformType = PlarformType.Windows,
                FormFactor = FormFactor.Mobile,
                OsVersion = WindowsOsNumberToName(platformInfo.First(itm => itm.StartsWith("Windows Phone")).SubstringFromString("Windows Phone "))
            };

            var ieData = platformInfo.FirstOrDefault(itm => itm.StartsWith("IEMobile"));
            if (ieData != null)
            {
                result.AppHost = ApplicationHost.Ie;
                result.AppVersion = ieData.SubstringFromString("IEMobile/");
                return result;
            }


            return result;

        }
예제 #6
0
        private static DeviceInfo ParseIphoneIPad(string userAgent, string[] platformInfo, FormFactor formFactor)
        {
            var result = new DeviceInfo
            {
                PlarformType = PlarformType.Apple,
                FormFactor = formFactor,
                OsVersion = null
            };

            var browserData = userAgent.SubstringFromChar(')', 1)
   .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("CriOS"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Chrome;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }

            browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("OPiOS"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Opera;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }



            browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("UCBrowser"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.UcBrowser;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }

            browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("MicroMessenger"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.WeChat;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }
            
            browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("Version"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Safari;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }


            return result;

        }
예제 #7
0
        private static DeviceInfo ParseMozillaWindows(string userAgent, string[] platformInfo)
        {

            var result = new DeviceInfo
            {
                PlarformType = PlarformType.Windows,
                Architecture = platformInfo.Any(itm => itm == "WOW64") ? ArchitectureType.X64 : ArchitectureType.X86,
                FormFactor = FormFactor.Desktop,
                OsVersion = WindowsOsNumberToName(platformInfo.First(itm => itm.StartsWith("Windows NT")).SubstringFromString("Windows NT "))
            };


            if (platformInfo.Any(itm => itm.StartsWith("Trident")) || platformInfo.Any(itm => itm.StartsWith(".NET")) || platformInfo.Any(itm => itm.StartsWith("MSIE")))
            {
                var ieData = platformInfo.FirstOrDefault(itm => itm.StartsWith("MSIE"));
                if (ieData != null)
                {
                    result.AppHost = ApplicationHost.Ie;
                    result.AppVersion = ieData.SubstringFromString("MSIE ");
                    return result;
                }

                ieData = platformInfo.FirstOrDefault(itm => itm.StartsWith("rv:"));

                if (ieData != null)
                {
                    result.AppHost = ApplicationHost.Ie;
                    result.AppVersion = ieData.SubstringFromString("rv:");
                    return result;
                }

            }




            var browserDataString = userAgent.SubstringFromChar(')', 1);

            if (browserDataString == null)
            {
                browserDataString = userAgent.SubstringFromChar(')');

                var bd = browserDataString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var bi = bd.FirstOrDefault(itm => itm.StartsWith("Firefox"));
                if (bi != null)
                {
                    result.AppHost = ApplicationHost.Firefox;
                    result.AppVersion = bi.SubstringFromChar('/');
                    return result;
                }

                return UnknownPlatform;
            }


            var browserData = browserDataString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("OPR"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Opera;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }

            browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("Chrome"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Chrome;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }



            browserInfo = browserData.FirstOrDefault(itm => itm.StartsWith("Version"));
            if (browserInfo != null)
            {
                result.AppHost = ApplicationHost.Safari;
                result.AppVersion = browserInfo.SubstringFromChar('/');
                return result;
            }
            

            return result;
        }