/// <summary> /// WURFLClientCapability constructor /// </summary> public WURFLClientCapability(DeviceInfoClientCapability deviceInfoClientCapability) { if (deviceInfoClientCapability != null) { ID = deviceInfoClientCapability.DeviceInfo.DeviceId; IsMobile = deviceInfoClientCapability.IsMobile; IsTablet = deviceInfoClientCapability.IsTablet; IsTouchScreen = deviceInfoClientCapability.IsTouchScreen; ScreenResolutionWidthInPixels = deviceInfoClientCapability.ScreenResolutionWidthInPixels; ScreenResolutionHeightInPixels = deviceInfoClientCapability.ScreenResolutionHeightInPixels; SupportsFlash = deviceInfoClientCapability.SupportsFlash; BrowserName = deviceInfoClientCapability.BrowserName; HtmlPreferedDTD = deviceInfoClientCapability.HtmlPreferedDTD; Capabilities = deviceInfoClientCapability.Capabilities; } }
private const int UserAgentsCacheTimeout = 60; //user agents cache expire time.(minutes) /// <summary> /// Returns ClientCapability based on HttpRequest /// </summary> public override IClientCapability GetClientCapability(string userAgent) { DeviceInfoClientCapability deviceInfoClientCapability = null; if (!string.IsNullOrEmpty(userAgent)) { bool found = false; //try to get content from cache var cachedUserAgents = DataCache.GetCache<SharedDictionary<string, DeviceInfoClientCapability>>(UserAgentsCacheKey); if (cachedUserAgents != null) { using (cachedUserAgents.GetReadLock()) { if (cachedUserAgents.ContainsKey(userAgent)) { deviceInfoClientCapability = cachedUserAgents[userAgent]; found = true; } } } if (!found) { var deviceInfo = WurflProvider.GetDeviceInfo(userAgent); if (deviceInfo != null) { deviceInfoClientCapability = new DeviceInfoClientCapability(deviceInfo); //update cache content if(cachedUserAgents == null) { cachedUserAgents = new SharedDictionary<string, DeviceInfoClientCapability>(); } using (cachedUserAgents.GetWriteLock()) { cachedUserAgents[userAgent] = deviceInfoClientCapability; } DataCache.SetCache(UserAgentsCacheKey, cachedUserAgents, TimeSpan.FromMinutes(UserAgentsCacheTimeout)); } } } var wurflClientCapability = new WURFLClientCapability(deviceInfoClientCapability); wurflClientCapability.UserAgent = userAgent; return wurflClientCapability; }