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

Match() public method

Resets the FiftyOne.Foundation.Mobile.Detection.Match object provided and performs the detection using that object rather than creating a new match.
public Match ( NameValueCollection headers, Match match ) : Match
headers System.Collections.Specialized.NameValueCollection /// List of HTTP headers to use for the detection ///
match System.Text.RegularExpressions.Match /// A /// object created by a previous match, or via the /// method. ///
return System.Text.RegularExpressions.Match
        public Match Match(NameValueCollection headers, Match match)
        {
            if (headers == null || headers.Count == 0)
            {
                // Empty headers all default match result.
                Controller.MatchDefault(match.State);
            }
            else
            {
                // Get the overlapping headers?
                var importantHeaders = headers.AllKeys.Intersect(DataSet.HttpHeaders);

                if (importantHeaders.Count() == 1)
                {
                    // If only 1 header is important then return a simple single match.
                    Match(headers[importantHeaders.First()], match);
                }
                else
                {
                    // Create matches for each of the headers.
                    var matches = MatchForHeaders(match, headers, importantHeaders);

                    // A list of new profiles to use with the match.
                    var componentIndex = 0;
                    foreach(var component in DataSet.Components)
                    {
                        // Get the profile for this component.
                        var profile = GetMatchingHeaderProfile(match.State, matches, component);

                        // Add the profile found, or the default one if not found.
                        match.State.ExplicitProfiles.Add(profile == null ? component.DefaultProfile : profile);

                        // Move to the next array element.
                        componentIndex++;
                    }

                    // Reset any fields that relate to the profiles assigned
                    // to the match result or that can't contain a value when
                    // HTTP headers are used.
                    match.State.Signature = null;
                    match.State.TargetUserAgent = null;
                }
            }
            return match;
        }

Same methods

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

Usage Example

Example #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