Exemplo n.º 1
0
        public void Process(RuleContext ruleContext) {
            if (!String.Equals(ruleContext.FunctionName, "url", StringComparison.OrdinalIgnoreCase))
                return;

            var context = _httpContextAccessor.Current();
            var url = Convert.ToString(ruleContext.Arguments[0]);
            if (url.StartsWith("~/")) {
                url = url.Substring(2);
                var appPath = context.Request.ApplicationPath;
                if (appPath == "/")
                    appPath = "";

                if(!String.IsNullOrEmpty(_shellSettings.RequestUrlPrefix))
                    appPath = String.Concat(appPath, "/", _shellSettings.RequestUrlPrefix);

                url = String.Concat(appPath, "/", url);
            }

            if (!url.Contains("?"))
                url = url.TrimEnd('/');

            var requestPath = context.Request.Path;
            if (!requestPath.Contains("?"))
                requestPath = requestPath.TrimEnd('/');

            ruleContext.Result = url.EndsWith("*")
                ? requestPath.StartsWith(url.TrimEnd('*'), StringComparison.OrdinalIgnoreCase)
                : string.Equals(requestPath, url, StringComparison.OrdinalIgnoreCase);
        }
        private static void CheckProperty(IDictionary<string, string> dictionary, RuleContext ruleContext) {
            var argumentsAsString = ruleContext.Arguments.Select(x => x.ToString()).ToList();

            var equalArguments = argumentsAsString.Where(x => x.Contains("=")).ToList();
            var boolArguments = argumentsAsString.Where(x => !x.Contains("=")).ToList();

            if (equalArguments
                .Select(equalsArgument => equalsArgument.Split('='))
                .Any(split => dictionary.ContainsKey(split[0]) &&
                              dictionary[split[0]].Equals(split[1], StringComparison.OrdinalIgnoreCase)))
            {

                ruleContext.Result = true;
                return;
            }

            if (boolArguments.Any(x => dictionary.ContainsKey(x) &&
                                       dictionary[x].Equals("true", StringComparison.OrdinalIgnoreCase)))
            {
                ruleContext.Result = true;
                return;
            }

            ruleContext.Result = false;
        }
Exemplo n.º 3
0
 public void UrlForHomePageMatchesHomePagePathWithUrlPrefix() {
     _stubContextAccessor.StubContext = new StubHttpContext("~/site1");
     _shellSettings.RequestUrlPrefix = "site1";
     var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/" } };
     _urlRuleProvider.Process(context);
     Assert.That(context.Result, Is.True);
 }
Exemplo n.º 4
0
        public void Process(RuleContext ruleContext) {
            if (ruleContext.FunctionName == "add") {
                ruleContext.Result = Convert.ToInt32(ruleContext.Arguments[0]) + Convert.ToInt32(ruleContext.Arguments[1]);
                return;
            }

            ruleContext.Result = true;
        }
        public void Process(RuleContext ruleContext) { 
            if (!String.Equals(ruleContext.FunctionName, "contenttype", StringComparison.OrdinalIgnoreCase)) {
                return;
            }

            var contentType = Convert.ToString(ruleContext.Arguments[0]);

            ruleContext.Result = _displayedContentItemHandler.IsDisplayed(contentType);
        }
Exemplo n.º 6
0
        public void Evaluate(ConditionEvaluationContext evaluationContext) {
            var ruleContext = new RuleContext {
                FunctionName = evaluationContext.FunctionName,
                Arguments = evaluationContext.Arguments,
                Result = evaluationContext.Result
            };

            _ruleProviders.Process(ruleContext);
            evaluationContext.Result = ruleContext.Result;
        }
        public void Process(RuleContext ruleContext)
        {
            if (String.Equals(ruleContext.FunctionName, "sitearea", StringComparison.OrdinalIgnoreCase)) {
                var argument = ((object[]) ruleContext.Arguments)
                    .Cast<string>()
                    .Single();

                ruleContext.Result = _workContext.IsAreaRequest(argument);
            }
        }
        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;
            }
        }
Exemplo n.º 9
0
        public void Process(RuleContext ruleContext)
        {
            if (!String.Equals(ruleContext.FunctionName, "contentterm", StringComparison.OrdinalIgnoreCase)
                || ruleContext.Arguments[0] == null || String.IsNullOrWhiteSpace(ruleContext.Arguments[0].ToString())
                || ruleContext.Arguments[1] == null || String.IsNullOrWhiteSpace(ruleContext.Arguments[1].ToString())
            )
            {
                return;
            }
            ruleContext.Result = false;

            var termIds = _workContextAccessor.GetContext().GetState<string>("ContentTermsIds");

            if (String.IsNullOrWhiteSpace(termIds))
            {
                return;
            }

            var ids = termIds.Split(new[] { ',' }).Select(Int32.Parse).ToArray();

            if (ids.Length == 0)
            {
                return;
            }

            string taxonomyName = ruleContext.Arguments[0].ToString();
            var taxonomyPart = _taxonomyService.GetTaxonomyByName(taxonomyName);

            if(taxonomyPart == null)
            {
                return;
            }

            string termName = ruleContext.Arguments[1].ToString();
            var termPart = _taxonomyService.GetTermByName(taxonomyPart.Id, termName);

            var terms = ids.Select(_taxonomyService.GetTerm).ToList();
            var allChildren = new List<TermPart>();
            foreach (var term in terms)
            {
                allChildren.AddRange(_taxonomyService.GetChildren(term));
                allChildren.Add(term);
            }

            allChildren = allChildren.Distinct().ToList();

            var allIds = allChildren.Select(x => x.Id).ToList();

            if (allIds.Contains(termPart.Id))
            {
                ruleContext.Result = true;
                return;
            }
        }
Exemplo n.º 10
0
            public void Process(GlobalMethodContext context) {
                var ruleContext = new RuleContext {
                    FunctionName = context.FunctionName,
                    Arguments = context.Arguments.ToArray(),
                    Result = context.Result
                };

                _ruleManager._ruleProviders.Process(ruleContext);

                context.Result = ruleContext.Result;
            }
        public void Process(RuleContext ruleContext) { 
            if (!String.Equals(ruleContext.FunctionName, "authenticated", StringComparison.OrdinalIgnoreCase)) {
                return;
            }

            if (_authenticationService.GetAuthenticatedUser() != null) {
                ruleContext.Result = true;
                return;
            }

            ruleContext.Result = false;
        }
        public void Process(RuleContext ruleContext)
        {
            if (!String.Equals(ruleContext.FunctionName, "culture", StringComparison.OrdinalIgnoreCase)) {
                return;
            }

            var ruleCulture = Convert.ToString(ruleContext.Arguments[0]);

            IWorkContextAccessor ContextManager = _services.WorkContext.Resolve<IWorkContextAccessor>();
            var siteCulture = ContextManager.GetContext().CurrentCulture;

            ruleContext.Result = String.Equals(ruleCulture, siteCulture, StringComparison.OrdinalIgnoreCase);
        }
Exemplo n.º 13
0
        public void Process(RuleContext ruleContext)
        {
            if (!String.Equals(ruleContext.FunctionName, "lang", StringComparison.OrdinalIgnoreCase)) {
                return;
            }

            var culture = ruleContext.Arguments.Cast<String>();
            var userCulture = _cultureManager.GetCurrentCulture(_workContextAccessor.GetContext().HttpContext).ToLower();

            var matches = culture.Any( c => c.ToLower()==userCulture.ToLower());
            if (matches)
            {
                ruleContext.Result = true;
                return;
            }

            ruleContext.Result = false;
            return;
        }
Exemplo n.º 14
0
 public void UrlForHomePageDoesNotMatchAboutPagePath() {
     _stubContextAccessor.StubContext = new StubHttpContext("~/about");
     var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/" } };
     _urlRuleProvider.Process(context);
     Assert.That(context.Result, Is.False);
 }
Exemplo n.º 15
0
 public void UrlForBlogWithEndingWildcardMatchesBlogPostPageInSaidBlog() {
     _stubContextAccessor.StubContext = new StubHttpContext("~/my-blog/my-blog-post");
     var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/my-blog/*" } };
     _urlRuleProvider.Process(context);
     Assert.That(context.Result, Is.True);
 }
 public void Process(RuleContext ruleContext) {
     if (string.Equals(ruleContext.FunctionName, "WorkContext", StringComparison.OrdinalIgnoreCase)) {
         ruleContext.Result = _workContextAccessor.GetContext();
     }
 }
Exemplo n.º 17
0
 public void UrlForAboutPageWithEndingSlashMatchesAboutPagePath() {
     _stubContextAccessor.StubContext = new StubHttpContext("~/About/");
     var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/about" } };
     _urlRuleProvider.Process(context);
     Assert.That(context.Result, Is.True);
 }
 public void UrlForAboutPageMatchesDifferentCasedAboutPagePath() {
     _stubContextAccessor.Set(new StubHttpContext("~/About"));
     var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/about" } };
     _urlRuleProvider.Process(context);
     Assert.That(context.Result, Is.True);
 }