コード例 #1
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;
 }
コード例 #2
0
 private string GetMobileDeviceManufacturer(BaseDeviceInfo device)
 {
     return _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(HardwareVendor));
 }
コード例 #3
0
ファイル: BaseProvider.cs プロジェクト: davelondon/dontstayin
        /// <summary>
        /// Gets an array of handlers that will support the device information.
        /// Device ids are used to determine if the handler supports the device
        /// tree the requested device is within.
        /// </summary>
        /// <param name="device">Device information to find supporting handlers.</param>
        /// <returns>A list of all handlers that can handle this device.</returns>
        private Handler[] GetHandlers(BaseDeviceInfo device)
        {
            byte highestConfidence = 0;
            List<Handler> handlers = new List<Handler>();

#if VER4
            foreach (Handler handler in Handlers.Where(handler => handler.CanHandle(device)))
            {
                GetHandlers(ref highestConfidence, handlers, handler);
            }
#elif VER2
            foreach (Handler handler in Handlers)
            {
                if (handler.CanHandle(device))
                    GetHandlers(ref highestConfidence, handlers, handler);
            }
#endif
            return handlers.ToArray();
        }
コード例 #4
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");
            }
        }
コード例 #5
0
 private void Init(
     BaseProvider devices,
     string deviceId,
     string userAgent,
     BaseDeviceInfo parent)
 {
     _parent = parent;
     Init(devices, deviceId, userAgent);
 }
コード例 #6
0
 /// <summary>
 /// Checks if another BaseDeviceInfo is equal to this one.
 /// </summary>
 /// <param name="other">Other BaseDeviceInfo.</param>
 /// <returns>True if the object instances are the same.</returns>
 internal bool Equals(BaseDeviceInfo other)
 {
     return DeviceId.Equals(other.DeviceId) &&
            UserAgent.Equals(other.UserAgent) &&
            Properties.Equals(other.Properties) &&
            CapabilitiesEquals(other);
 }
コード例 #7
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
        }
コード例 #8
0
 /// <summary>
 /// Constructs a new instance of ClientCapability.
 /// See http://51degrees.mobi/Products/DeviceData/PropertyDictionary.aspx
 /// for a full list of available properties.
 /// All the properties used are non-lists and therefore the first
 /// item contained in the values list contains the only available value.
 /// </summary>
 public FiftyOneClientCapability(BaseDeviceInfo device)
 {
     Initialise(device.GetAllProperties());
     UserAgent = device.UserAgent;
 }
コード例 #9
0
 /// <summary>
 /// Returns true if the device supports callbacks from the browser.
 /// </summary>
 /// <param name="device">The device to be checked.</param>
 /// <returns>True if callback is supported.</returns>
 private string GetSupportsCallback(BaseDeviceInfo device)
 {
     var values = device.GetPropertyValueStringIndexes(AjaxRequestType);
     if (values != null && values.Contains(AjaxRequestTypeNotSupported))
         return bool.FalseString.ToLowerInvariant();
     return bool.TrueString.ToLowerInvariant();
 }
コード例 #10
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];
 }
コード例 #11
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();
 }
コード例 #12
0
        private string GetPreferredHtmlVersion(BaseDeviceInfo device)
        {
            // Working out ASP.NET will support HTML5. Return 4 for the moment.
            return "html4";

            /*

            // Get the list of values.
            var values = new List<double>();
            var versions = device.GetPropertyValueStringIndexes(HtmlVersion);
            if (versions != null)
            {
                foreach (var index in versions)
                {
                    double value;
                    if (double.TryParse(_provider.Strings.Get(index), out value))
                        values.Add(value);
                }
            }
            values.Sort();
            values.Reverse();

            // Find the highest version of HTML supported.
            foreach(double value in values)
            {
                switch (value.ToString())
                {
                    default:
                    case "4":
                        return "html4";
                    case "3.2":
                        return "html32";
                    case "5":
                        return "html5";
                }
            }
 
            // Couldn't find anything return html 4.
            return "html4";
            */
        }
コード例 #13
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(); 
        }
コード例 #14
0
 private string GetPreferredImageMime(BaseDeviceInfo device, IDictionary capabilities)
 {
     var mimeTypes = device.GetPropertyValueStringIndexes(CcppAccept);
     // Look at the database and return the 1st one that matches in order
     // of preference.
     if (Contains(mimeTypes, ImagePng))
         return "image/png";
     if (Contains(mimeTypes, ImageJpeg))
         return "image/jpeg";
     if (Contains(mimeTypes, ImageGif))
         return "image/gif";
     return null;
 }
コード例 #15
0
 private string GetPlatform(BaseDeviceInfo device)
 {
     return _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(PlatformName));
 }
コード例 #16
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;
 }
コード例 #17
0
 private string GetAdapters(BaseDeviceInfo device)
 {
     return _provider.Strings.Get(device.GetFirstPropertyValueStringIndex(Adapters));
 }
コード例 #18
0
 /// <summary>
 /// Creates an instance of <cref see="BaseDeviceInfo"/>.
 /// </summary>
 /// <param name="userAgent">User agent string used to identify this device.</param>
 /// <param name="deviceId">A unique Identifier of the device.</param>
 /// <param name="devices">A reference to the complete index of devices.</param>
 /// <param name="parent">The parent device if one exists.</param>
 internal BaseDeviceInfo(
     BaseProvider devices,
     string deviceId,
     string userAgent,
     BaseDeviceInfo parent)
 {
     Init(devices, deviceId, userAgent, parent);
 }
コード例 #19
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();
 }
コード例 #20
0
 /// <summary>
 /// Returns true if the deviceId is in the parent hierarchy of the 
 /// device.
 /// </summary>
 /// <param name="device">The device being checked.</param>
 /// <returns>True if the device is within the parent hierarchy.</returns>
 internal bool GetIsParent(BaseDeviceInfo device)
 {
     if (this == device)
         return true;
     if (Parent != null)
         return Parent.GetIsParent(device);
     return false;
 }
コード例 #21
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;
 }
コード例 #22
0
 /// <summary>
 /// Check the strings are all equal.
 /// </summary>
 /// <param name="other">Other BaseDeviceInfo.</param>
 /// <returns>True if the object capability strings are the same.</returns>
 private bool CapabilitiesEquals(BaseDeviceInfo other)
 {
     foreach(var key in Properties.Keys)
     {
         if (_provider.Strings.Get(key).Equals(other.Provider.Strings.Get(key)) == false)
             return false;
         foreach(var value in GetPropertyValueStringIndexes(key))
             if (_provider.Strings.Get(value).Equals(other.Provider.Strings.Get(value)) == false)
             return false;
     }
     return true;
 }
コード例 #23
0
 private string GetIsColor(BaseDeviceInfo device)
 {
     long bitsPerPixel = GetBitsPerPixel(device);
     if (bitsPerPixel >= 4)
         return bool.TrueString.ToLowerInvariant();
     return bool.FalseString.ToLowerInvariant();
 }
コード例 #24
0
ファイル: BaseProvider.cs プロジェクト: davelondon/dontstayin
        /// <summary>
        /// Records the device in the indexes used by the API. If a device
        /// with the same ID already exists the previous one is overwritten.
        /// The device is also assigned to a handler based on the useragent,
        /// and supported root devices of the handler.
        /// </summary>
        /// <param name="device">The new device being added.</param>
        internal virtual void Set(BaseDeviceInfo device)
        {
            // Does the device already exist?
            lock (AllDevices)
            {
                int hashCode = device.DeviceId.GetHashCode();
                if (AllDevices.ContainsKey(hashCode))
                {
                    // Yes. Add this device to the list.
                    AllDevices[hashCode].Add(device);
                }
                else
                {
                    // No. So add the new device.
                    AllDevices.Add(hashCode, new List<BaseDeviceInfo>(new[] { device }));
                }
            }

            // Add the new device to handlers that can support it.
            if (String.IsNullOrEmpty(device.UserAgent) == false)
            {
#if VER4
            foreach (Handler handler in GetHandlers(device).Where(handler => handler != null))
            {
                handler.Set(device);
            }
#elif VER2
                foreach (Handler handler in GetHandlers(device))
                    if (handler != null)
                        handler.Set(device);
#endif
            }
        }
コード例 #25
0
        private void Create(BaseDeviceInfo device, IDictionary properties, IDictionary currentProperties)
        {
            // Enhance with the capabilities from the device data.
            if (device != null)
            {
                // Enhance the default capabilities collection based on the device.
                Enhance(properties, currentProperties, device);

                // Add the 51Degrees.mobi device properties to the collection.
                properties.Add(Constants.FiftyOneDegreesProperties, device.GetAllProperties());

                // If an adapters patch file has been loaded then include this
                // capability in the exposed list of capabilities.
                string adapters = GetAdapters(device);
                if (String.IsNullOrEmpty(adapters) == false)
                    SetValue(properties, "adapters", adapters);
            }
        }