/// <summary>
        /// Gets the device for the user.
        /// </summary>
        /// <param name="httpContextBase">The HTTP context base.</param>
        /// <returns>DeviceTypes.</returns>
        public IDeviceInfo GetDevice(HttpContextBase httpContextBase)
        {
            IDeviceInfo deviceInfo = new DeviceInfo();

            if (httpContextBase == null)
            {
                return(deviceInfo);
            }

            try
            {
                string userAgent = httpContextBase.Request.ServerVariables["HTTP_USER_AGENT"];

                IWURFLManager manager = WURFLManagerBuilder.Instance;
                IDevice       device  = WURFLManagerBuilder.Instance.GetDeviceForRequest(userAgent, manager.GetMatchMode());
                return(new WurflAdapter(device));
            }
            catch (NotSupportedException notSupportedException)
            {
                Log.Error(notSupportedException.Message, notSupportedException);
            }
            catch (NotImplementedException notImplementedException)
            {
                Log.Error(notImplementedException.Message, notImplementedException);
            }

            return(deviceInfo);
        }
Esempio n. 2
0
        static DeviceDetector()
        {
            Log.Info("Start: Initializing the WURFL Manager");
            try
            {
                var wurflDataFilePath =
                    HttpContext.Current.Server.MapPath(String.Format("~/{0}", WebConfig.Get <string>("WURFL:DatabaseFilePath")).Replace("//", "/"));
                var configurer = new WURFL.Config.InMemoryConfigurer().MainFile(wurflDataFilePath);

                var patches = WebConfig.Get <string>("WURFL:PatchFilePaths").Split(new[] { '|', ';', ':' }, StringSplitOptions.RemoveEmptyEntries);

                if (patches.Length > 0)
                {
                    foreach (var patch in patches)
                    {
                        var wurflPatchFilePath = HttpContext.Current.Server.MapPath(String.Format("~/{0}", patch).Replace("//", "/"));
                        configurer.PatchFile(wurflPatchFilePath);
                    }
                }

                WurflManager = WURFLManagerBuilder.Build(configurer);
                Log.Info("Stop: Initializing the WURFL Manager");
            }
            catch (Exception ex)
            {
                Log.Error("DeviceDetector() ctor:", ex);
                throw;
            }
        }
Esempio n. 3
0
        public bool DetectCapabilities(HttpRequest httpRequest)
        {
            _manager = WurflLoader.GetManager();
            _device  = _manager.GetDeviceForRequest(httpRequest);

            if (_device != null)
            {
                _capabilityDictionary = new Dictionary <string, string>(_device.GetCapabilities());

                _httpRequest = httpRequest;
                _loaded      = true;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        public void Initial()
        {
            string wurflDataFile  = HttpContext.Current.Server.MapPath(Constants.WurflDataFilePath);
            string wurflPatchFile = HttpContext.Current.Server.MapPath(Constants.WurflPatchFilePath);

            InMemoryConfigurer configurer = new InMemoryConfigurer().MainFile(wurflDataFile).PatchFile(wurflPatchFile);
            IWURFLManager      manager    = WURFLManagerBuilder.Build(configurer);

            AppCtx.Cache.AddObject(Constants.WurflManagerCacheKey, manager);

            #region 初始化所有的设备组实现类
            if (deviceGroups == null)
            {
                deviceGroups = new List <IDeviceGroup>();
            }
            if (deviceGroups.Count == 0)
            {
                GeneralConfigInfo si = GeneralConfigs.GetConfig();
                if (string.IsNullOrEmpty(si.DeviceGroups))
                {
                    Exception ex = new Exception("请配置IDeviceGroup设备组接口的实现类,在general.config里配置。");
                    Framework.LogHelper.WriteLog(GetType(), ex);
                    throw ex;
                }
                string[] DeviceGroups = si.DeviceGroups.Split(';');
                foreach (string s in DeviceGroups)
                {
                    Assembly     assembly  = Assembly.Load(s.Split(',')[1]);
                    string       className = s.Split(',')[0];
                    IDeviceGroup gGroup    = (IDeviceGroup)assembly.CreateInstance(className, true);
                    gGroup.Initial();
                    deviceGroups.Add(gGroup);
                }
                deviceGroups.Sort(new DeviceGroupComparer());
                deviceGroups.Reverse();
            }

            #endregion
        }
Esempio n. 5
0
    static MobileActionFilterAttribute()
    {
        IWURFLConfigurer configurer = new ApplicationConfigurer();

        WurflManager = WURFLManagerBuilder.Build(configurer);
    }