private int Enemies() { Random rand = new Random(); Random rd = new Random(); int v = rand.Next(10) + 5; ens.Clear(); for (int i = 0; i < v; i++) { int w = rd.Next(700) + 400; int x = rd.Next(100) * 10; Enemy2 en = new Enemy2(w, x); ens.Add(en); } es.Add(ens); return(es.Count - 1); }
/// <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); }
public string GetParametersBySqlParameter(string sql, string sqlVarName, MethodInformation method, DataOptType dataOptType, ref string dbParaListVarName) { string code = ""; string sql1 = sql; string executeDbHelper = "{ExecuteDbHelper#}"; string leftSpace = ""; Regex rg = rgParaField; if (string.IsNullOrEmpty(dbParaListVarName) || dbParaListVarName.ToLower().Equals("null")) { dbParaListVarName = "dbParaList"; method.append(ref code, LeftSpaceLevel.one, "DbList<System.Data.Common.DbParameter> {0} = new DbList<System.Data.Common.DbParameter>();", dbParaListVarName); } string dbHelperVarName = "dbHelper"; string resultVarName = "successVal"; string funcResultVarName = method.methodComponent.ResultVariantName; if (baseTypeWithResult(method)) { method.append(ref code, LeftSpaceLevel.one, "int {0} = 0;", resultVarName); } else { method.append(ref code, LeftSpaceLevel.one, "{0} {1} = default({0});", method.methodComponent.ResultType.FullName, resultVarName); } method.append(ref code, LeftSpaceLevel.one, "string err = \"\";"); method.append(ref code, LeftSpaceLevel.one, "IDbHelper {0} = ImplementAdapter.DbHelper;", dbHelperVarName); if (rg.IsMatch(sql) && 0 < method.paraList.Count) { string LeftSign = ""; string EndSign = ""; string DbTag = ""; string FieldName = ""; string autoCallName = method.AutoCallVarName; Match match = null; EList <CKeyValue> sqlParaList1 = new EList <CKeyValue>(); string sqlParasVarName = "sqlParaList"; method.append(ref code, LeftSpaceLevel.one, "EList<CKeyValue> {0} = new EList<CKeyValue>();", sqlParasVarName); int n = 0; while (rg.IsMatch(sql1) && 200 > n) { match = rg.Match(sql1); LeftSign = match.Groups["LeftSign"].Value; EndSign = match.Groups["EndSign"].Value; if (isEnabledField(LeftSign)) { if (string.IsNullOrEmpty(DbTag)) { DbTag = match.Groups["DbTag"].Value; } FieldName = match.Groups["FieldName"].Value; method.append(ref code, LeftSpaceLevel.one, "{0}.Add(new CKeyValue(){ Key = \"{1}\", Value = \"{2}\", other = \"{3}\" });", sqlParasVarName, FieldName.ToLower(), FieldName, DbTag); sqlParaList1.Add(new CKeyValue() { Key = FieldName.ToLower(), Value = FieldName, other = DbTag }); } sql1 = sql1.Replace(match.Groups[0].Value, ""); sql1 = EndSign + sql1; n++; } Regex rg1 = new Regex(@"\`[0-9]+\["); CKeyValue kv = null; PList <Para> paraList = method.paraList; string paraClassName = ""; //DJTools.GetParamertClassNameByDbTag(DbTag); foreach (Para para in paraList) { if (para.ParaType.BaseType == typeof(System.MulticastDelegate) && rg1.IsMatch(para.ParaType.ToString())) { continue; } if (DJTools.IsBaseType(para.ParaType)) { //方法参数为基本类型 string, int, bool 等 kv = sqlParaList1[para.ParaName.ToLower()]; if (null == kv) { continue; } method.append(ref code, LeftSpaceLevel.one, "{0}.Add(\"{2}\", {3});", dbParaListVarName, paraClassName, kv.Value.ToString(), para.ParaName); } else { LeftSpaceLevel leftSpaceLevel = LeftSpaceLevel.one; if (null != para.ParaType.GetInterface("IEnumerable")) { //集合复杂类型 //ICollection collection = (ICollection)para.ParaValue; method.append(ref code, LeftSpaceLevel.one, ""); method.append(ref code, LeftSpaceLevel.one, "System.Collections.ICollection collection = (System.Collections.ICollection){0};", para.ParaName); method.append(ref code, LeftSpaceLevel.one, ""); if (null != para.ParaType.GetInterface("IDictionary")) { method.append(ref code, leftSpaceLevel, "//键值对情况"); method.append(ref code, leftSpaceLevel, "object vObj = null;"); method.append(ref code, leftSpaceLevel, "string key = \"\";"); method.append(ref code, leftSpaceLevel, "foreach (var item in collection)"); method.append(ref code, leftSpaceLevel, "{"); method.append(ref code, leftSpaceLevel + 1, "key = item.GetType().GetProperty(\"Key\").GetValue(item, null).ToString();"); method.append(ref code, leftSpaceLevel + 1, "vObj = item.GetType().GetProperty(\"Value\").GetValue(item, null);"); method.append(ref code, leftSpaceLevel + 1, "if (DJTools.IsBaseType(vObj.GetType())) break;"); method.append(ref code, leftSpaceLevel + 1, "if (null != vObj.GetType().GetInterface(\"IEnumerable\")) break;"); method.append(ref code, leftSpaceLevel + 1, "//值必须是简单类型:int, string, bool, float, double等"); method.append(ref code, leftSpaceLevel + 1, ""); //Type dataType, string dbTag, object data, string fieldName, List<DbParameter> dbParas method.append(ref code, leftSpaceLevel + 1, "{0}.GetDbParaByBaseType(typeof(string),\"{1}\",vObj,key,{2});", autoCallName, DbTag, dbParaListVarName); method.append(ref code, leftSpaceLevel + 1, ""); method.append(ref code, leftSpaceLevel, "}"); //foreach (var item in collection) } else if (null != para.ParaType.GetInterface("IList") || para.ParaType.IsArray) { leftSpace = method.StartSpace + method.getSpace((int)leftSpaceLevel); method.append(ref code, leftSpaceLevel, "//List集合情况 或 数组情况"); method.append(ref code, leftSpaceLevel, "foreach (var item in collection)"); method.append(ref code, leftSpaceLevel, "{"); method.append(ref code, leftSpaceLevel + 1, "if (DJTools.IsBaseType(item.GetType())) break;"); method.append(ref code, leftSpaceLevel + 1, "if (null != item.GetType().GetInterface(\"IEnumerable\")) break;"); method.append(ref code, leftSpaceLevel + 1, "//集合元素必须是单体复杂对象(数据实体)"); //object entity, List<DbParameter> dbParas, EList<CKeyValue> paraNameList method.append(ref code, leftSpaceLevel + 1, "{0}.GetDbParaListByEntity(item,{1},{2});", autoCallName, dbParaListVarName, sqlParasVarName); code += "\r\n" + executeDbHelper; method.append(ref code, leftSpaceLevel + 1, ""); method.append(ref code, leftSpaceLevel, "}"); //foreach (var item in collection) } } else if (typeof(DataTable) == para.ParaType) { leftSpace = method.StartSpace + method.getSpace((int)leftSpaceLevel); method.append(ref code, LeftSpaceLevel.one, ""); method.append(ref code, LeftSpaceLevel.one, "{0} = null == {0} ? new System.Data.DataTable() : {0};", para.ParaName); method.append(ref code, LeftSpaceLevel.one, "System.Data.DataTable dtable = (System.Data.DataTable){0};", para.ParaName); method.append(ref code, LeftSpaceLevel.one, "EList<CKeyValue> tableColumns = new EList<CKeyValue>();"); method.append(ref code, LeftSpaceLevel.one, ""); method.append(ref code, leftSpaceLevel, "foreach(System.Data.DataColumn c in dtable.Columns)"); method.append(ref code, leftSpaceLevel, "{"); method.append(ref code, leftSpaceLevel + 1, "tableColumns.Add(new CKeyValue(){ Key = c.ColumnName.ToLower(), Value = c.ColumnName, other = c.DataType });"); method.append(ref code, leftSpaceLevel, "}"); method.append(ref code, leftSpaceLevel, ""); method.append(ref code, leftSpaceLevel, "foreach(System.Data.DataRow dr in dtable.Rows)"); method.append(ref code, leftSpaceLevel, "{"); //GetDbParaByDataRow(DataRow row, List<DbParameter> dbParas, EList<CKeyValue> sqlParaNameList, EList<CKeyValue> tableColumns) method.append(ref code, leftSpaceLevel + 1, "{0}.GetDbParaByDataRow(dr,{1},{2},tableColumns);", autoCallName, dbParaListVarName, sqlParasVarName); code += "\r\n" + executeDbHelper; method.append(ref code, leftSpaceLevel + 1, ""); method.append(ref code, leftSpaceLevel, "}");//foreach(var dr in dtable.Rows) } else { //单体复杂类型(数据实体) //object entity, List<DbParameter> dbParas, EList<CKeyValue> paraNameList method.append(ref code, LeftSpaceLevel.one, ""); method.append(ref code, LeftSpaceLevel.one, "//单体复杂类型(数据实体) "); method.append(ref code, LeftSpaceLevel.one, "{0}.GetDbParaListByEntity({1},{2},{3});", autoCallName, para.ParaName, dbParaListVarName, sqlParasVarName); method.append(ref code, LeftSpaceLevel.one, ""); } } } } if (string.IsNullOrEmpty(leftSpace)) { method.append(ref code, LeftSpaceLevel.one, ""); ExecuteSqlCode(method, LeftSpaceLevel.one, dataOptType, sqlVarName, dbParaListVarName, dbHelperVarName, resultVarName, ref code); } else { string code1 = ""; ExecuteSqlCode(method, LeftSpaceLevel.two, dataOptType, sqlVarName, dbParaListVarName, dbHelperVarName, resultVarName, ref code1); code = code.Replace(executeDbHelper, code1); } if (!string.IsNullOrEmpty(funcResultVarName)) { method.append(ref code, LeftSpaceLevel.one, ""); if (null == method.methodComponent.ActionType) { ReturnResult(method, LeftSpaceLevel.one, dataOptType, funcResultVarName, resultVarName, ref code); } else { method.append(ref code, LeftSpaceLevel.one, "{0} = {1};", funcResultVarName, resultVarName); } } return(code); }