/// <summary> /// 获取常量表达式,自动转换值的类型 /// </summary> /// <param name="expression">表达式</param> /// <param name="value">值</param> public static ConstantExpression GetConstant(this Expression expression, object value) { var memberExpression = expression as MemberExpression; if (memberExpression == null) { return(Expression.Constant(value)); } value = ObjectConvert.ConvertObject(memberExpression.Type, value); return(Expression.Constant(value, memberExpression.Type)); }
private void GetIFChildrenMaxID(Core.Action.Models.ActionModel action) { //var parameterjobject = action.Parameter as JObject; var parameter = ObjectConvert.Get <IFActionParameterModel>(action.Parameter); //var parameter = parameterjobject.ToObject<IFActionParameterModel>(); foreach (var paction in parameter.PassActions.Concat(parameter.NoPassActions)) { GetMaxID(paction); } }
public System.Action GenerateAction(int taskID, ActionModel action) { return(() => { OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Runing); var p = ObjectConvert.Get <SetDeviceVolumeActionParamsModel>(action.Parameter); p.Volume = ActionParameterConverter.ConvertToString(taskID, p.Volume); AudioHelper.SetMasterVolume(int.Parse(p.Volume)); OnEventStateChanged?.Invoke(taskID, action.ID, ActionInvokeStateType.Done); }); }
public DoubtInfo_Query QueryDoubtInfoById(string doubtId) { using (var manager = new DoubtManager()) { var entity = manager.GetDoubtById(doubtId); var info = new DoubtInfo_Query(); ObjectConvert.ConverEntityToInfo <Doubt, DoubtInfo_Query>(entity, ref info); return(info); } }
/// <summary> /// 获取插入语法 /// </summary> /// <param name="obj"></param> /// <returns></returns> public override int InsertObject(IModel obj) { Type type = obj.GetType(); string table = TypeCache.GetTableName(type, dbContext); var typeArry = TypeCache.GetProperties(type, true).Values; Attribute.FieldAttribute primaryKey = null; string sql = string.Format("insert into [{0}](", table); string sql1 = ""; string sql2 = ""; foreach (Attribute.FieldAttribute info in typeArry) { string name = info.Name; if (info.IsPrimaryKey) { primaryKey = info; } if (info.IsPrimaryKey && !info.KeepIdentity) { continue; } if (!string.IsNullOrEmpty(info.VirtualField)) { continue; } object value = info.GetValue(obj); if (info.PropertyType.FullName.StartsWith("System.Nullable"))//Nullable<T>类型为空值不插入 { if (value == null) { continue; } } value = ObjectConvert.SetNullValue(value, info.PropertyType); sql1 += string.Format("{0},", info.KeyWordName); sql2 += string.Format("@{0},", name); helper.AddParam(name, value); } sql1 = sql1.Substring(0, sql1.Length - 1); sql2 = sql2.Substring(0, sql2.Length - 1); sql += sql1 + ") values( " + sql2 + ") ; "; if (primaryKey.KeepIdentity) { sql += "SELECT " + primaryKey.GetValue(obj) + ";"; } else { sql += "SELECT scope_identity() ;"; } sql = SqlFormat(sql); return(Convert.ToInt32(helper.ExecScalar(sql))); }
public override Dictionary <TKey, TValue> ToDictionary <TModel, TKey, TValue>(LambdaQuery <TModel> query) { var dic = SqlStopWatch.ReturnData(() => { return(GetQueryDynamicReader(query)); }, (r) => { return(ObjectConvert.DataReadToDictionary <TKey, TValue>(r.reader)); }); return(dic); }
/// <summary> /// 获取插入语法 /// </summary> /// <param name="obj"></param> /// <returns></returns> public override object InsertObject(IModel obj) { Type type = obj.GetType(); string table = TypeCache.GetTableName(type, dbContext); var typeArry = TypeCache.GetProperties(type, true).Values; string sql = string.Format("insert into {0}(", table); string sql1 = ""; string sql2 = ""; string sequenceName = string.Format("{0}_sequence", table); var sqlGetIndex = string.Format("select {0}.nextval from dual", sequenceName);//oracle不能同时执行多条语句 int id = Convert.ToInt32(SqlStopWatch.ExecScalar(helper, sqlGetIndex)); foreach (Attribute.FieldAttribute info in typeArry) { if (info.FieldType != Attribute.FieldType.数据库字段) { continue; } string name = info.MapingName; if (info.IsPrimaryKey && !info.KeepIdentity) { //continue;//手动插入ID } //if (!string.IsNullOrEmpty(info.VirtualField)) //{ // continue; //} object value = info.GetValue(obj); if (info.PropertyType.FullName.StartsWith("System.Nullable"))//Nullable<T>类型为空值不插入 { if (value == null) { continue; } } value = ObjectConvert.CheckNullValue(value, info.PropertyType); sql1 += string.Format("{0},", info.MapingName); sql2 += string.Format("@{0},", info.MapingName); helper.AddParam(info.MapingName, value); } sql1 = sql1.Substring(0, sql1.Length - 1); sql2 = sql2.Substring(0, sql2.Length - 1); sql += sql1 + ") values( " + sql2 + ")"; sql = SqlFormat(sql); var primaryKey = TypeCache.GetTable(obj.GetType()).PrimaryKey; helper.SetParam(primaryKey.MapingName, id); helper.Execute(sql); //var helper2 = helper as CoreHelper.OracleHelper; //int id = helper2.Insert(sql,sequenceName); return(id); }
public IList <AgentReturnPointInitialInfo> GetAgentReturnPointList(string agentId) { var manager = new AgentManager(); var list = manager.GetAgentReturnPointList(agentId); IList <AgentReturnPointInitialInfo> collection = new List <AgentReturnPointInitialInfo>(); ObjectConvert.ConvertEntityListToInfoList <IList <AgentReturnPointReality>, AgentReturnPointReality , IList <AgentReturnPointInitialInfo>, AgentReturnPointInitialInfo>(list, ref collection, () => new AgentReturnPointInitialInfo()); return(collection); }
public void ImportAction(Core.Action.Models.ActionModel action) { this.action = action; //构建ui action actionItem.ID = action.ID; var parameter = ObjectConvert.Get <OpenURLActionParamsModel>(action.Parameter); if (parameter != null) { var data = inputData as OpenURLActionInputModel; data.URL = parameter.URL; } }
public void ImportAction(Core.Action.Models.ActionModel action) { this.action = action; //构建ui action actionItem.ID = action.ID; var parameter = ObjectConvert.Get <DelayActionParamsModel>(action.Parameter); if (parameter != null) { var data = inputData as DelayActionInputModel; data.Seconds = parameter.Seconds.ToString(); } }
public void AddSiteActivity(SiteActivityInfo info) { if (info == null) { throw new Exception("当前广告信息无效!"); } using (var manager = new SiteActivityManager()) { SiteActivity entity = new SiteActivity(); ObjectConvert.ConverInfoToEntity(info, ref entity); manager.AddSiteActivity(entity); } }
public void ImportAction(Core.Action.Models.ActionModel action) { this.action = action; //构建ui action actionItem.ID = action.ID; var parameter = ObjectConvert.Get <JsonDeserializeActionParamsModel>(action.Parameter); if (parameter != null) { var data = inputData as JsonDeserializeActionInputModel; data.Content = parameter.Content; } }
public void ImportAction(Core.Action.Models.ActionModel action) { this.action = action; //构建ui action actionItem.ID = action.ID; var parameter = ObjectConvert.Get <GetIPAddressActionParamsModel>(action.Parameter); if (parameter != null) { var data = inputData as GetIPAddressActionInputModel; data.Type = GetIPAddressActionData.GetIPAddressType((int)parameter.Type); } }
public void ImportAction(Core.Action.Models.ActionModel action) { this.action = action; //构建ui action actionItem.ID = action.ID; var parameter = ObjectConvert.Get <SetDeviceVolumeActionParamsModel>(action.Parameter); if (parameter != null) { var data = inputData as SetDeviceVolumeActionInputModel; data.Volume = parameter.Volume; } }
public void ImportAction(Core.Action.Models.ActionModel action) { this.action = action; //构建ui action actionItem.ID = action.ID; var parameter = ObjectConvert.Get <ReadFileActionParamsModel>(action.Parameter); if (parameter != null) { var data = inputData as ReadFileActionInputModel; data.FilePath = parameter.FilePath; } }
/// <summary> /// 使用完整的LamadaQuery查询 /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="query"></param> /// <param name="cacheKey">cacheKey</param> /// <returns></returns> public override List <TModel> QueryOrFromCache <TModel>(LambdaQuery <TModel> query, out string cacheKey) { cacheKey = ""; CheckTableCreated <TModel>(); List <TModel> list = new List <TModel>(); if (query.SkipPage > 0)//按分页 { list = QueryResult <TModel>(query); if (SettingConfig.AutoTrackingModel && query.__TrackingModel) { SetOriginClone(list); } return(list); } cacheKey = ""; System.Data.Common.DbDataReader reader; query.FillParames(this); var sql = query.GetQuery(); var cacheTime = query.__ExpireMinute; var compileSp = query.__CompileSp; double runTime = 0; if (cacheTime <= 0) { if (!compileSp) { reader = dbHelper.ExecDataReader(sql); } else//生成储过程 { string sp = CompileSqlToSp(_DBAdapter.TemplateSp, sql); reader = dbHelper.RunDataReader(sp); } query.ExecuteTime += dbHelper.ExecuteTime; var queryInfo = new LambdaQuery.Mapping.QueryInfo <TModel>(false, query.GetQueryFieldString(), query.GetFieldMapping()); list = ObjectConvert.DataReaderToSpecifiedList <TModel>(reader, queryInfo); query.MapingTime += runTime; } else { list = MemoryDataCache.CacheService.GetCacheList <TModel>(sql, query.GetFieldMapping(), cacheTime, dbHelper, out cacheKey).Values.ToList(); } ClearParame(); query.RowCount = list.Count; if (SettingConfig.AutoTrackingModel && query.__TrackingModel) { SetOriginClone(list); } return(list); }
/// <summary> /// 使用完整的LamadaQuery查询 /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="query"></param> /// <param name="cacheKey">cacheKey</param> /// <returns></returns> public override List <TModel> QueryList <TModel>(LambdaQuery <TModel> query, out string cacheKey) { cacheKey = ""; CheckTableCreated <TModel>(); if (query.SkipPage > 0)//按分页 { return(Page <TModel, TModel>(query)); } string sql = ""; cacheKey = ""; query.FillParames(this); sql = query.GetQuery(); sql = _DBAdapter.SqlFormat(sql); System.Data.Common.DbDataReader reader; var cacheTime = query.__ExpireMinute; var compileSp = query.__CompileSp; List <TModel> list = new List <TModel>(); double runTime = 0; if (cacheTime <= 0) { if (!compileSp) { if (query.TakeNum > 0) { dbHelper.AutoFormatWithNolock = false; } reader = dbHelper.ExecDataReader(sql); } else//生成储过程 { string sp = CompileSqlToSp(_DBAdapter.TemplateSp, sql); reader = dbHelper.RunDataReader(sp); } query.ExecuteTime += dbHelper.ExecuteTime; list = ObjectConvert.DataReaderToIModelList <TModel>(reader, out runTime, true); query.MapingTime += runTime; } else { list = MemoryDataCache.CacheService.GetCacheList <TModel>(sql, cacheTime, dbHelper, out cacheKey).Values.ToList(); } ClearParame(); query.RowCount = list.Count; if (SettingConfig.AutoTrackingModel && query.__TrackingModel) { SetOriginClone(list); } return(list); }
public GameWinNumber_Info QueryWinNumber(string issuseNumber) { var manager = new GDKLSF_GameWinNumberManager(); var entity = manager.QueryWinNumber(issuseNumber); if (entity == null) { return(new GameWinNumber_Info()); } var info = new GameWinNumber_Info(); ObjectConvert.ConverEntityToInfo <GDKLSF_GameWinNumber, GameWinNumber_Info>(entity, ref info); return(info); }
public void ImportAction(Core.Action.Models.ActionModel action) { this.action = action; //构建ui action actionItem.ID = action.ID; var parameter = ObjectConvert.Get <StartProcessActionParamsModel>(action.Parameter); if (parameter != null) { var data = inputData as StartProcessActionInputModel; data.Path = parameter.Path; data.Args = parameter.Args; } }
public void AddBannerInfo(SiteMessageBannerInfo info) { if (info == null) { throw new Exception("当前广告信息无效!"); } using (var manager = new BulletinManager()) { SiteMessageBanner entity = new SiteMessageBanner(); ObjectConvert.ConverInfoToEntity(info, ref entity); entity.CreateTime = DateTime.Now; manager.AddBannerInfo(entity); } }
/// <summary> /// 批量插入 /// </summary> /// <param name="details"></param> /// <param name="keepIdentity"></param> public override void BatchInsert(System.Collections.IList details, bool keepIdentity = false) { if (details.Count == 0) { return; } var type = details[0].GetType(); string table = TypeCache.GetTableName(type, dbContext); table = KeyWordFormat(table); string sql = GetSelectTop("*", " from " + table + " where 1=0", "", 1); DataTable tempTable = helper.ExecDataTable(sql); var typeArry = TypeCache.GetProperties(type, true).Values; foreach (var item in details) { DataRow dr = tempTable.NewRow(); foreach (Attribute.FieldAttribute info in typeArry) { if (info.FieldType != Attribute.FieldType.数据库字段) { continue; } string name = info.MapingName; object value = info.GetValue(item); if (!keepIdentity) { if (info.IsPrimaryKey) { continue; } } if (!string.IsNullOrEmpty(info.VirtualField)) { continue; } var value2 = ObjectConvert.CheckNullValue(value, info.PropertyType); if (info.PropertyType.FullName.StartsWith("System.Nullable"))//Nullable<T>类型为空值不插入 { if (value2 == null) { continue; } } dr[name] = value2; } tempTable.Rows.Add(dr); } helper.InsertFromDataTable(tempTable, table, keepIdentity); }
public ActivityPrizeConfigInfo GetActivityPrizeConfig(int activityId) { using (var manage = new UserIntegralManager()) { ActivityPrizeConfig entity = manage.GetActivityPrizeConfig(activityId); if (entity != null) { ActivityPrizeConfigInfo info = new ActivityPrizeConfigInfo(); ObjectConvert.ConverEntityToInfo(entity, ref info); return(info); } return(null); } }
public static List <TResult> DataReaderToDynamic <T, TResult>(System.Data.Common.DbDataReader reader, Expression <Func <T, TResult> > resultSelector, ParameCollection fieldMapping) where T : IModel, new() { List <TResult> list = new List <TResult>(); var typeArry = TypeCache.GetProperties(typeof(T), true).Values; while (reader.Read()) { var detailItem = ObjectConvert.DataReaderToObj(reader, typeof(T), typeArry, fieldMapping) as T; var result = resultSelector.Compile()(detailItem); list.Add(result); } reader.Close(); return(list); }
/// <summary> /// 查询新用户返点 /// </summary> /// <param name="agentId"></param> /// <returns></returns> public IList <AgentReturnPointInfo> GetAgentReturnPointListByAgentId(string agentId) { var manager = new AgentManager(); var list = manager.GetAgentReturnPointListByUserId(agentId); IList <AgentReturnPointInfo> collection = new List <AgentReturnPointInfo>(); ObjectConvert.ConvertEntityListToInfoList <IList <AgentReturnPoint>, AgentReturnPoint , IList <AgentReturnPointInfo>, AgentReturnPointInfo>(list, ref collection, () => new AgentReturnPointInfo()); return(collection); // return list; }
public UserSiteServiceInfo QueryUserSiteServiceByUserId(string userId) { using (var manager = new UserBalanceManager()) { UserSiteServiceInfo info = new UserSiteServiceInfo(); var entity = manager.QueryUserSiteServiceByUserId(userId, ServiceType.DrawingNotice); if (entity == null) { return(null); } ObjectConvert.ConverEntityToInfo(entity, ref info); return(info); } }
public bool IsCheck() { var p = ObjectConvert.Get <WriteFileActionParameterModel>(parameter); if (p == null) { return(false); } else if (p.FilePath == string.Empty) { return(false); } return(true); }
public SiteMessageBannerInfo GetBannerManagerInfo(string bannerId) { using (var manager = new BulletinManager()) { var entity = manager.GetBannerManagerInfo(bannerId); if (entity == null) { throw new Exception("未查询到广告数据!"); } SiteMessageBannerInfo info = new SiteMessageBannerInfo(); ObjectConvert.ConverEntityToInfo(entity, ref info); return(info); } }
public UserSiteServiceInfo QueryUserSiteServiceById(int Id) { using (var manager = new UserBalanceManager()) { UserSiteServiceInfo info = new UserSiteServiceInfo(); var entity = manager.QueryUserSiteServiceById(Id); if (entity == null) { return(new UserSiteServiceInfo()); } ObjectConvert.ConverEntityToInfo(entity, ref info); return(info); } }
public void ImportAction(Core.Action.Models.ActionModel action) { this.action = action; //构建ui action actionItem.ID = action.ID; var parameter = ObjectConvert.Get <KillProcessActionParamsModel>(action.Parameter); if (parameter != null) { var data = inputData as KillProcessActionInputModel; data.ProcessName = parameter.ProcessName; data.IsFuzzy = parameter.IsFuzzy; } }
static List <object> QueryData(string key, Type type, string query, IEnumerable <Attribute.FieldMapping> mapping, DBHelper helper) { if (cacheDatas.Count > 1000) { EventLog.Log("数据缓存超过了1000个,请检查程序调用是否正确", true); } DateTime time = DateTime.Now; System.Data.Common.DbDataReader reader; string sql; //语句 if (query.IndexOf("select ") > -1) { sql = query; reader = helper.ExecDataReader(sql); }//存储过程 else if (query.IndexOf("exec ") > -1) { string sp = query.Replace("exec ", ""); reader = helper.RunDataReader(sp); }//表名 else { sql = "select * from " + query; reader = helper.ExecDataReader(sql); } double runTime; var list = ObjectConvert.DataReaderToObjectList(reader, type, mapping, out runTime); //var queryInfo = new LambdaQuery.Mapping.QueryInfo<object>(false, mapping); //var list = ObjectConvert.DataReaderToIModelList2<object>(reader, queryInfo); string par = ""; foreach (KeyValuePair <string, object> item in helper.Params) { par += item.Key + ":" + item.Value; } //list.ForEach(b => // { // var item = b as IModel; // item.AddCacheListen(); // }); var ts = DateTime.Now - time; //WriteLog("更新查询 " + tableName + " 参数 " + par); EventLog.Log("更新查询 " + key + " 用时:" + ts.TotalSeconds + "秒", "DataCache"); return(list); }