예제 #1
0
            public string?Check(string key, Regex?regex = null, CheckOptions options = 0, string?message = null)
            {
                if (!dict.ContainsKey(key))
                {
                    if (!options.HasFlag(CheckOptions.Optional))
                    {
                        errors?.Error($"Missing required column {key}", lineNumber, line);
                        hadError = true;
                    }
                    return(null);
                }

                if (regex != null && !regex.IsMatch(dict[key]))
                {
                    if (!options.HasFlag(CheckOptions.Warning))
                    {
                        errors?.Error($"Unexpected value for {key}: '{dict[key]}'{message ?? ""}", lineNumber, line);
                        hadError = true;
                    }
                    else
                    {
                        errors?.Warning($"Unexpected value for {key}: '{dict[key]}'{message ?? ""}", lineNumber, line);
                    }
                }

                string value = dict[key];

                if (options.HasFlag(CheckOptions.EmptyIfDash))
                {
                    value = EmptyIfDash(value);
                }

                return(value);
            }
예제 #2
0
            public string Check(ICollection <string> keys, Func <string, bool> validate, CheckOptions options = 0)
            {
                foreach (var key in keys)
                {
                    if (!dict.ContainsKey(key))
                    {
                        continue;
                    }
                    string value = dict[key];

                    if (options.HasFlag(CheckOptions.EmptyIfDash))
                    {
                        value = EmptyIfDash(value);
                    }

                    if (!validate(value))
                    {
                        if (!options.HasFlag(CheckOptions.Warning))
                        {
                            if (errors != null)
                            {
                                errors.Error(string.Format("Unexpected value for {0}: '{1}'", key, value), lineNumber, line);
                            }
                            hadError = true;
                        }
                        else
                        {
                            if (errors != null)
                            {
                                errors.Warning(string.Format("Unexpected value for {0}: '{1}'", key, value), lineNumber, line);
                            }
                        }
                    }

                    return(value);
                }

                if (!options.HasFlag(CheckOptions.Optional))
                {
                    if (errors != null)
                    {
                        errors.Error(string.Format("Missing required column {0}",
                                                   string.Join("/", keys)), lineNumber, line);
                    }
                    hadError = true;
                }

                return(null);
            }
        private void SetSiblingErrors()
        {
            TNode[] siblings = null;

            if (CheckOptions.HasFlag(ErrorCheckOptions.SiblingIdDuplicates))
            {
                siblings = SelectSiblings().ToArray();

                var existingIdMatch = siblings.FirstOrDefault(HasSameIdentityAs);

                if (existingIdMatch != null)
                {
                    Error |= IdentityError.SiblingIdDuplicate;
                    existingIdMatch.Error |= IdentityError.SiblingIdDuplicate;
                }
            }

            if (!CheckOptions.HasFlag(ErrorCheckOptions.SiblingAliasDuplicates))
            {
                return;
            }

            siblings = siblings ?? SelectSiblings().ToArray();

            var existingAliasMatch = siblings.FirstOrDefault(HasSameAliasAs);

            if (existingAliasMatch != null)
            {
                Error |= IdentityError.SiblingAliasDuplicate;
                existingAliasMatch.Error |= IdentityError.SiblingAliasDuplicate;
            }
        }
예제 #4
0
            public string Check(string key, Regex regex = null, CheckOptions options = 0)
            {
                if (!dict.ContainsKey(key))
                {
                    if (!options.HasFlag(CheckOptions.Optional))
                    {
                        if (errors != null)
                        {
                            errors.Error(string.Format("Missing required column {0}", key), lineNumber, line);
                        }
                        hadError = true;
                    }
                    return(null);
                }

                if (regex != null && !regex.IsMatch(dict[key]))
                {
                    if (!options.HasFlag(CheckOptions.Warning))
                    {
                        if (errors != null)
                        {
                            errors.Error(string.Format("Unexpected value for {0}: '{1}'", key, dict[key]), lineNumber, line);
                        }
                        hadError = true;
                    }
                    else
                    {
                        if (errors != null)
                        {
                            errors.Warning(string.Format("Unexpected value for {0}: '{1}'", key, dict[key]), lineNumber, line);
                        }
                    }
                }

                string value = dict[key];

                if (options.HasFlag(CheckOptions.EmptyIfDash))
                {
                    value = EmptyIfDash(value);
                }

                return(value);
            }
예제 #5
0
            public string?Check(ICollection <string> keys, Func <string, bool> validate, CheckOptions options = 0, string?message = null)
            {
                foreach (var key in keys)
                {
                    if (!dict.ContainsKey(key))
                    {
                        continue;
                    }
                    string value = dict[key];

                    if (options.HasFlag(CheckOptions.EmptyIfDash))
                    {
                        value = EmptyIfDash(value);
                    }

                    if (!validate(value))
                    {
                        if (!options.HasFlag(CheckOptions.Warning))
                        {
                            errors?.Error($"Unexpected value for {key}: '{value}'{message ?? ""}", lineNumber, line);
                            hadError = true;
                        }
                        else
                        {
                            errors?.Warning($"Unexpected value for {key}: '{value}'{message ?? ""}", lineNumber, line);
                        }
                    }

                    return(value);
                }

                if (!options.HasFlag(CheckOptions.Optional))
                {
                    errors?.Error($"Missing required column {string.Join("/", keys)}", lineNumber, line);
                    hadError = true;
                }

                return(null);
            }
        private void SetErrorsAfterAddingThis()
        {
            SetSiblingErrors();

            if (CheckOptions.HasFlag(ErrorCheckOptions.CyclicIdDuplicates))
            {
                SetCyclicIdErrors();
            }

            if (IdentityTrackingIsTreeScope)
            {
                SetTreeScopeIdErrors();
            }
        }
        private void UpdateErrorsBeforeDetachingThis()
        {
            if (CheckOptions.HasFlag(ErrorCheckOptions.CyclicIdDuplicates))
            {
                UpdateCyclicIdErrorsBeforeDetachingThis();
            }

            if (CheckOptions.HasFlag(ErrorCheckOptions.SiblingAliasDuplicates) &&
                Error.HasFlag(IdentityError.SiblingAliasDuplicate))
            {
                UpdateSiblingAliasErrorsBeforeDetachingThis();
            }

            if (CheckOptions.HasFlag(ErrorCheckOptions.SiblingIdDuplicates) &&
                Error.HasFlag(IdentityError.SiblingIdDuplicate))
            {
                UpdateSiblingIdErrorsBeforeDetachingThis();
            }

            if (IdentityTrackingIsTreeScope)
            {
                UpdateTreeScopeIdErrorsBeforeDetachingThis();
            }
        }
        private void CheckTrackDictionary(IDictionary<string, object> dic, CheckOptions checkOptions = CheckOptions.None)
        {
            Assert.That(dic.Count, Is.EqualTo(2));
            Assert.That(dic[MixpanelProperty.TrackEvent], Is.EqualTo(Event));
            Assert.That(dic[MixpanelProperty.TrackProperties], Is.TypeOf<Dictionary<string, object>>());
            var props = (Dictionary<string, object>)dic[MixpanelProperty.TrackProperties];
            Assert.That(props.Count, Is.EqualTo(GetPropsCount(checkOptions, normalCount: 6, superPropsCount: 8)));
            Assert.That(props[MixpanelProperty.TrackToken], Is.EqualTo(Token));
            Assert.That(props[MixpanelProperty.TrackDistinctId], Is.EqualTo(GetDistinctId(checkOptions)));
            Assert.That(props[MixpanelProperty.TrackIp], Is.EqualTo(Ip));
            Assert.That(props[MixpanelProperty.TrackTime], Is.EqualTo(TimeUnix));
            Assert.That(props[StringPropertyName], Is.EqualTo(StringPropertyValue));
            Assert.That(props[DecimalPropertyName], Is.EqualTo(DecimalPropertyValue));

            if (checkOptions.HasFlag(CheckOptions.SuperPropsSet))
            {
                Assert.That(props[DecimalSuperPropertyName], Is.EqualTo(DecimalSuperPropertyValue));
                Assert.That(props[StringSuperPropertyName], Is.EqualTo(StringSuperPropertyValue));
            }
        }
        private void CheckTrackJsonMessage(JObject msg, CheckOptions checkOptions = CheckOptions.None)
        {
            Assert.That(msg.Count, Is.EqualTo(2));
            Assert.That(msg[MixpanelProperty.TrackEvent].Value<string>(), Is.EqualTo(Event));
            var props = (JObject)msg[MixpanelProperty.TrackProperties];

            Assert.That(props.Count, Is.EqualTo(GetPropsCount(checkOptions, normalCount: 6, superPropsCount: 8)));
            Assert.That(props[MixpanelProperty.TrackToken].Value<string>(), Is.EqualTo(Token));
            Assert.That(props[MixpanelProperty.TrackDistinctId].Value<string>(), Is.EqualTo(GetDistinctId(checkOptions)));
            Assert.That(props[MixpanelProperty.TrackIp].Value<string>(), Is.EqualTo(Ip));
            Assert.That(props[MixpanelProperty.TrackTime].Value<long>(), Is.EqualTo(TimeUnix));
            Assert.That(props[StringPropertyName].Value<string>(), Is.EqualTo(StringPropertyValue));
            Assert.That(props[DecimalPropertyName].Value<decimal>(), Is.EqualTo(DecimalPropertyValue));

            if (checkOptions.HasFlag(CheckOptions.SuperPropsSet))
            {
                Assert.That(props[DecimalSuperPropertyName].Value<decimal>(), Is.EqualTo(DecimalSuperPropertyValue));
                Assert.That(props[StringSuperPropertyName].Value<string>(), Is.EqualTo(StringSuperPropertyValue));
            }
        }
        private string GetDistinctId(CheckOptions checkOptions)
        {
            bool distinctIdSetFromSuperProps =
                checkOptions.HasFlag(CheckOptions.SuperPropsDistinctIdSet) &&
                !checkOptions.HasFlag(CheckOptions.DistinctIdSet);

            if (distinctIdSetFromSuperProps)
            {
                return SuperDistinctId;
            }
            return DistinctId;
        }
 private int GetPropsCount(CheckOptions checkOptions, int normalCount, int superPropsCount)
 {
     if (checkOptions.HasFlag(CheckOptions.SuperPropsSet))
     {
         return 8;
     }
     return 6;
 }
예제 #12
0
            public string Check(IEnumerable<string> keys, Func<string, bool> validate, CheckOptions options = 0)
            {
                foreach (var key in keys)
                {
                    if (!dict.ContainsKey(key))
                        continue;
                    string value = dict[key];

                    if (options.HasFlag(CheckOptions.EmptyIfDash))
                        value = EmptyIfDash(value);

                    if (!validate(value))
                    {
                        if (!options.HasFlag(CheckOptions.Warning))
                        {
                            if (errors != null)
                                errors.Error(String.Format("Unexpected value for {0}: '{1}'", key, value), lineNumber, line);
                            hadError = true;
                        }
                        else
                        {
                            if (errors != null)
                                errors.Warning(String.Format("Unexpected value for {0}: '{1}'", key, value), lineNumber, line);
                        }
                    }

                    return value;
                }
                return null;
            }
예제 #13
0
            public string Check(string key, Regex regex, CheckOptions options = 0)
            {
                if (!regex.IsMatch(dict[key]))
                {
                    if (!options.HasFlag(CheckOptions.Warning))
                    {
                        if (errors != null)
                            errors.Error(String.Format("Unexpected value for {0}: '{1}'", key, dict[key]), lineNumber, line);
                        hadError = true;
                    }
                    else
                    {
                        if (errors != null)
                            errors.Warning(String.Format("Unexpected value for {0}: '{1}'", key, dict[key]), lineNumber, line);
                    }
                }

                string value = dict[key];

                if (options.HasFlag(CheckOptions.EmptyIfDash))
                    value = EmptyIfDash(value);

                return value;
            }
예제 #14
0
            public string Check(ICollection<string> keys, Func<string, bool> validate, CheckOptions options = 0)
            {
                foreach (var key in keys)
                {
                    if (!dict.ContainsKey(key))
                        continue;
                    string value = dict[key];

                    if (options.HasFlag(CheckOptions.EmptyIfDash))
                        value = EmptyIfDash(value);

                    if (!validate(value))
                    {
                        if (!options.HasFlag(CheckOptions.Warning))
                        {
                            if (errors != null)
                                errors.Error(string.Format("Unexpected value for {0}: '{1}'", key, value), lineNumber, line);
                            hadError = true;
                        }
                        else
                        {
                            if (errors != null)
                                errors.Warning(string.Format("Unexpected value for {0}: '{1}'", key, value), lineNumber, line);
                        }
                    }

                    return value;
                }

                if (!options.HasFlag(CheckOptions.Optional))
                {
                    if (errors != null)
                        errors.Error(string.Format("Missing required column {0}",
                            string.Join("/", keys)), lineNumber, line);
                    hadError = true;
                }

                return null;
            }
예제 #15
0
            public string Check(string key, Regex regex = null, CheckOptions options = 0)
            {
                if (!dict.ContainsKey(key))
                {
                    if (!options.HasFlag(CheckOptions.Optional))
                    {
                        if (errors != null)
                            errors.Error(string.Format("Missing required column {0}", key), lineNumber, line);
                        hadError = true;
                    }
                    return null;
                }

                if (regex != null && !regex.IsMatch(dict[key]))
                {
                    if (!options.HasFlag(CheckOptions.Warning))
                    {
                        if (errors != null)
                            errors.Error(string.Format("Unexpected value for {0}: '{1}'", key, dict[key]), lineNumber, line);
                        hadError = true;
                    }
                    else
                    {
                        if (errors != null)
                            errors.Warning(string.Format("Unexpected value for {0}: '{1}'", key, dict[key]), lineNumber, line);
                    }
                }

                string value = dict[key];

                if (options.HasFlag(CheckOptions.EmptyIfDash))
                    value = EmptyIfDash(value);

                return value;
            }