Exemplo n.º 1
0
        /// <summary>
        /// 用数据实体中属于基本类型(int,string,bool等)的属性及其值来创建DbParameter集合
        /// </summary>
        /// <param name="dataType">数据类型(数据实体属性类型)</param>
        /// <param name="dbTag">数据源参数类型(如:sqlserver参数类型为@, mysql参数类型为?, oracle为:)</param>
        /// <param name="data">数据源属性值</param>
        /// <param name="fieldName">sql语句中字段名称(同时也是数据实体属性名称)</param>
        /// <param name="dbParas">DbParameter集合</param>
        public void GetDbParaByBaseType(Type dataType, string dbTag, object data, string fieldName, DbList <DbParameter> dbParas)
        {
            if (!DJTools.IsBaseType(dataType))
            {
                return;
            }

            object val = DJTools.ConvertTo(data, dataType);

            val = null == val ? DBNull.Value : val;
            dbParas.Add(fieldName, val);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 配置文件配置规则(多项配置换行):
        /// {DllRelativePathOfImpl="BLL.dll",ImplementNameSpace="BLL.SaleOrder",MatchImplExpression="^data.+",InterFaceName="IGetSaleOrderInfo",IgnoreCase=true}
        /// {DllRelativePathOfImpl="BLL.dll",ImplementNameSpace="BLL.MemberManage.impl",MatchImplExpression="^produce.+",InterFaceName="BLL.MemberManage.IProduceMaintain",IgnoreCase=true}
        /// </summary>
        /// <returns></returns>
        private static EList <CKeyValue> MatchRules()
        {
            EList <CKeyValue> list = new EList <CKeyValue>();
            string            file = Path.Combine(rootPath, configFile);

            if (!File.Exists(file))
            {
                defaultConfig(file);
            }

            if (!File.Exists(file))
            {
                return(list);
            }

            LogsRange logsRange1 = new LogsRange();

            string[]  arr = File.ReadAllLines(file);
            MatchRule mr  = null;

            string       FieldName  = "";
            string       FieldValue = "";
            int          n          = 0;
            Match        m          = null;
            PropertyInfo pi         = null;
            object       v          = null;
            RuleType     tag        = RuleType.none;
            object       entity     = null;

            string s = "";// @"(?<FieldName>[^\{\=\,\s]+)\s*\=\s*((""(?<FieldValue>[^""\}\,]+)"")|(?<FieldValue>[^""\}\=\,\s]+))";

            s = @"(?<FieldName>[^\{\=\,\s]+)\s*\=\s*((""(?<FieldValue>[^""]+)"")|(?<FieldValue>[^""\}\=\,\s]+))";
            Regex rg = new Regex(s, RegexOptions.IgnoreCase);

            foreach (string item in arr)
            {
                s   = item;
                n   = 0;
                tag = RuleType.none;
                while (rg.IsMatch(s) && 20 > n)
                {
                    m          = rg.Match(s);
                    FieldName  = m.Groups["FieldName"].Value;
                    FieldValue = m.Groups["FieldValue"].Value;
                    if (0 == n)
                    {
                        pi  = GetPropertyInfoByName(typeof(DbInfo), FieldName);
                        tag = null != pi ? RuleType.DbInfo : tag;

                        if (null == pi)
                        {
                            pi  = GetPropertyInfoByName(typeof(MatchRule), FieldName);
                            tag = null != pi ? RuleType.MatchRule : tag;
                            if (RuleType.MatchRule == tag)
                            {
                                mr = new MatchRule();
                            }
                        }

                        if (null == pi)
                        {
                            pi  = GetPropertyInfoByName(typeof(LogsRange), FieldName);
                            tag = null != pi ? RuleType.LogsRange : tag;
                        }
                    }

                    if (RuleType.DbInfo == tag)
                    {
                        pi     = GetPropertyInfoByName(typeof(DbInfo), FieldName);
                        entity = ImplementAdapter.dbInfo;
                    }
                    else if (RuleType.MatchRule == tag)
                    {
                        pi     = GetPropertyInfoByName(typeof(MatchRule), FieldName);
                        entity = mr;
                    }
                    else if (RuleType.LogsRange == tag)
                    {
                        pi     = GetPropertyInfoByName(typeof(LogsRange), FieldName);
                        entity = logsRange1;
                    }

                    if (null != pi)
                    {
                        v = DJTools.ConvertTo(FieldValue, pi.PropertyType);
                        try
                        {
                            entity.GetType().GetProperty(pi.Name).SetValue(entity, v, null);
                        }
                        catch { }
                    }

                    s = s.Replace(m.Groups[0].Value, "");
                    n++;
                }

                if (RuleType.MatchRule == tag)
                {
                    if (string.IsNullOrEmpty(mr.MatchImplExpression))
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(mr.InterFaceName))
                    {
                        continue;
                    }

                    list.Add(new CKeyValue()
                    {
                        Key = mr.InterFaceName, Value = mr
                    });
                    mr = null;
                }
            }

            errorLevels1.Clear();
            ErrorLevels el1   = ErrorLevels.severe;
            bool        bool1 = Enum.TryParse(logsRange1.upperLimit, out el1);

            if (!bool1)
            {
                el1 = ErrorLevels.severe;
            }
            errorLevels1.Add(el1);

            ErrorLevels el2 = ErrorLevels.debug;

            bool1 = Enum.TryParse(logsRange1.lowerLimit, out el2);
            if (!bool1)
            {
                el2 = ErrorLevels.debug;
            }
            errorLevels1.Add(el2);
            return(list);
        }