private int InvokeAction(ISQLAction action, string status, Dictionary <string, object> o, List <WhereClause> where) { int result = -1; switch (status.ToLower()) { case "insert": result = action.Insert(o); break; case "insertorupdate": result = action.InsertOrUpdate(o); break; case "update": result = action.Update(o, where); break; case "delete": result = action.Delete(o, where); break; default: result = action.InsertOrUpdate(o); break; } return(result); }
/// <summary> /// 查询topn条数据 /// </summary> /// <param name="topN"></param> /// <param name="entityType"></param> /// <param name="where"></param> /// <param name="orderby"></param> /// <returns></returns> protected DataTable GetTopNData(int topN, List <WhereClause> where, OrderByClause orderby) { IDBHelper helper = DBFactory.CreateDBHelper(); ISQLAction action = Factory.CreateAction(_tableconfig.Tag, _tableconfig, helper); var entity = Activator.CreateInstance <Dictionary <string, object> >(); return(action.SelectTopN(topN, entity, where, orderby)); }
public override void DeleteSendData(Dictionary <string, object> data) { ISQLAction action = Factory.CreateAction(_tableconfig.Tag, _tableconfig, _helper); lock (locker) { action.Delete(data, null); } }
public bool HandleMessage(string tags, string tableName, string body, bool enableLog) { try { var config = Factory.SyncDataConfig.Find(p => p.OrginalTableName.ToLower().Equals(tableName.ToLower())); if (config == null) { throw new Exception(string.Format("表名:{0}没有配置", tableName)); } if (config.Ignore) { return(true); } if (string.IsNullOrEmpty(tags) || tags.Trim().Equals("null")) { tags = ""; } var data = JsonHelper.Deserialize <Dictionary <string, object> >(body); ISQLAction action = Factory.CreateAction(tags, config, _helper); string status = ""; if (data.ContainsKey("__Status") && data["__Status"] != null) { status = data["__Status"].ToString(); } var effectCount = InvokeAction(action, status, data, null); if (enableLog) { _logger.Debug(string.Format("同步了一条数据到数据库。table name:{0}-----json:{1}", tableName, body)); } } catch (Exception ex) { _logger.Error(string.Format("table name:{0}-----json:{1}", tableName, body)); _logger.WriteException(ex); return(false); } return(true); }