public bool TryReceive <T>(EntityPropertySetFunc <T> setFunc, out List <T> dataList) where T : new() { bool result = false; dataList = null; if (string.IsNullOrEmpty(_schema.ConnectKey) && string.IsNullOrEmpty(_schema.ConnectionString)) { dataList = new List <T>(); return(true); } try { using (IDataReader reader = GetReader <T>()) { if (reader != null) { dataList = new List <T>(); while (reader.Read()) { T entity = ReadEntityProperty(reader, setFunc); dataList.Add(entity); } result = true; } } } catch (Exception ex) { TraceLog.WriteError("Read entity property error:{0}", ex); } return(result); }
/// <summary> /// 获取日志数据 /// 从账号创建到现在的日志数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="setFunc"></param> /// <param name="dataList"></param> /// <returns></returns> public bool TryReceiveLog <T>(EntityPropertySetFunc <T> setFunc, DateTime createTime, out List <T> dataList) where T : new() { bool result = false; dataList = null; if (string.IsNullOrEmpty(_schema.ConnectKey) && string.IsNullOrEmpty(_schema.ConnectionString)) { dataList = new List <T>(); return(true); } try { int loop = 0; dataList = new List <T>(); int crease = 0; var capacity = _filter.Capacity; var now = DateTime.Now; var date = now; while (capacity > 0 & (date.Year > createTime.Year || (date.Year == createTime.Year && date.Month >= createTime.Month))) { using (IDataReader reader = GetReaderLog <T>(crease, capacity)) { if (reader != null) { var num = 0; while (reader.Read()) { T entity = ReadEntityProperty(reader, setFunc); dataList.Add(entity); num++; } capacity -= num; result = true; } } crease--; date = date.AddMonths(crease); loop++; if (loop > 1000) { break; } } } catch (Exception ex) { TraceLog.WriteError("Read entity property error:{0}", ex); } return(result); }
private T ReadEntityProperty <T>(IDataReader reader, EntityPropertySetFunc <T> setFunc) where T : new() { T entity = new T(); var columns = _schema.GetColumns(); foreach (var column in columns) { try { object fieldValue = reader[column.Name]; if (setFunc != null) { setFunc(entity, column, fieldValue); } } catch (Exception ex) { throw new Exception(string.Format("read {0} table's {1} column error.", _schema.EntityName, column.Name), ex); } } return(entity); }
/// <summary> /// 获取日志数据 /// 从账号创建到现在的日志数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="schema"></param> /// <param name="filter"></param> /// <param name="setFunc"></param> /// <param name="createTime"></param> /// <param name="dataList"></param> /// <returns></returns> public static bool TryReceiveSqlLog <T>(SchemaTable schema, DbDataFilter filter, EntityPropertySetFunc <T> setFunc, DateTime createTime, out List <T> dataList) where T : new() { return(new SqlDataReceiver(schema, filter).TryReceiveLog(setFunc, createTime, out dataList)); }