Пример #1
0
 /// <summary>
 /// Returns the number of bits per pixel as a long, or 16 if not found.
 /// </summary>
 /// <param name="device"></param>
 /// <returns></returns>
 private long GetBitsPerPixel(BaseDeviceInfo device)
 {
     long bitsPerPixel = 1;
     if (long.TryParse(
         _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(BitsPerPixel)), 
         out bitsPerPixel))
         return bitsPerPixel;
     return 16;
 }
Пример #2
0
 private string GetMobileDeviceModel(BaseDeviceInfo device)
 {
     string value = _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(HardwareModel));
     if (String.IsNullOrEmpty(value))
         value = _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(HardwareName));
     return value;
 }
Пример #3
0
 private string GetMobileDeviceManufacturer(BaseDeviceInfo device)
 {
     return _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(HardwareVendor));
 }
Пример #4
0
 private string GetIsMobileDevice(BaseDeviceInfo device)
 {
     int value = device.GetFirstPropertyValueStringIndex(IsMobile);
     if (value == this.True[0] || value == this.True[1])
         return bool.TrueString.ToLowerInvariant();
     return bool.FalseString.ToLowerInvariant();
 }
Пример #5
0
 private string GetScreenPixelsWidth(BaseDeviceInfo device)
 {
     int size;
     string value = _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(ScreenPixelsWidth));
     if (int.TryParse(value, out size))
         return value;
     return null;
 }
Пример #6
0
 private string GetPlatform(BaseDeviceInfo device)
 {
     return _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(PlatformName));
 }
Пример #7
0
 private string GetAdapters(BaseDeviceInfo device)
 {
     return _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(Adapters));
 }
Пример #8
0
        /// <summary>
        /// Get the javascript version or null if not provided or invalid.
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        private string GetJavascriptVersion(BaseDeviceInfo device)
        {
            var index = device.GetFirstPropertyValueStringIndex(JavascriptVersion);
            if (index < 0)
                return null;

            string value = _provider.Strings.Get(index);

            // Check if the version value is valid in the version
            // class. If not then return null.
#if VER2
            try
            {
                new Version(value);
                return value;
            }
            catch
            {
                return null;
            }
#else
            Version version;
            if (Version.TryParse(value, out version))
                return value;
            return null;
#endif
        }
Пример #9
0
 /// <summary>
 /// If the device indicates javascript support then return true.
 /// </summary>
 /// <param name="device">The device to be checked.</param>
 /// <returns>True if javascript is supported.</returns>
 private object GetJavascriptSupport(BaseDeviceInfo device)
 {
     int value = device.GetFirstPropertyValueStringIndex(Javascript);
     if (value < 0)
         return null;
     return value == this.True[0] || value == this.True[1];
 }
Пример #10
0
 private string GetCookieSupport(BaseDeviceInfo device, string current)
 {
     bool value = false;
     // Return either the capability or the current value as a boolean string.
     if (bool.TryParse(_provider.Strings.Get(device.GetFirstPropertyValueStringIndex(CookiesCapable)), out value) == false)
         bool.TryParse(current, out value);
     return value.ToString();
 }
Пример #11
0
        /// <summary>
        /// Returns true if the device supports tables.
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        private object GetTablesCapable(BaseDeviceInfo device)
        {
            int value = device.GetFirstPropertyValueStringIndex(TablesCapable);
            if (value < 0)
                return null;

            if (value == this.True[0] || value == this.True[1])
                return bool.TrueString.ToLowerInvariant();
            return bool.FalseString.ToLowerInvariant(); 
        }
Пример #12
0
        /// <summary>
        /// Updates the capabilities used by Microsoft's implementation of the
        /// HttpBrowserCapabilities class to control the property values it
        /// returns. Only properties exposed by FiftyOneBrowserCapabilities are overriden
        /// by this method.
        /// </summary>
        /// <param name="capabilities">Dictionary of capabilities to be enhanced.</param>
        /// <param name="currentCapabilities">Dictionary of existing capabilities for the device.</param>
        /// <param name="device">Device to use for enhancements.</param>
        private void Enhance(IDictionary capabilities, IDictionary currentCapabilities, BaseDeviceInfo device)
        {
            // Set base capabilities for all mobile devices.
            SetStaticValues(capabilities);

            SetValue(capabilities, "isMobileDevice", GetIsMobileDevice(device));
            SetValue(capabilities, "crawler", GetIsCrawler(device));
            SetValue(capabilities, "mobileDeviceModel", GetMobileDeviceModel(device));
            SetValue(capabilities, "mobileDeviceManufacturer", GetMobileDeviceManufacturer(device));
            SetValue(capabilities, "platform", GetPlatform(device));
            SetValue(capabilities, "type", capabilities["mobileDeviceManufacturer"]);
            SetValue(capabilities, "screenPixelsHeight", GetScreenPixelsHeight(device));
            SetValue(capabilities, "screenPixelsWidth", GetScreenPixelsWidth(device));
            SetValue(capabilities, "screenBitDepth", GetBitsPerPixel(device));
            SetValue(capabilities, "preferredImageMime", GetPreferredImageMime(device, capabilities));
            SetValue(capabilities, "isColor", GetIsColor(device));
            SetValue(capabilities, "SupportsCallback", GetSupportsCallback(device));
            SetValue(capabilities, "canInitiateVoiceCall", GetIsMobileDevice(device));
            SetValue(capabilities, "jscriptversion", GetJavascriptVersion(device));

            // Use the Version class to find the version. If this fails use the 1st two
            // decimal segments of the string.
            string versionString = _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(BrowserVersion));
            if (String.IsNullOrEmpty(versionString) == false)
            {
                try
                {
                    Version version = new Version(versionString);
                    SetValue(capabilities, "majorversion", version.Major.ToString());
                    SetValue(capabilities, "minorversion", String.Format(".{0}", version.Minor));
                    SetValue(capabilities, "version", version.ToString());
                }
                catch (FormatException)
                {
                    SetVersion(capabilities, versionString);
                }
                catch (ArgumentException)
                {
                    SetVersion(capabilities, versionString);
                }
            }
            else
            {
                // Transfer the current version capabilities to the new capabilities.
                SetValue(capabilities, "majorversion", currentCapabilities != null ? currentCapabilities["majorversion"] : null);
                SetValue(capabilities, "minorversion", currentCapabilities != null ? currentCapabilities["minorversion"] : null);
                SetValue(capabilities, "version", currentCapabilities != null ? currentCapabilities["version"] : null);

                // Ensure the version values are not null to prevent null arguement exceptions
                // with some controls.
                versionString = currentCapabilities != null ? currentCapabilities["version"] as string : "0.0";
                SetVersion(capabilities, versionString);
            }

            // All we can determine from the device database is if javascript is supported as a boolean.
            // If the value is not provided then null is returned and the capabilities won't be altered.
            object javaScript = GetJavascriptSupport(device);
            if (javaScript is bool)
            {
                SetJavaScript(capabilities, (bool)javaScript);
                SetValue(capabilities, "ecmascriptversion",
                         (bool)javaScript ? "3.0" : "0.0");
            }

            // Update the cookies value if we have additional information.
            SetValue(capabilities, "cookies",
                    GetCookieSupport(device,
                                     currentCapabilities != null
                                         ? (string)currentCapabilities["cookies"]
                                         : String.Empty));

            // Only set these values from 51Degrees.mobi if they've not already been set from
            // the Http request header, or the .NET solution.
            if (capabilities.Contains("preferredRenderingType") == false)
            {
                // Set the rendering type for the response.
                SetValue(capabilities, "preferredRenderingType", GetPreferredHtmlVersion(device));

                // Set the Mime type of the response.
                SetValue(capabilities, "preferredRenderingMime", "text/html");
            }
        }