private void bwAsync_DoWork(object sender, DoWorkEventArgs e) { Stopwatch mStopWatch = new Stopwatch(); mStopWatch.Start(); SanitaLogEx.d(TAG, "Start database cache..."); PostMessage("Start database cache ..."); IsCacheCompleted = false; try { //Update timer SystemInfo.NOW = SoftUpdatePresenter.GetCurrentTime(null, null); //Kiểm tra và nâng cấp cấu trúc database Splasher.Status = "Check and update database..."; SoftUpdatePresenter.DoUpdateDatabaseSQL(); using (IDbConnection connection = SoftUpdatePresenter.GetConnection()) { //Open connection connection.Open(); //Begin transtation using (IDbTransaction trans = connection.BeginTransaction()) { Splasher.Status = "Đang xử lý : Danh sách danh mục...".Translate(); DM_Intent_Type.InitDefaultList(DM_Intent_TypePresenter.GetDM_Intent_Types(connection, trans)); MyVar.mListDM_Intent_Type = DM_Intent_Type.GetDefaultList(0).OrderBy(p => p.DM_Intent_TypeID).ToList(); DM_Entity_Type.InitDefaultList(DM_Entity_TypePresenter.GetDM_Entity_Types(connection, trans)); MyVar.mListDM_Entity_Type = DM_Entity_Type.GetDefaultList(0).OrderBy(p => p.DM_Entity_TypeID).ToList(); MyVar.mListUser = UserPresenter.GetUsers(connection, trans); MyVar.mListHome = HomePresenter.GetHomes(connection, trans); MyVar.mListRoom = RoomPresenter.GetRooms(connection, trans); MyVar.mListDevice = DevicePresenter.GetDevices(connection, trans); //----------------------------------------------------------------------------- //Commit transtation trans.Commit(); //Close connection connection.Close(); } } SanitaLogEx.d(TAG, "End database cache..."); } catch (Exception ex) { SanitaLogEx.e(TAG, "bwAsync_DoWork error !", ex); } IsCacheCompleted = true; }
private void bwAsync_DoWork(object sender, DoWorkEventArgs e) { Stopwatch mStopWatch = new Stopwatch(); mStopWatch.Start(); SanitaLogEx.d(TAG, "Start database cache..."); PostMessage("Start database cache ..."); IsCacheCompleted = false; try { //Update timer SystemInfo.NOW = SoftUpdatePresenter.GetCurrentTime(null, null); //Kiểm tra và nâng cấp cấu trúc database Splasher.Status = "Check and update database..."; SoftUpdatePresenter.DoUpdateDatabaseSQL(); using (IDbConnection connection = SoftUpdatePresenter.GetConnection()) { //Open connection connection.Open(); //Begin transtation using (IDbTransaction trans = connection.BeginTransaction()) { MyVar.mListLoaiPhong = LoaiPhongPresenter.GetLoaiPhongs(); //----------------------------------------------------------------------------- //Commit transtation trans.Commit(); //Close connection connection.Close(); } } SanitaLogEx.d(TAG, "End database cache..."); } catch (Exception ex) { SanitaLogEx.e(TAG, "bwAsync_DoWork error !", ex); } IsCacheCompleted = true; }
public override bool SynchDatabase(IDbConnection connection, IDbTransaction trans, ExBackgroundWorker worker, int number_hosobenhan, bool IsCapNhatTrigger) { synch_worker = worker; //Get database name String DatabaseName = myBaseDao.GetDatabaseName(); String file_name = "Database\\" + DatabaseName + ".db"; SanitaLogEx.d(TAG, "[SynchDatabase] Database = [" + DatabaseName + "]"); //If have no database -> create datbase if (!File.Exists("Database\\" + DatabaseName + ".db")) { SanitaLog.e(TAG, "[SynchDatabase] Database chưa tồn tại"); CreateDatabase(DatabaseName); } //Get all base table IList <ClassTable> listTable = GetListTable(connection, trans, DatabaseName); //Synch database if (synch_worker != null) { synch_worker.ReportProgress(0, listFixTable.Count); } for (int i = 0; i < listFixTable.Count; i++) { if (synch_worker != null) { synch_worker.ReportProgress(i + 1, "Nâng cấp table '" + listFixTable[i].Table + "..."); } //Convert mysql to sqlite for (int j = 0; j < listFixTable[i].listColumn.Count; j++) { listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("int(10) unsigned NOT NULL auto_increment", "INTEGER"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("int(10) unsigned", "INTEGER"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("int(10)", "INTEGER"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("int(11)", "INTEGER"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("text CHARACTER SET utf8 COLLATE utf8_unicode_ci", "text"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("longblob", "BLOB"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("double", "REAL"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("Datetime DEFAULT '1-1-1'", "TEXT"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("datetime DEFAULT '1-1-1'", "TEXT"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("Datetime", "TEXT"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("datetime", "TEXT"); listFixTable[i].listColumn[j].ColumnDefine = listFixTable[i].listColumn[j].ColumnDefine.Replace("timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP", "TEXT"); } //Tim xem co table ton tai chua var foundTable = listTable.FirstOrDefault(p => p.Table.Equals(listFixTable[i].Table, StringComparison.CurrentCultureIgnoreCase)); if (foundTable == null) { //Create table SanitaLogEx.d(TAG, "[SynchDatabase] Create table '" + listFixTable[i].Table + "'"); if (CreateTable(connection, trans, DatabaseName, listFixTable[i]) <= -100) { SanitaLogEx.e(TAG, "[SynchDatabase] Create table lỗi"); if (synch_worker != null) { synch_worker.ReportProgress(-1, "Tạo table '" + listFixTable[i].Table + "' lỗi !"); } return(false); } } else { //Alter table SanitaLogEx.e(TAG, "[SynchDatabase] Alter table '" + listFixTable[i].Table + "'"); if (AlterTableTable(connection, trans, DatabaseName, listFixTable[i], foundTable) <= -100) { SanitaLogEx.e(TAG, "[SynchDatabase] Alter table lỗi"); if (synch_worker != null) { synch_worker.ReportProgress(-1, "Update table '" + listFixTable[i].Table + "' lỗi !"); } return(false); } } if (synch_worker != null) { synch_worker.ReportProgress(i + 1, "Nâng cấp table '" + listFixTable[i].Table + "' OK !"); } } return(true); }