FiftyOne.Foundation.Mobile.Detection.Provider.Match C# (CSharp) Method

Match() public method

For a given collection of HTTP headers returns a match containing information about the capabilities of the device and it's components.
public Match ( NameValueCollection headers ) : Match
headers System.Collections.Specialized.NameValueCollection /// List of HTTP headers to use for the detection ///
return System.Text.RegularExpressions.Match
        public Match Match(NameValueCollection headers)
        {
            return Match(headers, CreateMatch());
        }

Same methods

Provider::Match ( NameValueCollection headers, Match match ) : Match
Provider::Match ( string targetUserAgent ) : Match
Provider::Match ( string targetUserAgent, Match match ) : Match
Provider::Match ( string targetUserAgent, MatchState state ) : MatchResult

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Gets the match from the cache for the useragent or if not
        /// present in the cache from the detection provider.
        /// </summary>
        /// <param name="userAgent">The user agent whose properties are needed</param>
        /// <returns>A results object for the user agent</returns>
        private static InternalResult GetMatchByUserAgent(string userAgent)
        {
            InternalResult result;

            if (_cacheUserAgent._itemsActive.TryGetValue(userAgent, out result) == false)
            {
                // The result wasn't in the cache so find it from the 51Degrees provider.
                var match = _provider.Match(userAgent);

                // Construct the results for the values and the profile Ids.
                result = new InternalResult(
                    new SortedList <string, string>(_numberOfProperties),
                    match.ProfileIds.OrderBy(i =>
                                             i.Key).SelectMany(i =>
                                                               BitConverter.GetBytes(i.Value)).ToArray());

                // Load the values into the results.
                foreach (var property in _requiredProperties.SelectMany(i =>
                                                                        i.Value))
                {
                    var values = match[property];
                    if (values != null)
                    {
                        result.Values.Add(property.Name, values.ToString());
                    }
                }

                // Load the dynamic values into the results.
                foreach (var dynamicProperty in _dynamicProperties)
                {
                    // Add special properties for the detection.
                    switch (dynamicProperty)
                    {
                    case DynamicProperties.Id:
                        result.Values.Add("Id", String.Join(
                                              Constants.ProfileSeperator,
                                              match.ProfileIds.OrderBy(i =>
                                                                       i.Key).Select(i => i.Value.ToString())));
                        break;

                    case DynamicProperties.Difference:
                        result.Values.Add("Difference", match.Difference.ToString());
                        break;

                    case DynamicProperties.Method:
                        result.Values.Add("Method", match.Method.ToString());
                        break;
                    }
                }

                // Add the results to the cache.
                _cacheUserAgent._itemsActive[userAgent] = result;
            }

            // Ensure the result is added to the background cache.
            //_cacheUserAgent.SetBackground(userAgent, result);
            _cacheUserAgent.AddRecent(userAgent, result);

            return(result);
        }
All Usage Examples Of FiftyOne.Foundation.Mobile.Detection.Provider::Match