Ejemplo n.º 1
0
        /// <summary>
        /// Adds the device to the collection of devices with UA prof information.
        /// If the device already exists the previous one is replaced.
        /// </summary>
        /// <param name="device">Device to be added.</param>
        private void SetUaProf(BaseDeviceInfo device)
        {
            foreach (int index in _provider.UserAgentProfileStringIndexes)
            {
                var list = device.GetPropertyValueStringIndexes(index);
                if (list != null)
                {
                    foreach (int userAgentProfileStringIndex in list)
                    {
                        string value = _provider.Strings.Get(userAgentProfileStringIndex);

                        // Don't process empty values.
                        if (String.IsNullOrEmpty(value)) continue;
                        
                        // If the url is not valid don't continue processing.
                        Uri url = null;
                        if (Uri.TryCreate(value, UriKind.Absolute, out url) == false) continue;

                        // Get the hashcode before locking the list and processing
                        // the device and hashcode.
                        int hashcode = value.GetHashCode();
                        lock (_uaprofs)
                        {
                            ProcessUaProf(device, hashcode);
                        }

                        // Add the domain to the list of domains for the handler.
                        lock (_uaProfDomains)
                        {
                            if (_uaProfDomains.Contains(url.Host) == false)
                                _uaProfDomains.Add(url.Host);
                        }
                    }
                }
            }
        }