/// <summary> /// Execute the query /// </summary> /// <param name="trxContext"></param> /// <param name="vo"></param> /// <returns></returns> public override ValueObject Execute(TransactionContext trxContext, ValueObject vo) { StringBuilder sqlQuery = new StringBuilder(); sqlQuery.Append("select now() currentdatetime "); TimeVo outVo = new TimeVo(); DbCommandAdaptor sqlCommandAdapter = base.GetDbCommandAdaptor(trxContext, sqlQuery.ToString()); //create parameter DbParameterList sqlParameter = sqlCommandAdapter.CreateParameterList(); //execute SQL IDataReader dataReader = sqlCommandAdapter.ExecuteReader(trxContext, sqlParameter); while (dataReader.Read()) { DateTime currentServerDateTime = Convert.ToDateTime(dataReader["currentdatetime"]); string timeZoneString = ConfigurationDataTypeEnum.SERVER_TIME_ZONE.GetValue(); outVo.CurrentDateTime = TimeZoneInfo.ConvertTime(currentServerDateTime, TimeZoneInfo.FindSystemTimeZoneById(timeZoneString)); } dataReader.Close(); return(outVo); }
/// <summary> /// executing transaction /// </summary> /// <param name="cbm"></param> /// <param name="vo"></param> /// <returns></returns> internal static ValueObject Invoke(CbmController cbm, ValueObject vo, UserData userData, TransactionContextFactory trxFactory, string connectionString) { if (cbm == null) { MessageData messageData = new MessageData("ffce00001", Properties.Resources.ffce00001, System.Reflection.MethodBase.GetCurrentMethod().Name); logger.Error(messageData, new NullReferenceException()); throw new SystemException(messageData, new NullReferenceException()); } if (trxFactory == null) { //please write code here defaultTrxFactory.GetTransactionContext(userData); trxFactory = defaultTrxFactory; } IDbTransaction dbTransaction = null; IDbConnection connection = null; //Get TransactionContext TransactionContext trxContext = trxFactory.GetTransactionContext(userData); try { connection = new NpgsqlConnection(connectionString); trxContext.DbConnection = connection; trxContext.DbConnection.Open(); dbTransaction = trxContext.DbConnection.BeginTransaction(); //Get DB Processing Time CbmController GetDBProcessingTimeCbm = trxFactory.GetDBProcessingTimeCbm(); TimeVo time = (TimeVo)GetDBProcessingTimeCbm.Execute(trxContext, vo); trxContext.ProcessingDBDateTime = time.CurrentDateTime; //Start transaction ValueObject returnedVo = cbm.Execute(trxContext, vo); //commit dbTransaction.Commit(); return(returnedVo); } catch (ApplicationException appEx) { //rollback if (dbTransaction != null) { dbTransaction.Rollback(); } MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, appEx.Message); logger.Error(messageData, appEx); throw appEx; } catch (SystemException sysEx) { //rollback if (dbTransaction != null) { dbTransaction.Rollback(); } MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, sysEx.Message); logger.Error(messageData, sysEx); throw sysEx; } catch (Exception Ex) { //rollback if (dbTransaction != null) { dbTransaction.Rollback(); } MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, Ex.Message); logger.Error(messageData, Ex); throw new SystemException(messageData); } finally { try { if (connection != null) { connection.Close(); } } catch (Exception ex) { //need to be implemented MessageData messageData = new MessageData("ffce00003", Properties.Resources.ffce00003, ex.Message); logger.Error(messageData, ex); throw new SystemException(messageData); } } }