/// <summary> /// Gets the device for the user. /// </summary> /// <param name="httpContextBase">The HTTP context base.</param> /// <returns>DeviceTypes.</returns> /// <exception cref="System.ApplicationException">[DeviceInfo detection] No license key found. Add an appsetting called \wurfl: apikey\ with your cloud service key.</exception> public IDeviceInfo GetDevice(HttpContextBase httpContextBase) { IDeviceInfo deviceInfo = new DeviceInfo(); if (httpContextBase == null) { return(deviceInfo); } if (string.IsNullOrWhiteSpace(ApiKey)) { throw new ApplicationException( "[DeviceInfo detection] No license key found. Add an appsetting called \"wurfl: apikey\" with your cloud service key."); } bool isFullVersion; bool.TryParse(FullVersion, out isFullVersion); DefaultCloudClientConfig config = new DefaultCloudClientConfig { ApiKey = ApiKey }; CloudClientManager manager = new CloudClientManager(config); ScientiaMobile.WurflCloud.Device.DeviceInfo device = isFullVersion ? manager.GetDeviceInfo(httpContextBase) : manager.GetDeviceInfo(httpContextBase, new[] { "complete_device_name, form_factor, is_mobile" }); return(new WurflAdapter(device, isFullVersion)); }
/// <summary> /// Initializes a new instance of the <see cref="WurflAdapter" /> class. /// </summary> /// <param name="deviceInfo">The <see cref="ScientiaMobile.WurflCloud.Device.DeviceInfo" /> for the visitor.</param> /// <param name="isFullVersion">if set to <c>true</c> [is full version].</param> public WurflAdapter(ScientiaMobile.WurflCloud.Device.DeviceInfo deviceInfo, bool isFullVersion) { // Desktop, App, Tablet, Smartphone, Feature Phone, Smart-TV, Robot, Other non-Mobile, Other Mobile this.DeviceType = deviceInfo.Get("form_factor"); bool isMobile; bool.TryParse(deviceInfo.Get("is_mobile"), out isMobile); this.IsMobile = isMobile; if (isFullVersion) { int screenPixelsWidth; int.TryParse(deviceInfo.Get("resolution_width"), out screenPixelsWidth); this.ScreenPixelsWidth = screenPixelsWidth; int screenPixelsHeight; int.TryParse(deviceInfo.Get(" resolution_height"), out screenPixelsHeight); this.ScreenPixelsHeight = screenPixelsHeight; bool isTv; bool.TryParse(deviceInfo.Get("is_smarttv"), out isTv); this.IsTv = isTv; bool isSmartWatch; bool.TryParse(deviceInfo.Get("is_smartwatch"), out isSmartWatch); // Not available in wurfl this.IsSmartWatch = isSmartWatch; bool isSmartPhone; bool.TryParse(deviceInfo.Get("is_smartphone"), out isSmartPhone); this.IsSmartPhone = isSmartPhone; bool isLargeScreen; bool.TryParse(deviceInfo.Get("is_largescreen"), out isLargeScreen); this.IsSmallScreen = !isLargeScreen; bool isMediaHub; bool.TryParse(deviceInfo.Get("is_mediahub"), out isMediaHub); // Not available in wurfl this.IsMediaHub = isMediaHub; bool isEReader; bool.TryParse(deviceInfo.Get("is_ereader"), out isEReader); // Not available in wurfl this.IsEReader = isEReader; bool isConsole; bool.TryParse(deviceInfo.Get("is_console"), out isConsole); this.IsConsole = isConsole; bool isTablet; bool.TryParse(deviceInfo.Get("is_tablet"), out isTablet); this.IsTablet = isTablet; return; } switch (this.DeviceType) { case "Tablet": this.IsTablet = true; break; case "Smartphone": this.IsSmartPhone = true; break; case "Smart-TV": this.IsTv = true; break; } }