示例#1
0
        public void Sha1()
        {
            string sha1 = Xmtool.Hash().SHA1("wangxiaoming");

            output.WriteLine("wangxiaoming sha1: " + sha1);
            Assert.Equal(40, sha1.Length);
        }
示例#2
0
        public void Md5()
        {
            string md5 = Xmtool.Hash().MD5("wangxiaoming");

            output.WriteLine("wangxiaoming md5: " + md5);
            Assert.Equal(32, md5.Length);
        }
示例#3
0
        public void Sha256()
        {
            string sha256 = Xmtool.Hash().SHA256("wangxiaoming");

            output.WriteLine("wangxiaoming sha256: " + sha256);
            Assert.Equal(64, sha256.Length);
        }
示例#4
0
        public void XmlInterate()
        {
            string aaaArg = string.Empty;

            string path  = Path.Combine(Environment.CurrentDirectory, "ioc.xml");
            bool   isObj = false;

            Xmtool.Xml().Iterate(path, (XmlNodeInfo node) =>
            {
                if (!node.IsEndNode)
                {
                    if (node.Path == "/objects/object")
                    {
                        isObj = node.GetAttribute("id") == "aaa";
                    }
                    else if (node.Path == "/objects/object/constructor-arg/@text")
                    {
                        if (isObj)
                        {
                            aaaArg = node.Text;
                        }
                    }

                    output.WriteLine(node.FullPath);
                }
                return(true);
            });

            Assert.Equal("\"wangxm\"", aaaArg);
        }
示例#5
0
        public void Test6()
        {
            string   timespan = "15";
            TimeSpan?ts       = Xmtool.DateTime().GetTimeSpanFromString(timespan);

            Assert.NotNull(ts);
            Assert.True(ts.Value.TotalSeconds == 15);
        }
示例#6
0
        public void Base64()
        {
            string source       = "wangxiaoming";
            string base64Encode = Xmtool.Crypto().Base64Encode(source);

            output.WriteLine("wangxiaoming base64: " + base64Encode);
            string base64Decode = Xmtool.Crypto().Base64Decode(base64Encode);

            Assert.Equal(base64Decode, source);
        }
示例#7
0
        public void Aes()
        {
            string source      = "wangxiaoming";
            string aesEncypted = Xmtool.Crypto().AESEncode(source, "test");

            output.WriteLine("wangxiaoming aes: " + aesEncypted);
            string aesDecrypted = Xmtool.Crypto().AESDecode(aesEncypted, "test");

            Assert.Equal(aesDecrypted, source);
        }
示例#8
0
 public void Test8()
 {
     try
     {
         bool bRet = Xmtool.DateTime().CheckStringTimeSpan("abc");
     }
     catch (Exception exp)
     {
         Assert.Contains("错误的时间段格式", exp.Message);
     }
 }
示例#9
0
        public void Test2()
        {
            DateTime dtNow = DateTime.Now;
            long     ts    = Xmtool.DateTime().GetUtcTimestamp13();

            Assert.True((ts + "").Length == 13);

            DateTime dt = Xmtool.DateTime().GetLocalDateTimeFromUtcTimestamp13(ts);

            Assert.Equal(dt.Year, dtNow.Year);
            Assert.Equal(dt.Month, dtNow.Month);
            Assert.Equal(dt.Day, dtNow.Day);
            Assert.Equal(dt.Hour, dtNow.Hour);
            Assert.Equal(dt.Minute, dtNow.Minute);
            Assert.Equal(dt.Second, dtNow.Second);
        }
示例#10
0
        public void XmlSerialize()
        {
            string  xml = @"<xml>
                <test id='demo'>
                    <hello id='aaa' />
                    <world>123</world>
                </test>
                <name><![CDATA[张三]]></name>
                <age>18</age>
                <gender>男</gender>
            </xml>";
            dynamic obj = Xmtool.Xml().DeserializeFromString(xml);

            Assert.NotNull(obj);
            Assert.Equal("张三", obj.name.Value);
            Assert.Equal("aaa", obj.test.hello.id);
        }
示例#11
0
        public void Test()
        {
            string a = Xmtool.Captcha().Random(4);
            string b = Xmtool.Captcha().Random(4);
            string c = Xmtool.Captcha().Random(4);

            string d = Xmtool.Captcha().RandomOnlyNumber(4);
            string e = Xmtool.Captcha().RandomOnlyNumber(4);
            string f = Xmtool.Captcha().RandomOnlyNumber(4);

            string       code;
            MemoryStream stream;

            Xmtool.Captcha().Build(100, 45, out stream, out code, true, 4);

            Assert.Equal(4, code.Length);
            Assert.NotNull(stream);
            Assert.True(stream.Length > 0);
        }
示例#12
0
        public void XmlNodeLevel()
        {
            string xml = @"<xml>
                <name><![CDATA[张三]]></name>
                <age>18</age>
                <gender>男</gender>
            </xml>";

            int nameLevel = 0;

            Xmtool.Xml().IterateFromString(xml, (XmlNodeInfo node) =>
            {
                if (node.Path == "/xml/name")
                {
                    nameLevel = node.Level;
                }
                return(true);
            });
            Assert.Equal(2, nameLevel);
        }
示例#13
0
        public void XmlRootNode()
        {
            string xml = @"<xml>
                <name><![CDATA[张三]]></name>
                <age>18</age>
                <gender>男</gender>
            </xml>";

            bool xmlIsRoot = false;

            Xmtool.Xml().IterateFromString(xml, (XmlNodeInfo node) =>
            {
                if (node.Path == "/xml")
                {
                    xmlIsRoot = node.IsRoot;
                }
                return(true);
            });
            Assert.True(xmlIsRoot);
        }
示例#14
0
        public void XmlIterateFromString()
        {
            int age = 0;

            string xml = @"<xml>
                <name>уехЩ</name>
                <age>18</age>
                <gender>дп</gender>
            </xml>";

            Xmtool.Xml().IterateFromString(xml, (XmlNodeInfo node) =>
            {
                if (!node.IsEndNode)
                {
                    if (node.Path == "/xml/age/@text")
                    {
                        age = int.Parse(node.Text);
                    }
                }
                return(true);
            });

            Assert.Equal(18, age);
        }
示例#15
0
        public void DecimalTest9()
        {
            bool ret = Xmtool.Regex().IsDecimal("");

            Assert.False(ret);
        }
示例#16
0
        public void PositiveIntTest7()
        {
            bool ret = Xmtool.Regex().IsPositiveInteger("");

            Assert.False(ret);
        }
示例#17
0
        public void NaturalIntTest2()
        {
            bool ret = Xmtool.Regex().IsNaturalInteger("10");

            Assert.True(ret);
        }
示例#18
0
        public void NaturalIntTest6()
        {
            bool ret = Xmtool.Regex().IsNaturalInteger("");

            Assert.False(ret);
        }
示例#19
0
        public void DecimalTest2()
        {
            bool ret = Xmtool.Regex().IsDecimal("0.2");

            Assert.True(ret);
        }
示例#20
0
        public void DecimalTest4()
        {
            bool ret = Xmtool.Regex().IsDecimal("-0.9");

            Assert.True(ret);
        }
示例#21
0
        public void Test7()
        {
            bool bRet = Xmtool.DateTime().CheckStringTimeSpan("1s");

            Assert.True(bRet);
        }
示例#22
0
        private void _CheckProperyValue(string name, object value)
        {
            Property p = mModel.GetProperty(name);

            if (p.IsNotNull && value == null)
            {
                throw new Exception(string.Concat("属性值不能为空:", name));
            }

            if (value != null)
            {
                if (FieldUtils.IsNumeric(p.FieldType))
                {
                    if (!Xmtool.Regex().IsNumber(value.ToString()))
                    {
                        throw new Exception(string.Concat(p.Name, "属性值期待类型:", p.FieldType, ",实际类型为:", value.GetType()));
                    }
                }
                else if (p.FieldType == DbType.Boolean)
                {
                    Type _typ = value.GetType();
                    if (_typ != typeof(bool))
                    {
                        bool result;
                        if (!bool.TryParse(value.ToString(), out result))
                        {
                            throw new Exception(string.Concat(p.Name, "属性值期待类型:", p.FieldType, ",实际类型为:", _typ));
                        }
                    }
                }
                else if (p.FieldType == DbType.Date ||
                         p.FieldType == DbType.DateTime ||
                         p.FieldType == DbType.DateTime2)
                {
                    DateTime result;
                    if (!DateTime.TryParse(value.ToString(), out result))
                    {
                        throw new Exception(string.Concat(p.Name, "属性值期待类型:", p.FieldType, ",实际类型为:", value.GetType()));
                    }
                }

                if (p.RealType == typeof(string) && p.Length > 0)
                {
                    if (value.ToString().Length > p.Length)
                    {
                        throw new Exception(string.Concat(p.Name, "属性值最大长度不能超过", p.Length, ":", name));
                    }
                }
                else if (FieldUtils.IsNumeric(p.FieldType))
                {
                    double dValue = double.Parse(value.ToString());
                    if (p.MinValue != null)
                    {
                        if (dValue < p.MinValue)
                        {
                            throw new Exception(string.Concat(p.Name, "属性值取值限制范围:", p.MinValue, "-", p.MaxValue));
                        }
                    }
                    if (p.MaxValue != null)
                    {
                        if (dValue > p.MaxValue)
                        {
                            throw new Exception(string.Concat(p.Name, "属性值取值限制范围:", p.MinValue, "-", p.MaxValue));
                        }
                    }
                }
            }
        }
示例#23
0
        public void MobileTest6()
        {
            bool ret = Xmtool.Regex().IsMobile("");

            Assert.False(ret);
        }
示例#24
0
        public void Test9()
        {
            bool bRet = Xmtool.DateTime().CheckStringTimeSpan("abc", false);

            Assert.False(bRet);
        }
示例#25
0
        public void EmailTest2()
        {
            bool ret = Xmtool.Regex().IsEmail("*****@*****.**");

            Assert.True(ret);
        }
示例#26
0
        public void MobileTest4()
        {
            bool ret = Xmtool.Regex().IsMobile("1361234567");

            Assert.False(ret);
        }
示例#27
0
        private static ConnectionSetting ParseConnectionSetting(string connectionFilePath)
        {
            ConnectionSetting result = new ConnectionSetting();

            Xmtool.Xml().Iterate(connectionFilePath, (nodeInfo) => {
                if (!nodeInfo.IsEndNode)
                {
                    if (nodeInfo.Path == "/connection/dialect/@text")
                    {
                        result.Dialect = nodeInfo.Text.Trim().ToLower();
                    }
                    else if (nodeInfo.Path == "/connection/host/@text")
                    {
                        result.Host = nodeInfo.Text.Trim();
                    }
                    else if (nodeInfo.Path == "/connection/port/@text")
                    {
                        int port;
                        if (int.TryParse(nodeInfo.Text, out port))
                        {
                            result.Port = port;
                        }
                        else
                        {
                            throw new Exception("name属性不能为空。 " + connectionFilePath + " - Line " + nodeInfo.Line);
                        }
                    }
                    else if (nodeInfo.Path == "/connection/user/@text")
                    {
                        result.User = nodeInfo.Text.Trim();
                    }
                    else if (nodeInfo.Path == "/connection/password/@text")
                    {
                        result.Password = nodeInfo.Text.Trim();
                    }
                    else if (nodeInfo.Path == "/connection/database/@text")
                    {
                        result.Database = nodeInfo.Text.Trim();
                    }
                    else if (nodeInfo.Path == "/connection/charset/@text")
                    {
                        result.Charset = nodeInfo.Text.Trim();
                    }
                    else if (nodeInfo.Path == "/connection/encrypt/@text")
                    {
                        if (!reBool.IsMatch(nodeInfo.Text.Trim()))
                        {
                            throw new Exception("encrypt节点值必须是布尔型。 " + connectionFilePath + " - Line " + nodeInfo.Line);
                        }
                        result.Encrypt = bool.Parse(nodeInfo.Text.Trim());
                    }
                    else if (nodeInfo.Path == "/connection/pool")
                    {
                        string maxStr = nodeInfo.GetAttribute("max");
                        if (!Xmtool.Regex().IsPositiveInteger(maxStr))
                        {
                            throw new Exception("max属性必须是有效正整数。 " + connectionFilePath + " - Line " + nodeInfo.Line);
                        }
                        result.MaxPoolSize = int.Parse(maxStr);

                        string minStr = nodeInfo.GetAttribute("min");
                        if (!Xmtool.Regex().IsNaturalInteger(minStr))
                        {
                            throw new Exception("min属性必须是有效自然数。 " + connectionFilePath + " - Line " + nodeInfo.Line);
                        }
                        result.MinPoolSize = int.Parse(minStr);
                    }
                    else if (nodeInfo.Path == "/connection/pool/@text")
                    {
                        if (!reBool.IsMatch(nodeInfo.Text.Trim()))
                        {
                            throw new Exception("pool节点值必须是布尔型。 " + connectionFilePath + " - Line " + nodeInfo.Line);
                        }
                        result.Pooling = bool.Parse(nodeInfo.Text.Trim());
                    }
                }
                return(true);
            });
            return(result);
        }
示例#28
0
        public void CheckListType()
        {
            List <string> lst = new List <string>();

            Assert.True(Xmtool.Type().IsList(lst));
        }
示例#29
0
        internal static Model ParseModel(string modelFilePath, string parent)
        {
            Model model = new Model();

            model.Path = parent.ToLower();

            Xmtool.Xml().Iterate(modelFilePath, (nodeInfo) =>
            {
                if (nodeInfo.Path == "/model")
                {
                    if (!nodeInfo.IsEndNode)
                    {
                        string name = nodeInfo.GetAttribute("name");
                        if (name == null)
                        {
                            throw new Exception("缺少name属性。 " + modelFilePath + " - Line " + nodeInfo.Line);
                        }
                        else if (string.IsNullOrWhiteSpace(name))
                        {
                            throw new Exception("name属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                        }
                        model.Name = name.Trim();

                        string table = nodeInfo.GetAttribute("table");
                        if (table != null)
                        {
                            if (string.IsNullOrWhiteSpace(table))
                            {
                                throw new Exception("table属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                            model.Table = table.Trim();
                        }
                        else
                        {
                            model.Table = model.Name;
                        }

                        string beforeSaveProcStr = nodeInfo.GetAttribute("beforeSave");
                        if (beforeSaveProcStr != null)
                        {
                            beforeSaveProcStr = beforeSaveProcStr.Trim();
                            if (beforeSaveProcStr.Length > 4 &&
                                beforeSaveProcStr.StartsWith("{{") &&
                                beforeSaveProcStr.EndsWith("}}"))
                            {
                                model.BeforeSaveProcessor = beforeSaveProcStr.Substring(2, beforeSaveProcStr.Length - 4);
                            }
                            else
                            {
                                throw new Exception("beforeSave属性必须是Processor。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string afterSaveProcStr = nodeInfo.GetAttribute("afterSave");
                        if (afterSaveProcStr != null)
                        {
                            afterSaveProcStr = afterSaveProcStr.Trim();
                            if (afterSaveProcStr.Length > 4 &&
                                afterSaveProcStr.StartsWith("{{") &&
                                afterSaveProcStr.EndsWith("}}"))
                            {
                                model.AfterSaveProcessor = afterSaveProcStr.Substring(2, afterSaveProcStr.Length - 4);
                            }
                            else
                            {
                                throw new Exception("afterSave属性必须是Processor。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string beforeDeleteProcStr = nodeInfo.GetAttribute("beforeDelete");
                        if (beforeDeleteProcStr != null)
                        {
                            beforeDeleteProcStr = beforeDeleteProcStr.Trim();
                            if (beforeDeleteProcStr.Length > 4 &&
                                beforeDeleteProcStr.StartsWith("{{") &&
                                beforeDeleteProcStr.EndsWith("}}"))
                            {
                                model.BeforeDeleteProcessor = beforeDeleteProcStr.Substring(2, beforeDeleteProcStr.Length - 4);
                            }
                            else
                            {
                                throw new Exception("beforeDelete属性必须是Processor。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string afterDeleteProcStr = nodeInfo.GetAttribute("afterDelete");
                        if (afterDeleteProcStr != null)
                        {
                            afterDeleteProcStr = afterDeleteProcStr.Trim();
                            if (afterDeleteProcStr.Length > 4 &&
                                afterDeleteProcStr.StartsWith("{{") &&
                                afterDeleteProcStr.EndsWith("}}"))
                            {
                                model.AfterDeleteProcessor = afterDeleteProcStr.Substring(2, afterDeleteProcStr.Length - 4);
                            }
                            else
                            {
                                throw new Exception("afterDelete属性必须是Processor。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }
                    }
                }
                else if (nodeInfo.Path == "/model/property")
                {
                    if (!nodeInfo.IsEndNode)
                    {
                        Property p = new Property();
                        DelayCheckPropertySetting dcps = null;

                        string name = nodeInfo.GetAttribute("name");
                        if (name == null)
                        {
                            throw new Exception("缺少name属性。 " + modelFilePath + " - Line " + nodeInfo.Line);
                        }
                        else if (string.IsNullOrWhiteSpace(name))
                        {
                            throw new Exception("name属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                        }
                        p.Name = name.Trim();

                        string field = nodeInfo.GetAttribute("field");
                        if (field != null)
                        {
                            if (string.IsNullOrWhiteSpace(field))
                            {
                                throw new Exception("field属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                            p.Field = field.Trim();
                        }
                        else
                        {
                            p.Field = string.Concat("f_", p.Name.ToLower());
                        }

                        Type type      = typeof(string);
                        string typeStr = nodeInfo.GetAttribute("type");
                        if (typeStr != null)
                        {
                            type = GetPropertyType(typeStr);
                            if (type == null)
                            {
                                throw new Exception("type属性非法。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                            else if (type == typeof(Model) ||
                                     type == typeof(DynamicObjectExt))
                            {
                                p.TypeValue = typeStr;

                                dcps          = new DelayCheckPropertySetting();
                                dcps.Position = modelFilePath + " - Line " + nodeInfo.Line;
                            }
                        }
                        else
                        {
                            string aiStr = nodeInfo.GetAttribute("autoIncrement");
                            if (aiStr != null)
                            {
                                if (!string.IsNullOrWhiteSpace(aiStr) &&
                                    reBool.IsMatch(aiStr))
                                {
                                    type = typeof(Int32);
                                }
                            }
                        }
                        p.Type     = type;
                        p.RealType = type;

                        string joinPropStr = nodeInfo.GetAttribute("joinProp");
                        if (joinPropStr != null)
                        {
                            if (p.Type == typeof(Model))
                            {
                                if (string.IsNullOrWhiteSpace(joinPropStr))
                                {
                                    throw new Exception("joinProp属性不能为空。" + modelFilePath + " - Line " + nodeInfo.Line);
                                }
                                p.JoinProp = joinPropStr.Trim();
                            }
                            else
                            {
                                throw new Exception("joinProp属性只在type属性为Model类型时有效。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string fieldTypeStr = nodeInfo.GetAttribute("fieldType");
                        if (fieldTypeStr != null)
                        {
                            if (type == typeof(DynamicObjectExt))
                            {
                                throw new Exception(typeStr + "类型的Property禁止设置fieldType。" + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            try
                            {
                                p.FieldType = Enum.Parse <DbType>(fieldTypeStr, true);
                                p.RealType  = DbType2Type(p.FieldType);
                            }
                            catch
                            {
                                throw new Exception("fieldType属性非法。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }
                        else
                        {
                            p.FieldType = Type2DbType(type);
                            if (p.Type == typeof(Model))
                            {
                                dcps.FieldTypeNotSet = true;
                            }
                        }

                        string lengthStr = nodeInfo.GetAttribute("length");
                        if (lengthStr != null)
                        {
                            if (string.IsNullOrWhiteSpace(lengthStr))
                            {
                                throw new Exception("length属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            if (!Xmtool.Regex().IsPositiveInteger(lengthStr))
                            {
                                throw new Exception("length属性必须是有效正整数。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            p.Length = int.Parse(lengthStr);
                        }
                        else
                        {
                            p.Length = FieldUtils.GetFieldLength(model, p.FieldType);
                            if (p.Type == typeof(DynamicObjectExt))
                            {
                                p.Length = 512;
                            }
                            else if (p.Type == typeof(Model))
                            {
                                dcps.LengthNotSet = true;
                            }
                        }

                        string minStr = nodeInfo.GetAttribute("min");
                        if (minStr != null)
                        {
                            if (FieldUtils.IsNumeric(p.FieldType))
                            {
                                if (string.IsNullOrWhiteSpace(minStr))
                                {
                                    throw new Exception("min属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                if (!Xmtool.Regex().IsNumber(minStr))
                                {
                                    throw new Exception("min属性必须是有效数值。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                p.MinValue = double.Parse(minStr);
                            }
                            else
                            {
                                throw new NotSupportedException(p.FieldType.ToString() + "类型不支持min设置。" + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string maxStr = nodeInfo.GetAttribute("max");
                        if (maxStr != null)
                        {
                            if (FieldUtils.IsNumeric(p.FieldType))
                            {
                                if (string.IsNullOrWhiteSpace(maxStr))
                                {
                                    throw new Exception("max属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                if (!Xmtool.Regex().IsNumber(maxStr))
                                {
                                    throw new Exception("max属性必须是有效数值。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                p.MaxValue = double.Parse(maxStr);
                            }
                            else
                            {
                                throw new NotSupportedException(p.FieldType.ToString() + "类型不支持max设置。" + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string precisionStr = nodeInfo.GetAttribute("precision");
                        if (precisionStr != null)
                        {
                            if (FieldUtils.IsFloat(p.FieldType))
                            {
                                if (string.IsNullOrWhiteSpace(precisionStr))
                                {
                                    throw new Exception("precision属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                if (!Xmtool.Regex().IsNaturalInteger(precisionStr))
                                {
                                    throw new Exception("precision属性必须是有效自然数。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                p.Precision = int.Parse(precisionStr);
                            }
                            else
                            {
                                throw new NotSupportedException(p.FieldType.ToString() + "类型不支持precision设置。" + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string notNullStr = nodeInfo.GetAttribute("notNull");
                        if (notNullStr != null)
                        {
                            if (string.IsNullOrWhiteSpace(notNullStr))
                            {
                                throw new Exception("notNull属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            if (!reBool.IsMatch(notNullStr))
                            {
                                throw new Exception("notNull属性必须是布尔型。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            p.IsNotNull = bool.Parse(notNullStr);
                        }

                        string descStr = nodeInfo.GetAttribute("desc");
                        if (!string.IsNullOrEmpty(descStr))
                        {
                            p.Description = descStr;
                        }

                        string autoIncrStr = nodeInfo.GetAttribute("autoIncrement");
                        if (autoIncrStr != null)
                        {
                            if (FieldUtils.IsInteger(p.FieldType))
                            {
                                if (string.IsNullOrWhiteSpace(autoIncrStr))
                                {
                                    throw new Exception("autoIncrement属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                if (!reBool.IsMatch(autoIncrStr))
                                {
                                    throw new Exception("autoIncrement属性必须是布尔型。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                p.AutoIncrement = bool.Parse(autoIncrStr);
                            }
                            else
                            {
                                throw new NotSupportedException(p.FieldType.ToString() + "类型不支持autoIncrement设置。" + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string unsignedStr = nodeInfo.GetAttribute("unsigned");
                        if (unsignedStr != null)
                        {
                            if (FieldUtils.IsNumeric(p.FieldType))
                            {
                                if (string.IsNullOrWhiteSpace(unsignedStr))
                                {
                                    throw new Exception("unsigned属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                if (!reBool.IsMatch(unsignedStr))
                                {
                                    throw new Exception("unsigned属性必须是布尔型。 " + modelFilePath + " - Line " + nodeInfo.Line);
                                }

                                p.Unsigned = bool.Parse(unsignedStr);
                            }
                            else
                            {
                                throw new NotSupportedException(p.FieldType.ToString() + "类型不支持unsigned设置。" + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string uniqueGroupStr = nodeInfo.GetAttribute("uniqueGroup");
                        if (uniqueGroupStr != null)
                        {
                            if (string.IsNullOrWhiteSpace(uniqueGroupStr))
                            {
                                throw new Exception("uniqueGroup属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                            p.UniqueGroup = uniqueGroupStr.Trim();
                        }

                        string indexGroupStr = nodeInfo.GetAttribute("indexGroup");
                        if (indexGroupStr != null)
                        {
                            if (string.IsNullOrWhiteSpace(indexGroupStr))
                            {
                                throw new Exception("indexGroup属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                            p.IndexGroup = indexGroupStr.Trim();
                        }

                        string primaryStr = nodeInfo.GetAttribute("primary");
                        if (primaryStr != null)
                        {
                            if (string.IsNullOrWhiteSpace(primaryStr))
                            {
                                throw new Exception("primary属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            if (!reBool.IsMatch(primaryStr))
                            {
                                throw new Exception("primary属性必须是布尔型。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            p.IsPrimaryKey = bool.Parse(primaryStr);
                        }

                        string defaultStr = nodeInfo.GetAttribute("defaultValue");
                        if (defaultStr != null)
                        {
                            p.DefaultValue = defaultStr.Trim();
                        }

                        string beforeProcStr = nodeInfo.GetAttribute("beforeSave");
                        if (beforeProcStr != null)
                        {
                            beforeProcStr = beforeProcStr.Trim();
                            if (beforeProcStr.Length > 4 &&
                                beforeProcStr.StartsWith("{{") &&
                                beforeProcStr.EndsWith("}}"))
                            {
                                p.BeforeSaveProcessor = beforeProcStr.Substring(2, beforeProcStr.Length - 4);
                            }
                            else
                            {
                                throw new Exception("beforeSave属性必须是Processor。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string afterProcStr = nodeInfo.GetAttribute("afterQuery");
                        if (afterProcStr != null)
                        {
                            afterProcStr = afterProcStr.Trim();
                            if (afterProcStr.Length > 4 &&
                                afterProcStr.StartsWith("{{") &&
                                afterProcStr.EndsWith("}}"))
                            {
                                p.AfterQueryProcessor = afterProcStr.Substring(2, afterProcStr.Length - 4);
                            }
                            else
                            {
                                throw new Exception("afterQuery属性必须是Processor。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }
                        }

                        string joinInsertStr = nodeInfo.GetAttribute("joinInsert");
                        if (joinInsertStr != null)
                        {
                            if (string.IsNullOrWhiteSpace(joinInsertStr))
                            {
                                throw new Exception("joinInsert属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            if (!reBool.IsMatch(joinInsertStr))
                            {
                                throw new Exception("joinInsert属性必须是布尔型。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            p.JoinInsert = bool.Parse(joinInsertStr);
                        }

                        string joinUpdateStr = nodeInfo.GetAttribute("joinUpdate");
                        if (joinUpdateStr != null)
                        {
                            if (string.IsNullOrWhiteSpace(joinUpdateStr))
                            {
                                throw new Exception("joinUpdate属性不能为空。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            if (!reBool.IsMatch(joinUpdateStr))
                            {
                                throw new Exception("joinUpdate属性必须是布尔型。 " + modelFilePath + " - Line " + nodeInfo.Line);
                            }

                            p.JoinUpdate = bool.Parse(joinUpdateStr);
                        }

                        model.AddProperty(p);

                        if (dcps != null)
                        {
                            sDelayCheckProperties.TryAdd(p, dcps);
                        }
                    }
                }

                return(true);
            });
            return(model);
        }
示例#30
0
        public void PositiveIntTest2()
        {
            bool ret = Xmtool.Regex().IsPositiveInteger("2");

            Assert.True(ret);
        }