Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        public DateTime GetCurrentTime(IDbConnection connection, IDbTransaction trans)
        {
            StringBuilder sql = new StringBuilder();

            if (GetDatabaseType() == DATABASE_TYPE.POSTGRESQL)
            {
                sql.Append(" SELECT NOW()::TIMESTAMP WITHOUT TIME ZONE AS TIME_NOW ");
            }
            else if (GetDatabaseType() == DATABASE_TYPE.MYSQL)
            {
                sql.Append(" SELECT NOW() AS TIME_NOW ");
            }
            else
            {
                return(DateTime.Now);
            }

            DataRow row = GetDatabaseDAO().DoGetDataRow(connection, trans, sql.ToString());

            DateTime dt = new DateTime();

            if (row != null)
            {
                if (row["TIME_NOW"] != System.DBNull.Value)
                {
                    DateTime.TryParse(row["TIME_NOW"].ToString(), out dt);
                }
                else
                {
                    SanitaLogEx.e("X100", "GetCurrentTime.row.TIME = null");
                }
            }
            else
            {
                SanitaLogEx.e("X100", "GetCurrentTime.row = null");
            }

#if false
            //Update local time
            if (dt.Year > 2001)
            {
                UtilityDate.SetLocalTime(dt);
            }
#endif

            return(dt);
        }
Esempio n. 3
0
        private void bwAsync_Worker(object sender, DoWorkEventArgs e)
        {
            SanitaLogEx.e(TAG, "Start get timer...");

            try
            {
                using (IDbConnection connection = SoftUpdatePresenter.GetConnection())
                {
                    //Open connection
                    connection.Open();

                    //Get time
                    DateTime dt = SoftUpdatePresenter.GetCurrentTime(null, null);

                    //Close connection
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                SanitaLog.e(TAG, ex);
            }
        }