Ejemplo n.º 1
0
        public bool IsFeatureEnabled(string feature, User user)
        {
            UserAttributes userAtrributes = new UserAttributes();

            foreach (KeyValuePair <string, object> keyValuePair in user.GetAttributes())
            {
                userAtrributes.Add(keyValuePair.Key, keyValuePair.Value);
            }
            return(_optimizelyClient.IsFeatureEnabled(feature.ToLower(), user.Email, userAtrributes));
        }
        public void DispatchEvent(LogEvent actualLogEvent)
        {
            Visitor[] visitors = null;
            if (actualLogEvent.Params.ContainsKey("visitors"))
            {
                JArray jArray = (JArray)actualLogEvent.Params["visitors"];
                visitors = jArray.ToObject <Visitor[]>();
            }

            if (visitors == null)
            {
                return;
            }

            foreach (var visitor in visitors)
            {
                foreach (var snapshot in visitor.Snapshots)
                {
                    var decisions = snapshot.Decisions ?? new Decision[1] {
                        new Decision()
                    };
                    foreach (var decision in decisions)
                    {
                        foreach (var @event in snapshot.Events)
                        {
                            var userAttributes = new UserAttributes();
                            foreach (var attribute in visitor.Attributes.Where(attr => !attr.Key.StartsWith(DatafileProjectConfig.RESERVED_ATTRIBUTE_PREFIX)))
                            {
                                userAttributes.Add(attribute.Key, attribute.Value);
                            }

                            ActualEvents.Add(new CanonicalEvent(decision.ExperimentId, decision.VariationId, @event.Key,
                                                                visitor.VisitorId, userAttributes, @event.EventTags));
                        }
                    }
                }
            }

            try
            {
                CountdownEvent?.Signal();
            }
            catch (ObjectDisposedException)
            {
                Logger.Log(LogLevel.ERROR, "The CountdownEvent instance has already been disposed.");
            }
            catch (InvalidOperationException)
            {
                Logger.Log(LogLevel.ERROR, "The CountdownEvent instance has already been set.");
            }
        }