Esempio n. 1
0
        public static bool CheckString(string eventName)
        {
            if (string.IsNullOrEmpty(eventName))
            {
                TD_Log.w("TA.PropertiesChecker - the string is null");
                return(false);
            }

            if (keyPattern.IsMatch(eventName))
            {
                return(true);
            }
            else
            {
                TD_Log.w("TA.PropertiesChecker - the string is invalid for TA: " + eventName + ", " +
                         "事件名和属性名规则: 必须以字母开头,只能包含:数字,字母(忽略大小写)和下划线“_”,长度最大为50个字符。请注意配置时不要带有空格。");
                return(false);
            }
        }
Esempio n. 2
0
        public static bool CheckProperties <V>(Dictionary <string, V> properties)
        {
            if (properties == null)
            {
                return(true);
            }
            foreach (KeyValuePair <string, V> kv in properties)
            {
                if (!CheckString(kv.Key))
                {
                    return(false);
                }

                if (!(kv.Value is string || kv.Value is DateTime || kv.Value is bool || IsNumeric(kv.Value) || IsList(kv.Value)))
                {
                    TD_Log.w("TA.PropertiesChecker - property values must be one of: string, numberic, Boolean, DateTime, Array");
                    return(false);
                }

                if (kv.Value is string && System.Text.Encoding.UTF8.GetBytes(Convert.ToString(kv.Value)).Length > 2048)
                {
                    TD_Log.w("TA.PropertiesChecker - the string is too long: " + (string)(object)kv.Value);
                    return(false);
                }

                if (IsNumeric(kv.Value))
                {
                    double number = Convert.ToDouble(kv.Value);
                    if (number > 9999999999999.999 || number < -9999999999999.999)
                    {
                        TD_Log.w("TA.PropertiesChecker - number value is invalid: " + number + ", 数据范围是-9E15至9E15,小数点最多保留3位");
                        return(false);
                    }
                }
            }
            return(true);
        }