Ejemplo n.º 1
0
        public IEnumerable <PXPolicyResult> GetMatchedPolicy(string url)
        {
            foreach (var policy in Policies)
            {
                foreach (string pattern in policy.UrlPatterns)
                {
                    var match = Regex.Match(url, pattern);
                    if (match.Success)
                    {
                        PXPolicyResult result = new PXPolicyResult
                        {
                            Name = policy.Name,
                            MatchedUrlPattern = pattern,
                            Path    = policy.PathPattern,
                            Actions = policy.Actions
                        };
                        var ms = Regex.Matches(policy.PathPattern, @"(?<={)\S+?(?=})");
                        foreach (Match m in ms)
                        {
                            string va = match.Groups[m.Value].Value;
                            // In netstandard2.1 we can use Group.Name
                            if (!string.IsNullOrEmpty(va))
                            {
                                result.Path = result.Path.Replace("{" + m.Value + "}", va);
                            }
                        }
                        yield return(result);

                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void AddAction(string actionName, string name, string url, PXPolicyResult policy)
        {
            Trace.TraceInformation("ADD ACTION " + actionName);
            PXActionContext context = new PXActionContext
            {
                Id             = Guid.NewGuid().ToString(),
                CreatedAt      = DateTimeOffset.Now,
                Name           = name,
                Key            = actionName,
                Url            = url,
                FilenamePrefix = ReplaceInvalidChars(name),
                PolicyInfo     = policy
            };

            context.WorkingDictory = Storage.NewTemp(context);
            ActionM.AddAndStart(context);
        }