private static IReadOnlyList <OnDeviceDecisioningRule> GetViewRules(OnDeviceDecisioningRuleSet ruleSet, ViewRequest viewRequest)
        {
            if (string.IsNullOrEmpty(viewRequest.Name))
            {
                return(ruleSet.Rules.Views.Values.SelectMany(list => list).ToList());
            }

            return(ruleSet.Rules.Views.TryGetValue(viewRequest.Name, out var result) ? result : null);
        }
Ejemplo n.º 2
0
 internal TraceHandler(
     TargetClientConfig clientConfig,
     IRuleLoader ruleLoader,
     OnDeviceDecisioningRuleSet ruleSet,
     TargetDeliveryRequest request)
 {
     this.ruleSet = ruleSet;
     this.trace   = new Dictionary <string, object>
     {
         { ClientCodeKey, clientConfig.Client },
         { ArtifactKey, this.ArtifactTrace(ruleLoader) },
         { ProfileKey, ProfileTrace(request.DeliveryRequest.Id) },
     };
     this.campaigns        = new Dictionary <long, IDictionary <string, object> >();
     this.evaluatedTargets = new Dictionary <long, IDictionary <string, object> >();
 }
 private static IReadOnlyList <OnDeviceDecisioningRule> GetPageLoadRules(OnDeviceDecisioningRuleSet ruleSet)
 {
     return(ruleSet.Rules.Mboxes.TryGetValue(ruleSet.GlobalMbox, out var result) ? result : null);
 }
 private static IReadOnlyList <OnDeviceDecisioningRule> GetMboxRules(OnDeviceDecisioningRuleSet ruleSet, MboxRequest mboxRequest)
 {
     return(ruleSet.Rules.Mboxes.TryGetValue(mboxRequest.Name, out var result) ? result : null);
 }
 private static IReadOnlyList <OnDeviceDecisioningRule> GetDetailsRules(RequestDetailsUnion details, OnDeviceDecisioningRuleSet ruleSet)
 {
     return(details.Match(
                _ => GetPageLoadRules(ruleSet),
                mboxRequest => GetMboxRules(ruleSet, mboxRequest),
                viewRequest => GetViewRules(ruleSet, viewRequest)));
 }
        public void ExecuteDetails(
            TargetDeliveryRequest deliveryRequest,
            IDictionary <string, object> localContext,
            string visitorId,
            ISet <string> responseTokens,
            TraceHandler traceHandler,
            OnDeviceDecisioningRuleSet ruleSet,
            RequestDetailsUnion details,
            PrefetchResponse prefetchResponse,
            ExecuteResponse executeResponse,
            IList <Notification> notifications)
        {
            traceHandler?.UpdateRequest(deliveryRequest, details, executeResponse != null);
            var rules = GetDetailsRules(details, ruleSet);

            if (rules == null)
            {
                UnhandledResponse(details, prefetchResponse, executeResponse, traceHandler);
                return;
            }

            var propertyToken      = deliveryRequest.DeliveryRequest.Property?.Token;
            var handledAtLeastOnce = false;
            var skipKeySet         = new HashSet <string>();

            foreach (var rule in rules)
            {
                if (PropertyTokenMismatch(rule.PropertyTokens, propertyToken))
                {
                    continue;
                }

                if (rule.RuleKey != null && skipKeySet.Contains(rule.RuleKey))
                {
                    continue;
                }

                var consequence = this.ruleExecutor.ExecuteRule(localContext, details, visitorId, rule, responseTokens, traceHandler);
                if (!HandleResult(consequence, rule, details, prefetchResponse, executeResponse, notifications, traceHandler, ruleSet.GlobalMbox))
                {
                    continue;
                }

                handledAtLeastOnce = true;
                if (rule.RuleKey != null)
                {
                    skipKeySet.Add(rule.RuleKey);
                }

                if (details.Match(
                        _ => false,
                        _ => true,
                        _ => false))
                {
                    break;
                }
            }

            if (!handledAtLeastOnce)
            {
                UnhandledResponse(details, prefetchResponse, executeResponse, traceHandler);
            }
        }