FiftyOne.Foundation.Mobile.Detection.WebProvider.GetMatch C# (CSharp) Method

GetMatch() static private method

Returns the match results for the request, or creates one if one does not already exist. If the match has already been calculated it is fetched from the context items collection.
static private GetMatch ( HttpRequest request ) : Match
request System.Web.HttpRequest
return Match
        internal static Match GetMatch(HttpRequest request)
        {
            var matchKey = Constants.MatchKey + (request.UserAgent != null ? request.UserAgent.GetHashCode().ToString() : "");
            var hasOverrides = Feature.ProfileOverride.HasOverrides(request);

            // Get a collection to store data across the request. One may not be returned
            // depending of the configuration of the server or the current stage in the
            // pipeline.
            var items = GetContextItems(request);

            // Get the results from the items collection if if exists already.
            var match = items != null ? items[matchKey] as Match : null;

            if (match == null || hasOverrides)
            {
                // A lock is needed in case 2 simultaneous operations are done on the
                // request at the sametime. This is a rare use case but ensures robustness.
                lock (request)
                {
                    match = items != null ? items[matchKey] as Match : null;
                    if ((match == null || hasOverrides) && ActiveProvider != null)
                    {
                        // Get the match and store the list of properties and values
                        // in the context and session.
                        match = ActiveProvider.Match(GetRequiredHeaders(request));

                        // Allow other feature detection methods to override profiles.
                        Feature.ProfileOverride.Override(request, match);
                        if (items != null)
                        {
                            items[matchKey] = match;
                        }
                    }
                }
            }

            return match;
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Gets the JavaScript to send to the specific client device based on the
        /// request context provided.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private static string GetFeatureJavaScript(HttpContext context)
        {
            var queryString = context.Request.QueryString.ToString();
            var match       = WebProvider.GetMatch(context.Request);
            var features    = new List <string>();

            if (String.IsNullOrEmpty(queryString))
            {
                foreach (var property in WebProvider.ActiveProvider.DataSet.Properties.Where(i =>
                                                                                             i._valueType != Entities.Property.PropertyValueType.JavaScript))
                {
                    GetFeatureJavaScript(match, features, property);
                }
            }
            else
            {
                foreach (var propertyName in HttpUtility.UrlDecode(queryString).Split(
                             new char[] { ' ', ',', '&', '|' }))
                {
                    var property = WebProvider.ActiveProvider.DataSet.Properties.FirstOrDefault(i =>
                                                                                                i.Name.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase));
                    if (property != null)
                    {
                        GetFeatureJavaScript(match, features, property);
                    }
                }
            }
            return(String.Format("var FODF={{{0}}};", String.Join(",", features.ToArray())));
        }
All Usage Examples Of FiftyOne.Foundation.Mobile.Detection.WebProvider::GetMatch