Exemplo n.º 1
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AUserID"></param>
        /// <param name="ALoginStatus"></param>
        /// <param name="AImmediateLogout"></param>
        /// <param name="AProcessID"></param>
        public static void AddLoginLogEntry(String AUserID,
                                            String ALoginStatus,
                                            Boolean AImmediateLogout,
                                            out Int32 AProcessID)
        {
            TDBTransaction ReadTransaction;
            TDBTransaction WriteTransaction;

            SLoginTable LoginTable;
            SLoginRow   NewLoginRow;

            OdbcParameter[] ParametersArray;
            DateTime        LoginDateTime;

            LoginTable    = new SLoginTable();
            NewLoginRow   = LoginTable.NewRowTyped(false);
            LoginDateTime = DateTime.Now;

            // Set DataRow values
            NewLoginRow.LoginProcessId = -1;
            NewLoginRow.UserId         = AUserID.ToUpper();
            NewLoginRow.LoginStatus    = ALoginStatus;
            NewLoginRow.LoginDate      = LoginDateTime.Date;
            NewLoginRow.LoginTime      = Conversions.DateTimeToInt32Time(LoginDateTime);

            if (AImmediateLogout)
            {
                NewLoginRow.LogoutDate = LoginDateTime;
                NewLoginRow.LogoutTime = Conversions.DateTimeToInt32Time(LoginDateTime);
            }

            LoginTable.Rows.Add(NewLoginRow);

            // Save DataRow
            WriteTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                // especially in the unit tests, we need to allow several logins per minute, without unique key violation
                while (SLoginAccess.Exists(NewLoginRow.UserId, NewLoginRow.LoginDate, NewLoginRow.LoginTime, WriteTransaction))
                {
                    NewLoginRow.LoginTime++;
                }

                SLoginAccess.SubmitChanges(LoginTable, WriteTransaction);

                DBAccess.GDBAccessObj.CommitTransaction();
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during the saving of the Login Log (#1):" + Environment.NewLine + Exc.ToString());

                DBAccess.GDBAccessObj.RollbackTransaction();

                throw;
            }

            // Retrieve ROWID of the SLogin record

            ParametersArray          = new OdbcParameter[4];
            ParametersArray[0]       = new OdbcParameter("", OdbcType.VarChar, 20);
            ParametersArray[0].Value = (System.Object)(AUserID);
            ParametersArray[1]       = new OdbcParameter("", OdbcType.Date);
            ParametersArray[1].Value = (System.Object)(LoginDateTime.Date);
            ParametersArray[2]       = new OdbcParameter("", OdbcType.Int);
            ParametersArray[2].Value = (System.Object)(NewLoginRow.LoginTime);
            ParametersArray[3]       = new OdbcParameter("", OdbcType.VarChar, 50);
            ParametersArray[3].Value = (System.Object)(ALoginStatus);

            ReadTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            try
            {
                // ROWID for postgresql: see http://archives.postgresql.org/sydpug/2005-05/msg00002.php
                AProcessID =
                    Convert.ToInt32(DBAccess.GDBAccessObj.ExecuteScalar("SELECT " + SLoginTable.GetLoginProcessIdDBName() + " FROM PUB_" +
                                                                        TTypedDataTable.GetTableNameSQL(SLoginTable.TableId) +
                                                                        ' ' +
                                                                        "WHERE " + SLoginTable.GetUserIdDBName() + " = ? AND " + SLoginTable.GetLoginDateDBName() + " = ? AND " +
                                                                        SLoginTable.GetLoginTimeDBName() + " = ? AND " + SLoginTable.GetLoginStatusDBName() + " = ?", ReadTransaction,
                                                                        ParametersArray));

                DBAccess.GDBAccessObj.CommitTransaction();
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during the saving of the Login Log (#2):" + Environment.NewLine + Exc.ToString());

                DBAccess.GDBAccessObj.RollbackTransaction();

                throw;
            }
        }
Exemplo n.º 2
0
        // See also constants LOGIN_STATUS_TYPE_* in Ict.Petra.Server.MSysMan.Security.TLoginLog!

        /// <summary>
        /// Adds a record to the s_login DB Table. That DB Table contains a log of all the log-ins/log-in attempts to
        /// the system, and of log-outs from the system.
        /// </summary>
        /// <param name="AUserID">UserID of the User for which a record should be written.</param>
        /// <param name="ALoginType">Type of the login/logout record. This is a hard-coded constant value
        /// (there's no 'lookup table' for it); for available values and their meaning please check program code
        /// (Ict.Petra.Server.MSysMan.Security.TLoginLog Class).</param>
        /// <param name="ALoginDetails">Details/description of the login/login attempt/logout </param>
        /// <param name="AProcessID">'Process ID'; this is a unique key and comes from a sequence (seq_login_process_id).</param>
        /// <param name="ATransaction">Instantiated DB Transaction.</param>
        public static void AddLoginLogEntry(String AUserID, String ALoginType, String ALoginDetails, out Int32 AProcessID,
                                            TDBTransaction ATransaction)
        {
            SLoginTable LoginTable  = new SLoginTable();
            SLoginRow   NewLoginRow = LoginTable.NewRowTyped(false);

            OdbcParameter[] ParametersArray;
            DateTime        LoginDateTime = DateTime.Now;

            // Set DataRow values
            NewLoginRow.LoginProcessId = -1;
            NewLoginRow.UserId         = AUserID.ToUpper();
            NewLoginRow.LoginType      = ALoginType;
            NewLoginRow.LoginDetails   = ALoginDetails;
            NewLoginRow.Date           = LoginDateTime.Date;
            NewLoginRow.Time           = Conversions.DateTimeToInt32Time(LoginDateTime);

            //TLogging.Log(String.Format("AddLoginLogEntry: NewLoginRow.Date: {0}; NewLoginRow.Time: {1}",
            //    NewLoginRow.Date, NewLoginRow.Time));

            LoginTable.Rows.Add(NewLoginRow);

            try
            {
                SLoginAccess.SubmitChanges(LoginTable, ATransaction);
            }
            catch (Exception Exc)
            {
                TLogging.Log("AddLoginLogEntry: An Exception occured during the saving of a Login Log entry (Situation #1):" +
                             Environment.NewLine + Exc.ToString());

                throw;
            }

            // Retrieve ROWID of the SLogin record
            ParametersArray          = new OdbcParameter[4];
            ParametersArray[0]       = new OdbcParameter("", OdbcType.VarChar, 20);
            ParametersArray[0].Value = (System.Object)(AUserID);
            ParametersArray[1]       = new OdbcParameter("", OdbcType.Date);
            ParametersArray[1].Value = (System.Object)(LoginDateTime.Date);
            ParametersArray[2]       = new OdbcParameter("", OdbcType.Int);
            ParametersArray[2].Value = (System.Object)(NewLoginRow.Time);
            ParametersArray[3]       = new OdbcParameter("", OdbcType.VarChar, 500);
            ParametersArray[3].Value = (System.Object)(ALoginDetails);

            try
            {
                // ROWID for postgresql: see http://archives.postgresql.org/sydpug/2005-05/msg00002.php
                AProcessID =
                    Convert.ToInt32(ATransaction.DataBaseObj.ExecuteScalar("SELECT " + SLoginTable.GetLoginProcessIdDBName() + " FROM PUB_" +
                                                                           TTypedDataTable.GetTableNameSQL(SLoginTable.TableId) +
                                                                           ' ' +
                                                                           "WHERE " + SLoginTable.GetUserIdDBName() + " = ? AND " + SLoginTable.GetDateDBName() + " = ? AND " +
                                                                           SLoginTable.GetTimeDBName() + " = ? AND " + SLoginTable.GetLoginDetailsDBName() + " = ?", ATransaction,
                                                                           ParametersArray));
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during the saving of the a Login Log entry (Situation #2):" +
                             Environment.NewLine + Exc.ToString());

                throw;
            }
        }