public void Process(RuleContext ruleContext)
        {
            //Not my game - return
            if (!_functions.Any(x => String.Equals(ruleContext.FunctionName, x, StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }

            var request = _httpContextAccessor.Current().Request;
            var device  = _oddrDeviceService.GetDevice(request.UserAgent);

            //Device - IsPhone, IsTablet, IsDesktop
            if (String.Equals(ruleContext.FunctionName, "device", StringComparison.OrdinalIgnoreCase))
            {
                if (ruleContext.Arguments.Any(x => String.Equals("tablet", x.ToString(), StringComparison.OrdinalIgnoreCase)) && device.IsTablet)
                {
                    ruleContext.Result = true;
                    return;
                }

                if (ruleContext.Arguments.Any(x => String.Equals("phone", x.ToString(), StringComparison.OrdinalIgnoreCase) && device.IsPhone))
                {
                    ruleContext.Result = true;
                    return;
                }

                if (ruleContext.Arguments.Any(x => String.Equals("desktop", x.ToString(), StringComparison.OrdinalIgnoreCase)) && device.IsDesktop)
                {
                    ruleContext.Result = true;
                    return;
                }

                ruleContext.Result = false;
                return;
            }

            //Device properties
            if (String.Equals(ruleContext.FunctionName, "device_property", StringComparison.OrdinalIgnoreCase))
            {
                CheckProperty(device.DeviceProperties, ruleContext);
                return;
            }

            //Browser properties
            if (String.Equals(ruleContext.FunctionName, "browser_property", StringComparison.OrdinalIgnoreCase))
            {
                CheckProperty(device.BrowserProperties, ruleContext);
                return;
            }

            //OS properties
            if (String.Equals(ruleContext.FunctionName, "os_property", StringComparison.OrdinalIgnoreCase))
            {
                CheckProperty(device.OsProperties, ruleContext);
                return;
            }
        }
Esempio n. 2
0
        public ActionResult UserAgentSearch(UserAgentSearchOptions options)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageWurfl, T("Not allowed to manage wurfl")))
            {
                return(new HttpUnauthorizedResult());
            }

            // Use the current browsers user agent if none is given.
            if (string.IsNullOrEmpty(options.UserAgentText))
            {
                options.UserAgentText = _httpContextAccessor.Current().Request.UserAgent;
                ModelState.Clear(); // HTML helpers such as TextAreaFor will always bind to modelstate over an explicitly passed model object.
            }

            var device = _wurflService.GetDevice(options.UserAgentText);

            return(View(new UserAgentSearchViewModel {
                Device = device, Options = options
            }));
        }