Esempio n. 1
0
        public static MessageCandidate CreateValidMessageCandidate(
            string token,
            IEnumerable <ObjectProperty> superProperties,
            object rawProperties,
            object distinctId,
            MixpanelConfig config,
            out string errorMessage)
        {
            var messageCandidate = new MessageCandidate(
                token,
                superProperties,
                rawProperties,
                distinctId,
                config,
                PeopleSpecialPropertyMapper.RawNameToSpecialProperty);

            ObjectProperty tokenProp = messageCandidate.GetSpecialProperty(PeopleSpecialProperty.Token);

            if (tokenProp == null)
            {
                errorMessage = $"'{PeopleSpecialProperty.Token}' is not set.";
                return(null);
            }

            ValueParseResult tokenParseResult =
                PeopleSpecialPropertyParser.Parse(PeopleSpecialProperty.Token, tokenProp.Value);

            if (!tokenParseResult.Success)
            {
                errorMessage = $"Error parsing '{PeopleSpecialProperty.Token}'. {tokenParseResult.ErrorDetails}";
                return(null);
            }

            ObjectProperty distinctIdProp = messageCandidate.GetSpecialProperty(PeopleSpecialProperty.DistinctId);

            if (distinctIdProp == null)
            {
                errorMessage = $"'{PeopleSpecialProperty.DistinctId}' is not set.";
                return(null);
            }

            ValueParseResult distinctIdParseResult =
                PeopleSpecialPropertyParser.Parse(PeopleSpecialProperty.DistinctId, distinctIdProp.Value);

            if (!distinctIdParseResult.Success)
            {
                errorMessage = $"Error parsing '{PeopleSpecialProperty.DistinctId}'. {distinctIdParseResult.ErrorDetails}";
                return(null);
            }

            errorMessage = null;
            return(messageCandidate);
        }
Esempio n. 2
0
        public static void RunForValidSpecialProperties(
            MessageCandidate messageCandidate,
            Action <string, bool, object> fn)
        {
            foreach (KeyValuePair <string, ObjectProperty> pair in messageCandidate.SpecialProperties)
            {
                string         specialPropertyName = pair.Key;
                ObjectProperty objectProperty      = pair.Value;

                ValueParseResult result = PeopleSpecialPropertyParser.Parse(specialPropertyName, objectProperty.Value);
                if (!result.Success)
                {
                    continue;
                }

                bool isMessageSpecialProperty = PeopleSpecialProperty.IsMessageSpecialProperty(specialPropertyName);

                fn(specialPropertyName, isMessageSpecialProperty, result.Value);
            }
        }