static void init() { if (string.IsNullOrEmpty(rootPath)) { return; } matchRules = MatchRules(); TempImpl tempImpl = new TempImpl(); tempImpl.SetRootPath(rootPath); tempImpl.IsShowCodeOfDataResourceDLL = dbInfo.IsShowCode; DataAdapter.SetConfig(dbInfo.ConnectionString, dbInfo.DatabaseType); assemblies = DJTools.GetAssemblyCollection(rootPath); AutoCall.AssemblyCollection = assemblies; AutoCall.SetDataProviderAssemble(dbInfo.SqlProviderRelativePathOfDll); AutoCall.RootPath = rootPath; AutoCall.GetDllAbsolutePathByRelativePath = GetDllAbsolutePathByRelativePath; DbList <Data.Common.DbParameter> .dataServerProvider = dataServerProvider; if (null != DbHelper) { DbHelper.connectString = dbInfo.ConnectionString; DbHelper.optByBatchMaxNumber = dbInfo.optByBatchMaxNumber; DbHelper.optByBatchWaitSecond = dbInfo.optByBatchWaitSecond; DbHelper.sqlMaxLengthForBatch = dbInfo.sqlMaxLengthForBatch; DbHelper.disposableAndClose = dbInfo.close; } }
static void addDataToCollection(IDbHelper dbHelper, AutoCall autoCall, Action <object> action, Func <DbCommand, object> func, string sql_1, string tableName_1, List <DbParameter> para_1) { lock (_addDataToCollection) { IExecuteSql executeSql = null; execSqlDic.TryGetValue(tableName_1, out executeSql); if (null == executeSql) { executeSql = ExecuteSql.Instance; executeSql.Key = tableName_1; executeSql.connectString = dbHelper.connectString; Type type = dbHelper.dataServerProvider.GetType(); executeSql.dataServerProvider = (IDataServerProvider)Activator.CreateInstance(type); executeSql.disposableAndClose = dbHelper.disposableAndClose; executeSql.dbConnectionState = dbHelper.dbConnectionState; execSqlDic.Add(tableName_1, executeSql); } TempData td = TempData.Instance; td.dbHelper = dbHelper; td.autoCall = autoCall; td.sql = sql_1; td.parameters = para_1; td.resultOfOpt = action; td.dataOpt = func; executeSql.Add(td); } }
public IProductPathFlow Visit(AutoCall autocall) { List <Coupon> underlyingsCouponsByPayDate = autocall.Underlying.Decomposition() .OrderBy(cpn => cpn.PaymentInfo.Date) .ToList(); CouponPathFlow[] underlyingPathFlows = BuildCouponPathFlow(underlyingsCouponsByPayDate.ToArray()); int[] underlyingCallIndexes = autocall.CallDates.Map(callDate => { var idx = underlyingsCouponsByPayDate.FindIndex(cpn => cpn.PaymentInfo.Date > callDate); if (idx == -1) { return(underlyingsCouponsByPayDate.Count); } return(idx); }); var triggerPathEvals = autocall.CallDates.Map(callDate => { var trigger = autocall.CallTrigger(callDate); return(FixingFuncPathValue(trigger)); }); var redemptionPathFlows = autocall.CallDates.Map(callDate => { var redemptionCpn = autocall.Redemption(callDate); return(BuildCouponPathFlow(redemptionCpn).Single()); }); return(new AutocallPathFlow(underlyingPathFlows, redemptionPathFlows, triggerPathEvals, underlyingCallIndexes)); }
string GetInterfaceName(Type interfaceType, AutoCall autoCall) { string resetKeyName = DJTools.GetClassName(interfaceType, true); //string fn1 = autoCall.MatchRuleOrClassName; //fn1 = null == fn1 ? "" : fn1; //fn1 = fn1.Trim(); //fn1 = string.IsNullOrEmpty(fn1) ? "" : ("+" + fn1); //resetKeyName += fn1; return(resetKeyName); }
public void Exec(AutoCall autoCall, string sql, List <DbParameter> parameters, ref string err, Action <object> action, Func <DbCommand, object> func) { lock (_execObj) { if (DbConnct(ref err)) { DbCommand cmd = dataServerProvider.CreateDbCommand(sql, conn); if (null != parameters) { foreach (var item in parameters) { cmd.Parameters.Add(item); } } object vObj = null; try { vObj = func(cmd); } catch (Exception ex) { conn.Close(); conn.Dispose(); conn = null; err = ex.ToString(); err += "\r\n\r\n" + sql; if (null != autoCall) { autoCall.ExecuteExcption(this.GetType(), this, "Exec", null, new Exception(err)); } //throw; } finally { cmd.Dispose(); if (null != conn) { if (disposableAndClose) { conn.Close(); } conn.Dispose(); } action(vObj); } } } }
int ICalculate.Division(int a, int b, AutoCall autoCall) { int c = 0; try { c = a / b; } catch (Exception ex) { autoCall.e(ex.ToString(), System.DJ.ImplementFactory.Commons.ErrorLevels.dangerous); } return(c); }
Type LoadImplementTypeByInterface(Type interfaceType, AutoCall autoCall) { Assembly objAss = interfaceType.Assembly; Type[] types = objAss.GetTypes(); string fn1 = ""; Regex rg1 = null; bool isIgnoreCase = false; AutoCallMatch(autoCall, ref fn1, ref rg1, ref isIgnoreCase); Type impl_type = GetImplTypeByTypes(types, interfaceType, autoCall, rg1, fn1, isIgnoreCase); return(impl_type); }
static void bufferDatas(IDbHelper dbHelper, AutoCall autoCall, DataOptType dataOptType, string sql, List <DbParameter> parameters, Action <object> action, Func <DbCommand, object> func) { lock (_bufferData) { if (DataOptType.insert == dataOptType) { if (null == insertBatch) { insertBatch = new InsertBatch(); setAsbBatchProperty(insertBatch, dbHelper); } insertBatch.analysis(dbHelper, autoCall, sql, parameters, (sql_1, tableName_1, para_1) => { addDataToCollection(dbHelper, autoCall, action, func, sql_1, tableName_1, para_1); }); } else if (DataOptType.update == dataOptType) { if (null == updateBatch) { updateBatch = new UpdateBatch(); setAsbBatchProperty(updateBatch, dbHelper); } updateBatch.analysis(dbHelper, autoCall, sql, parameters, (sql_1, tableName_1, para_1) => { addDataToCollection(dbHelper, autoCall, action, func, sql_1, tableName_1, para_1); }); } else if (DataOptType.delete == dataOptType) { if (null == deleteBatch) { deleteBatch = new DeleteBatch(); setAsbBatchProperty(deleteBatch, dbHelper); } deleteBatch.analysis(dbHelper, autoCall, sql, parameters, (sql_1, tableName_1, para_1) => { addDataToCollection(dbHelper, autoCall, action, func, sql_1, tableName_1, para_1); }); } } }
/// <summary> /// /// </summary> /// <param name="dbHelper"></param> /// <param name="autoCall"></param> /// <param name="sql"></param> /// <param name="dbParameters"></param> /// <param name="action">参数:sql, tableName, DbParameterCollection</param> public void analysis(IDbHelper dbHelper, AutoCall autoCall, string sql, List <DbParameter> dbParameters, Action <string, string, List <DbParameter> > action) { if (null == this.dbHelper) { this.dbHelper = dbHelper; } if (null == this.autoCall) { this.autoCall = autoCall; } if (null == dbParameters) { dbParameters = new List <DbParameter>(); } string tbName = Step01_GetTableName(sql); if (Step02_InvalidBatch(sql)) { action(sql, tbName, dbParameters); return; } DataEle de = null; deDic.TryGetValue(tbName, out de); if (null == de) { de = new DataEle() { absBatch = this, dbHelper = dbHelper, dbTag = dbTag, maxNum = maxNum, action = action, sql_length = sqlMaxLengthForBatch, Key = tbName }; deDic.Add(tbName, de); } de.Add(sql, dbParameters); }
void AutoCallMatch(AutoCall autoCall, ref string implName, ref Regex regex, ref bool isIgnoreCase1) { string fn1 = autoCall.MatchRuleOrClassName; fn1 = string.IsNullOrEmpty(fn1) ? implName : fn1; fn1 = null == fn1 ? "" : fn1; fn1 = fn1.Trim(); bool isIgnoreCase = isIgnoreCase1; if (IgnoreLU.none != autoCall.IgnoreCase) { isIgnoreCase = IgnoreLU.is_true == autoCall.IgnoreCase ? true : isIgnoreCase; isIgnoreCase = IgnoreLU.is_false == autoCall.IgnoreCase ? false : isIgnoreCase; } Regex rg = new Regex(@"[^0-9a-z_\s]", RegexOptions.IgnoreCase); Regex rg1 = null; if (rg.IsMatch(fn1)) { if (isIgnoreCase) { rg1 = new Regex(fn1, RegexOptions.IgnoreCase); } else { rg1 = new Regex(fn1); } } else { fn1 = isIgnoreCase ? fn1.ToLower() : fn1; } if (string.IsNullOrEmpty(fn1)) { return; } implName = fn1; regex = rg1; isIgnoreCase1 = isIgnoreCase; }
void GetSqlByProvider(MethodInformation method, DbList <DbParameter> dbParameters, ref string sql) { string dataProviderNamespace = method.dataProviderNamespace; string dataProviderClassName = method.dataProviderClassName; if (string.IsNullOrEmpty(dataProviderNamespace) || string.IsNullOrEmpty(dataProviderClassName)) { return; } AutoCall autoCall = (AutoCall)method.AutoCall; ISqlExpressionProvider sqlExpressionProvider = autoCall.GetDataProvider(dataProviderNamespace, dataProviderClassName, autoCall); if (null == sqlExpressionProvider) { return; } autoCall.GetSqlByDataProvider(sqlExpressionProvider, method.paraList, dbParameters, autoCall, method.dataOptType, ref sql); }
Type GetImplTypeByTypes(Type[] types, Type interfaceType, AutoCall autoCall, Regex rg1, string implName, bool isIgnoreCase) { Type impl_type = null; foreach (Type t in types) { if (false == t.IsImplementInterface(interfaceType)) { continue; } if (!MatchImpl(rg1, t, implName, isIgnoreCase)) { continue; } impl_type = t; break; } return(impl_type); }
void Adapter() { if (string.IsNullOrEmpty(rootPath)) { return; } object[] arr = null; string resetKeyName = ""; Type interfaceType = null; Type implType = null; CKeyValue kv = null; MatchRule mr = null; object impl = null; object implNew = null; object impl_1 = null; bool isShowCode = false; bool isSingleCall = false; bool isSingleInstance = false; bool isUnSingleInstance = false; InstanceObj instanceObj = null; string unSingleInstanceStr = typeof(IUnSingleInstance).FullName; TempImpl temp = new TempImpl(); temp.codeCompiler = codeCompiler; bool enableCompiler = false; if (null != codeCompiler && null != dataServerProvider && null != DbHelper) { enableCompiler = true; } Action <object, Action> action = (obj, action1) => { if (null != obj) { if (null != (obj as IUnSingleInstance)) { isUnSingleInstance = true; isSingleCall = false; isSingleInstance = false; } if ((null != (obj as ISingleInstance) || isSingleCall) && false == isUnSingleInstance) { isSingleCall = true; isSingleInstance = true; action1?.Invoke(); } } }; Regex rg = null; string implName = ""; bool isIgnoreCase = false; AutoCall autoCall = null; FieldInfo[] fArr = null; // currentObj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); List <Type> objList = new List <Type>(); Type _objType = currentObj.GetType(); int n = 0; while (20 > n && typeof(object) != _objType && typeof(ImplementAdapter) != _objType) { objList.Add(_objType); _objType = _objType.BaseType; n++; } if (0 == objList.Count && null != currentObj) { objList.Add(currentObj.GetType()); } foreach (Type typeItem in objList) { fArr = typeItem.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); foreach (FieldInfo p in fArr) { arr = p.GetCustomAttributes(typeof(AutoCall), true); if (0 == arr.Length) { continue; } autoCall = null; foreach (var item in arr) { if (null != (item as AutoCall)) { autoCall = (AutoCall)item; break; } } interfaceType = p.FieldType; if (!autoCall.LoadBeforeFilter(interfaceType)) { continue; } autoCall.errorLevels1 = errorLevels1; impl = null; impl_1 = null; implType = null; resetKeyName = null; isSingleInstance = false; isUnSingleInstance = false; instanceObj = null; arr = p.GetCustomAttributes(typeof(SingleCall), true); isSingleCall = 0 < arr.Length; resetKeyName = GetInterfaceName(interfaceType, autoCall); interfaceImplements.TryGetValue(resetKeyName, out instanceObj); if (null != instanceObj) { impl = instanceObj.newInstance; } if (null != instanceObj) { implName = ""; rg = null; isIgnoreCase = false; AutoCallMatch(autoCall, ref implName, ref rg, ref isIgnoreCase); if (null != rg) { if (!MatchImpl(rg, instanceObj.oldInstanceType, implName, isIgnoreCase)) { impl = null; } } } impl_1 = impl; action(impl, () => { impl = null; }); if (null == impl) { kv = GetKvByInterfaceType(interfaceType); mr = null == kv ? null : ((MatchRule)kv.Value); isShowCode = false; if (interfaceType.IsInterface) { if (null != mr) { isShowCode = mr.IsShowCode; implType = LoadImplementTypeByMatchRule(mr, interfaceType, autoCall); } else { implType = LoadImplementTypeByInterface(interfaceType, autoCall); } if (null == implType) { implType = LoadImplementTypeByAssemblies(interfaceType, autoCall); } if (enableCompiler && null == (autoCall as ExistCall)) { implNew = temp.NewImplement(interfaceType, implType, autoCall, isShowCode); if (null != implNew) { impl = implNew; } } if (null != implType && null == impl) { try { impl = Activator.CreateInstance(implType); } catch (Exception ex) { string err = "[" + implType.FullName + "] 实例可能缺少一个无参构造函数(或该类访问权限不够)\r\n" + ex.ToString(); autoCall.ExecuteExcption(interfaceType, null, null, null, new Exception(err)); //throw; } } } else { if (enableCompiler) { implType = interfaceType; interfaceType = typeof(IEmplyInterface); implNew = temp.NewImplement(interfaceType, implType, autoCall, isShowCode); if (null != implNew) { impl = implNew; } } if (null == impl && null != implType) { try { impl = Activator.CreateInstance(implType); } catch (Exception ex) { string err = "[" + implType.FullName + "] 实例可能缺少一个无参构造函数(或该类访问权限不够)\r\n" + ex.ToString(); autoCall.ExecuteExcption(interfaceType, null, null, null, new Exception(err)); //throw; } } } if (false == isUnSingleInstance) { action(impl, null); } if (null != impl && null == impl_1 && false == isSingleCall) { lock (_adapterOfImplement) { interfaceImplements.TryGetValue(resetKeyName, out instanceObj); if (null == instanceObj) { interfaceImplements.Add(resetKeyName, new InstanceObj() { newInstance = impl, oldInstanceType = implType }); } else { impl = instanceObj.newInstance; } } } } if (null == impl) { continue; } isSingleInstance = false; if (null != (impl as ISingleInstance)) { isSingleInstance = true; } if (isSingleInstance) { if (null == ((ISingleInstance)impl).Instance) { ((ISingleInstance)impl).Instance = impl; } } if (!autoCall.LoadAfterFilter(impl)) { continue; } p.SetValue(currentObj, impl); } } }
Type LoadImplementTypeByMatchRule(MatchRule mr, Type interfaceType, AutoCall autoCall) { Type impl_type = null; Assembly objAss = null; string err = ""; string DllRelativePathOfImpl = mr.DllRelativePathOfImpl; if (!string.IsNullOrEmpty(DllRelativePathOfImpl)) { string dllFile = GetDllAbsolutePathByRelativePath(DllRelativePathOfImpl); if (!File.Exists(dllFile)) { return(null); } try { objAss = Assembly.LoadFrom(dllFile); } catch (Exception ex) { err = "加载程序集[" + dllFile + "]出错\r\n" + ex.ToString(); autoCall.ExecuteExcption(interfaceType, null, null, null, new Exception(err)); } } else { objAss = interfaceType.Assembly; //Assembly.GetExecutingAssembly(); //当前应用程序集 } if (null == objAss) { err = "加载程序集失败"; autoCall.ExecuteExcption(interfaceType, null, null, null, new Exception(err)); return(impl_type); } Regex rg1 = null; string mie = mr.MatchImplExpression; bool isIgnoreCase = mr.IgnoreCase; AutoCallMatch(autoCall, ref mie, ref rg1, ref isIgnoreCase); if ((!string.IsNullOrEmpty(mr.ImplementNameSpace)) && null == rg1) { string s = mr.ImplementNameSpace + "." + mie; Type type = null; try { type = objAss.GetType(s); } catch { } if (null == type) { return(impl_type); } if (type.IsImplementInterface(interfaceType)) { impl_type = type; } return(impl_type); } string fn1 = isIgnoreCase ? mie.ToLower() : mie; Type[] types = null; try { types = objAss.GetTypes(); } catch { } impl_type = GetImplTypeByTypes(types, interfaceType, autoCall, rg1, fn1, isIgnoreCase); return(impl_type); }
public object NewImplement(Type interfaceType, Type implementType, AutoCall autoCall_Impl, bool isShowCode) { object impl = null; string dir = Path.Combine(rootPath, dirName); if (!Directory.Exists(dir)) { return(impl); } DynamicCodeTempImpl dynamicCode = new DynamicCodeTempImpl(dirName); string classPath = ""; string code = dynamicCode.GetCodeByImpl(interfaceType, implementType, autoCall_Impl, ref classPath); if (!string.IsNullOrEmpty(code)) { string fn = "a" + Guid.NewGuid().ToString().Replace("-", "_"); string fn1 = fn + ".dll"; string dllFilePath = Path.Combine(dir, fn1); string err = ""; if (null == codeCompiler) { err = "请提供代码编译器"; autoCall_Impl.ExecuteExcption(interfaceType, null, null, null, new Exception(err)); return(null); } Assembly assObj = codeCompiler.TranslateCode(dllArr, "v4.0", code, dllFilePath, ref err); if (string.IsNullOrEmpty(err)) { try { Type type = assObj.GetType(classPath); impl = Activator.CreateInstance(type); instanceCount++; } catch (Exception ex) { err = "加载程序集时出错:\r\n" + ex.ToString(); } } else { autoCall_Impl.ExecuteExcption(interfaceType, null, null, null, new Exception(err)); } isShowCode = dynamicCode.IsDataInterface ? IsShowCodeOfDataResourceDLL : isShowCode; if (isShowCode) { if (!string.IsNullOrEmpty(err)) { dllFilePath = "\r\n/******************\r\n" + err; dllFilePath += "\r\n********/"; code += dllFilePath; } string fn2 = fn + ".cs"; string f2 = Path.Combine(dir, fn2); try { File.WriteAllText(f2, code); } catch { } } else { if (!string.IsNullOrEmpty(err)) { autoCall_Impl.e(err); } } } autoCall_Impl.CreateInstanceByInterface(interfaceType, impl, autoCall_Impl, instanceCount); return(impl); }
DataTable IDbHelper.query(object autoCall, string sql, List <DbParameter> parameters, bool EnabledBuffer, Action <DataTable> resultAction, ref string err) { DataTable dt = new DataTable(); string msg = ""; AutoCall autoCall_1 = autoCall as AutoCall; Action action = () => { basicExecForSQL.Exec(autoCall_1, sql, parameters, ref msg, result => { }, cmd => { IDataServerProvider dataServerProvider = ((IDbHelper)this).dataServerProvider; Data.Common.DataAdapter da = dataServerProvider.CreateDataAdapter(cmd); DataSet ds = new DataSet(); try { da.Fill(ds); if (0 < ds.Tables.Count) { dt = ds.Tables[0]; } } catch (Exception ex) { msg = ex.ToString(); //throw; } if (null != resultAction) { if (EnabledBuffer) { if (null != m_SyncContext) { m_SyncContext.Post(PostDataTable, new object[] { resultAction, dt }); } else { resultAction(dt); } } else { resultAction(dt); } } if (!string.IsNullOrEmpty(msg)) { throw new Exception(msg); } return(dt); }); }; if (EnabledBuffer) { Task task = new Task(() => { Thread.Sleep(50); action(); }); task.Start(); } else { action(); } err = msg; return(dt); }
int IDbHelper.update(object autoCall, string sql, List <DbParameter> parameters, bool EnabledBuffer, Action <int> resultAction, ref string err) { int num = 1; string msg = ""; AutoCall autoCall_1 = autoCall as AutoCall; if (EnabledBuffer) { bufferDatas(this, autoCall_1, DataOptType.update, sql, parameters, result => { }, cmd => { try { num = cmd.ExecuteNonQuery(); } catch (Exception ex) { num = 0; msg = ex.ToString(); //throw; } if (null != resultAction) { if (null != m_SyncContext) { m_SyncContext.Post(PostInt, new object[] { resultAction, num }); } else { resultAction(num); } } if (!string.IsNullOrEmpty(msg)) { throw new Exception(msg); } return(num); }); } else { num = 0; basicExecForSQL.Exec(autoCall_1, sql, parameters, ref err, result => { }, cmd => { try { num = cmd.ExecuteNonQuery(); } catch (Exception ex) { msg = ex.ToString(); //throw; } if (null != resultAction) { resultAction(num); } if (!string.IsNullOrEmpty(msg)) { throw new Exception(msg); } return(num); }); } return(num); }
Type LoadImplementTypeByAssemblies(Type interfaceType, AutoCall autoCall) { if (null == assemblies) { return(null); } if (0 == assemblies.Count) { return(null); } Type impl_type = null; string implName = ""; Regex regex = null; bool isIgnoreCase1 = false; AutoCallMatch(autoCall, ref implName, ref regex, ref isIgnoreCase1); InstanceObj impl1 = null; Type type1 = null; foreach (KeyValuePair <string, InstanceObj> item in interfaceImplements) { impl1 = item.Value; if (null == impl1) { continue; } type1 = impl1.newInstance.GetType(); if (false == type1.IsImplementInterface(interfaceType)) { continue; } if (!MatchImpl(regex, type1, implName, isIgnoreCase1)) { continue; } impl_type = impl1.newInstance.GetType(); break; } if (null != impl_type) { return(impl_type); } Type[] types = null; foreach (Assembly item in assemblies) { try { types = item.GetTypes(); impl_type = GetImplTypeByTypes(types, interfaceType, autoCall, regex, implName, isIgnoreCase1); } catch { } if (null != impl_type) { break; } } return(impl_type); }
public T Exec <T>(MethodInformation method, DataOptType dataOptType, Action <T> action, string sql) { T result = default(T); AutoCall autoCall = (AutoCall)method.AutoCall; dynamicWhere(method, ref sql); IList <DataEntity <DataElement> > dataElements = null; DataEntity <DataElement> dataElements1 = null; DbList <DbParameter> dbParameters = null; if (0 < method.paraList.Count) { foreach (Para item in method.paraList) { if (null != item.ParaValue) { if (null != item.ParaValue as IList <DataEntity <DataElement> > ) { dataElements = item.ParaValue as IList <DataEntity <DataElement> >; break; } else if (null != item.ParaValue as DataEntity <DataElement> ) { dataElements = new List <DataEntity <DataElement> >(); dataElements1 = item.ParaValue as DataEntity <DataElement>; dataElements.Add(dataElements1); break; } } } } if (null == dataElements) { dataElements = new List <DataEntity <DataElement> >(); } string err = ""; bool EnabledBuffer = method.methodComponent.EnabledBuffer; EnabledBuffer = method.methodComponent.IsAsync ? true : EnabledBuffer; if (DataOptType.select == dataOptType || DataOptType.count == dataOptType || DataOptType.procedure == dataOptType) { if (0 < dataElements.Count) { dataElements1 = dataElements[0]; } dbParameters = GetDbParameters(method, dataElements1, sql); GetSqlByProvider(method, dbParameters, ref sql); dbHelper.query(autoCall, sql, dbParameters, EnabledBuffer, (dt) => { DynamicCodeAutoCall dynamicCodeAutoCall = new DynamicCodeAutoCall(); string execClassPath = ""; string execMethodName = ""; bool paraExsit = false; Type returnType = dynamicCodeAutoCall.GetParaTypeOfResultExecMethod(method, ref execClassPath, ref execMethodName, ref paraExsit); if (paraExsit) { Type resultExecMethodType = execClassPath.GetClassTypeByPath(); if (null == resultExecMethodType) { err = "The ClassPath '" + execClassPath + "' is not exist."; autoCall.e(err, ErrorLevels.dangerous); throw new Exception(err); } object clsObj = null; MethodInfo methodInfo = resultExecMethodType.GetMethod(execMethodName); if (null != methodInfo) { if (methodInfo.ReturnType != typeof(T)) { err = ""; string msg = "The return value type of the method '{0}' of the class '{1}' and the method '{2}' of the interface '{3}' are not the same."; method.append(ref err, 0, msg, execMethodName, execClassPath, method.methodInfo.Name, method.methodInfo.DeclaringType.FullName); autoCall.e(err, ErrorLevels.dangerous); throw new Exception(err); } object vData = dataTableTo(method, dt, returnType); try { clsObj = Activator.CreateInstance(resultExecMethodType); result = (T)methodInfo.Invoke(clsObj, new object[] { vData }); } catch (Exception ex) { autoCall.e(ex.ToString(), ErrorLevels.dangerous); //throw; } } } else { result = dataTableTo <T>(method, dt); } if (null != action) { action(result); } }, ref err); } else { int n = 0; Func <int, T> funcResult = n1 => { object v = n1; if (typeof(bool) == typeof(T)) { v = 0 < n1; } return((T)v); }; foreach (DataEntity <DataElement> item in dataElements) { dbParameters = GetDbParameters(method, item, sql); switch (dataOptType) { case DataOptType.insert: dbHelper.insert(autoCall, sql, dbParameters, EnabledBuffer, (num) => { n += num; result = funcResult(n); if (null != action) { action(result); } }, ref err); break; case DataOptType.update: dbHelper.update(autoCall, sql, dbParameters, EnabledBuffer, (num) => { n += num; result = funcResult(n); if (null != action) { action(result); } }, ref err); break; case DataOptType.delete: dbHelper.delete(autoCall, sql, dbParameters, EnabledBuffer, (num) => { n += num; result = funcResult(n); if (null != action) { action(result); } }, ref err); break; } } result = funcResult(n); } return(result); }