// 构造器 public ServerBusinessLogger(params string[] fieldsName) { // null 表示所有可读写的 field 和 property if (fieldsName == null || fieldsName.Length == 0) { List <string> fLst = new List <string>(); FieldInfo[] fs = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (FieldInfo fi in fs) { fLst.Add(fi.Name); } PropertyInfo[] ps = t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (PropertyInfo pi in ps) { if (pi.CanRead && pi.CanWrite) { fLst.Add(pi.Name); } } fieldsName = fLst.ToArray(); } // 表明和建表语句 tableName = typeof(T).FullName.Replace(".", "_"); string createTableCmd = "CREATE TABLE " + tableName + "(ID int, DT DATETIME, "; foreach (string f in fieldsName) { Type ft = GetFieldOrProperty(f); string dbTypeName = MySqlDbPersistence <ServerBusinessLogItem <T>, int> .GetDbTypeName(ft, f); createTableCmd += f + " " + dbTypeName + ", "; } createTableCmd += "Data BLOB, PRIMARY KEY(ID ASC))"; // 序列化器 List <string> fieldsWithTime = new List <string>(); fieldsWithTime.AddRange(fieldsName); fieldsWithTime.Add("DT"); p = new MySqlDbPersistence <ServerBusinessLogItem <T>, int>(dbName, dbServer, usr, pwd, tableName, createTableCmd, fieldsWithTime.ToArray(), null, null, ColValueMap); }
public DataAnalysisContainer(MySqlDbPersistence <DataAnalysis, string> persistence) : base(persistence) { }
public QuestionnaireResultContainer(MySqlDbPersistence <QuestionnaireResult, string> persistence) : base(persistence) { }
public int CreateUserTable() { var p = new MySqlDbPersistence <DataAnalysisUser, string>( DbName, "127.0.0.1", "root", "123456", @"UserCount", "CREATE TABLE UserCount(ID VARCHAR(100) BINARY, Data MediumBlob, Count INT," + "PRIMARY KEY(ID ASC));", new string[] { "Count", }, (da) => { var buff = new WriteBuffer(); da.Serialize(buff); return(buff.Data); }, (data) => { var rb = new RingBuffer(data); var da = new DataAnalysisUser(); da.Deserialize(rb); return(da); }, (DataAnalysisUser da, string col) => { switch (col) { case "Count": return(da.Info.Count); } return(null); }); var userCnt = new Dictionary <string, int>(); dac.P.LoadAll((daArr) => { foreach (var da in daArr) { var usr1 = da.Info.User1; var usr2 = da.Info.User2; if (!userCnt.ContainsKey(usr1)) { userCnt[usr1] = 1; } else { userCnt[usr1]++; } if (!userCnt.ContainsKey(usr2)) { userCnt[usr2] = 1; } else { userCnt[usr2]++; } } }); dac.P.Wait4CompoleteAll(); foreach (var usr in userCnt.Keys) { var dau = new DataAnalysisUser(); dau.ID = usr; dau.Info.Id = usr; dau.Info.Count = userCnt[usr]; p.AddNew(dau); } p.Wait4CompoleteAll(); return(userCnt.Count); }
public UserContainer(MySqlDbPersistence <User, string> persistence) : base(persistence) { }