Esempio n. 1
0
 /// <summary>
 /// Set the userAgent string for this device to the value specified.
 /// </summary>
 /// <param name="value"></param>
 internal void SetUserAgent(string value)
 {
     if (_userAgent != value)
     {
         _userAgent = value;
         // Ensure the indexes in the collection are updated to reflect
         // the change in UserAgent string for this device.
         _devices.Set(this);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Processes the XML element containing the device attributes.
        /// </summary>
        /// <param name="devices">A list of loaded devices.</param>
        /// <param name="reader">The XML stream readers.</param>
        /// <returns>An empty device.</returns>
        private static DeviceInfo LoadDevice(Provider devices, XmlReader reader)
        {
            // Create the next device using the fallback device if available.
            string deviceId         = reader.GetAttribute(Constants.IdAttributeName, string.Empty);
            string userAgent        = reader.GetAttribute(Constants.UserAgentAttributeName, string.Empty);
            string fallbackDeviceId = reader.GetAttribute(Constants.FallbackAttributeName, string.Empty);

            // If the device already exists then use the previous one. This may happen
            // when an earlier device referenced a fallback device that had not yet
            // been created.
            DeviceInfo device = devices.GetDeviceInfoFromID(deviceId);

            if (device == null)
            {
                // Create the new device.
                device = new DeviceInfo(devices, deviceId, userAgent ?? String.Empty);
            }
            else if (userAgent != null)
            {
                // Ensure the correct UserAgent string is assigned to this device.
                device.SetUserAgent(userAgent);
            }

            // If the Actual Device Root attribute is specified then set the value
            // for this device.
            bool isActualDeviceRoot;

            if (bool.TryParse(reader.GetAttribute(Constants.ActualDeviceRoot, string.Empty), out isActualDeviceRoot))
            {
                device.IsActualDeviceRoot = isActualDeviceRoot;
            }

            // Check the fallback device is different to the device being loaded.
            if (fallbackDeviceId != null && device.DeviceId != fallbackDeviceId)
            {
                // Does the fallback device already exist?
                device.FallbackDevice = devices.GetDeviceInfoFromID(fallbackDeviceId);
                if (device.FallbackDevice == null)
                {
                    // No. So create new fallback device.
                    device.FallbackDevice = new DeviceInfo(devices, fallbackDeviceId);
                    // Add it to the available devices.
                    devices.Set(device.FallbackDevice);
                }
            }
            return(device);
        }
Esempio n. 3
0
        private static void LoadXmlData(
            StringCollection availableCapabilities,
            Provider devices,
            string filePath,
            DateTime masterFileDate)
        {
            DeviceInfo device = null;
            FileInfo   file   = new FileInfo(filePath);

            if (file.Exists)
            {
                // Open the reader using decompression if the file has an extension
                // that indicates it's compressed.
                using (XmlReader reader = GetReader(file))
                {
                    try
                    {
                        // Process the data file.
                        while (reader.Read())
                        {
                            switch (reader.Name)
                            {
                            // Load Device Data
                            case Constants.DeviceNodeName:
                                if (reader.IsStartElement())
                                {
                                    // If a device has already been created ensure it's saved.
                                    if (device != null)
                                    {
                                        devices.Set(device);
                                    }

                                    // Create or get the device related to the current XML element.
                                    device = LoadDevice(devices, reader);
                                }
                                break;

                            // Load the device capability.
                            case Constants.CapabilityNodeName:
                                if (reader.IsStartElement())
                                {
                                    LoadCapabilityData(
                                        reader,
                                        device,
                                        availableCapabilities);
                                }
                                break;
                            }
                        }

                        // If a device has not been written ensure it's added to the device dataset.
                        if (device != null)
                        {
                            devices.Set(device);
                        }
                    }
                    catch (XmlException ex)
                    {
                        throw new WurflException(
                                  String.Format("XML exception processing wurfl file '{0}'.", filePath),
                                  ex);
                    }
                    catch (IOException ex)
                    {
                        throw new WurflException(
                                  String.Format("IO exception processing wurfl file '{0}'.", filePath),
                                  ex);
                    }
                    catch (Exception ex)
                    {
                        throw new WurflException(
                                  String.Format("Exception processing wurfl file '{0}'.", filePath),
                                  ex);
                    }
                }
            }
        }
Esempio n. 4
0
        private static void LoadXmlData(
            StringCollection availableCapabilities,
            Provider devices,
            string filePath,
            DateTime masterFileDate)
        {
            DeviceInfo device = null;
            FileInfo file = new FileInfo(filePath);

            if (file.Exists)
            {
                // Open the reader using decompression if the file has an extension
                // that indicates it's compressed.
                using (XmlReader reader = GetReader(file))
                {
                    try
                    {
                        // Process the data file.
                        while (reader.Read())
                        {
                            switch (reader.Name)
                            {
                                    // Load Device Data
                                case Constants.DeviceNodeName:
                                    if (reader.IsStartElement())
                                    {
                                        // If a device has already been created ensure it's saved.
                                        if (device != null)
                                            devices.Set(device);

                                        // Create or get the device related to the current XML element.
                                        device = LoadDevice(devices, reader);
                                    }
                                    break;

                                    // Load the device capability.
                                case Constants.CapabilityNodeName:
                                    if (reader.IsStartElement())
                                    {
                                        LoadCapabilityData(
                                            reader,
                                            device,
                                            availableCapabilities);
                                    }
                                    break;
                            }
                        }

                        // If a device has not been written ensure it's added to the device dataset.
                        if (device != null)
                            devices.Set(device);
                    }
                    catch (XmlException ex)
                    {
                        throw new WurflException(
                            String.Format("XML exception processing wurfl file '{0}'.", filePath),
                            ex);
                    }
                    catch (IOException ex)
                    {
                        throw new WurflException(
                            String.Format("IO exception processing wurfl file '{0}'.", filePath),
                            ex);
                    }
                    catch (Exception ex)
                    {
                        throw new WurflException(
                            String.Format("Exception processing wurfl file '{0}'.", filePath),
                            ex);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Processes the XML element containing the device attributes.
        /// </summary>
        /// <param name="devices">A list of loaded devices.</param>
        /// <param name="reader">The XML stream readers.</param>
        /// <returns>An empty device.</returns>
        private static DeviceInfo LoadDevice(Provider devices, XmlReader reader)
        {
            // Create the next device using the fallback device if available.
            string deviceId = reader.GetAttribute(Constants.IdAttributeName, string.Empty);
            string userAgent = reader.GetAttribute(Constants.UserAgentAttributeName, string.Empty);
            string fallbackDeviceId = reader.GetAttribute(Constants.FallbackAttributeName, string.Empty);

            // If the device already exists then use the previous one. This may happen
            // when an earlier device referenced a fallback device that had not yet
            // been created.
            DeviceInfo device = devices.GetDeviceInfoFromID(deviceId);
            if (device == null)
            {
                // Create the new device.
                device = new DeviceInfo(devices, deviceId, userAgent ?? String.Empty);
            }
            else if (userAgent != null)
            {
                // Ensure the correct UserAgent string is assigned to this device.
                device.SetUserAgent(userAgent);
            }

            // If the Actual Device Root attribute is specified then set the value
            // for this device.
            bool isActualDeviceRoot;
            if (bool.TryParse(reader.GetAttribute(Constants.ActualDeviceRoot, string.Empty), out isActualDeviceRoot))
                device.IsActualDeviceRoot = isActualDeviceRoot;

            // Check the fallback device is different to the device being loaded.
            if (fallbackDeviceId != null && device.DeviceId != fallbackDeviceId)
            {
                // Does the fallback device already exist?
                device.FallbackDevice = devices.GetDeviceInfoFromID(fallbackDeviceId);
                if (device.FallbackDevice == null)
                {
                    // No. So create new fallback device.
                    device.FallbackDevice = new DeviceInfo(devices, fallbackDeviceId);
                    // Add it to the available devices.
                    devices.Set(device.FallbackDevice);
                }
            }
            return device;
        }