Beispiel #1
0
        void LoadWaitTasks()
        {
            if (_taskIds == null)
            {
                DbTableDmlMgr dmlMgr = _daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                      , TaskProcessing.Constants.TaskProcessingQueue
                                                                      , TaskProcessing.Constants.TaskQueueCode
                                                                      , TaskProcessing.Constants.TaskId);
                dmlMgr.SetWhereCondition(w => w.Column(TaskProcessing.Constants.TaskQueueCode)
                                         != w.Parameter(TaskProcessing.Constants.TaskQueueCode));
                DbCommand dbCmd = _daMgr.BuildSelectDbCommand(dmlMgr, null);
                dbCmd.Parameters[_daMgr.BuildParamName(TaskProcessing.Constants.TaskQueueCode)].Value = _taskQueueCode;

                _taskIds = _daMgr.ExecuteDataSet(dbCmd, null, null).Tables[0];
                foreach (DataRow taskId in _taskIds.Rows)
                {
                    cmbWaitTasks.Items.Add(string.Format("{0}:{1}"
                                                         , taskId[TaskProcessing.Constants.TaskQueueCode]
                                                         , taskId[TaskProcessing.Constants.TaskId]));
                    if (_taskQueueItem != null &&
                        taskId[TaskProcessing.Constants.TaskQueueCode].ToString()
                        == _taskQueueItem[TaskProcessing.Constants.WaitTaskQueueCode].ToString())
                    {
                        cmbWaitTasks.SelectedIndex = cmbWaitTasks.Items.Count - 1;
                    }
                }
            }
        }
        /// <summary>
        /// Builds the DbCommand that returns the list of dependent tasks
        /// and their dependent tasks for a given WaitTaskQueueCode
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <returns>DbCommand Object with DbNull Parameter values</returns>
        static DbCommand GetDependentTasksCmd(DataAccessMgr daMgr)
        {
            StringBuilder sb = new StringBuilder();

            // we do not have any helper functions to build a recursive query; so we
            // are building this manually.
            sb.AppendFormat("WITH Dependencies ({0}, {1}, Level){2} AS{2} ({2}"
                            , TaskProcessing.Constants.TaskQueueCode
                            , TaskProcessing.Constants.WaitTaskQueueCode
                            , Environment.NewLine);
            sb.AppendFormat("SELECT tpq.{0}, {1}, 1 AS Level{2}"
                            , TaskProcessing.Constants.TaskQueueCode
                            , TaskProcessing.Constants.WaitTaskQueueCode
                            , Environment.NewLine);
            sb.AppendFormat("FROM {0}.{1} tpq{2}"
                            , DataAccess.Constants.SCHEMA_CORE
                            , TaskProcessing.Constants.TaskProcessingQueue
                            , Environment.NewLine);
            sb.AppendFormat("INNER JOIN {0}.{1} td{2}"
                            , DataAccess.Constants.SCHEMA_CORE
                            , TaskProcessing.Constants.TaskDependencies
                            , Environment.NewLine);
            sb.AppendFormat("ON tpq.{0} = td.{0}{1}UNION ALL{1}"
                            , TaskProcessing.Constants.TaskQueueCode
                            , Environment.NewLine);
            sb.AppendFormat("SELECT d.{0}, td.{1}, Level + 1{2}"
                            , TaskProcessing.Constants.TaskQueueCode
                            , TaskProcessing.Constants.WaitTaskQueueCode
                            , Environment.NewLine);
            sb.AppendFormat("FROM Dependencies d{0}"
                            , Environment.NewLine);
            sb.AppendFormat("INNER JOIN {0}.{1} td{2}"
                            , DataAccess.Constants.SCHEMA_CORE
                            , TaskProcessing.Constants.TaskDependencies
                            , Environment.NewLine);
            sb.AppendFormat("ON d.{0} = td.{1}{2})"
                            , TaskProcessing.Constants.WaitTaskQueueCode
                            , TaskProcessing.Constants.TaskQueueCode
                            , Environment.NewLine);
            sb.AppendFormat("SELECT {0}, {1}, Level{2}"
                            , TaskProcessing.Constants.TaskQueueCode
                            , TaskProcessing.Constants.WaitTaskQueueCode
                            , Environment.NewLine);
            sb.AppendFormat("FROM Dependencies d{0}"
                            , Environment.NewLine);
            sb.AppendFormat("WHERE {0} = {1}{2};"
                            , TaskProcessing.Constants.WaitTaskQueueCode
                            , daMgr.BuildBindVariableName(TaskProcessing.Constants.WaitTaskQueueCode)
                            , Environment.NewLine);

            DbCommand dbCmd = daMgr.BuildSelectDbCommand(sb.ToString(), null);

            daMgr.AddNewParameterToCollection(dbCmd.Parameters, TaskProcessing.Constants.WaitTaskQueueCode
                                              , DbType.Int32
                                              , null
                                              , 0
                                              , ParameterDirection.Input
                                              , DBNull.Value);
            return(dbCmd);
        }
        static DbCommand BuildCmdGetAllUserSessionsList(DataAccessMgr daMgr)
        {
            DbTableDmlMgr dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.UserSessions);

            return(daMgr.BuildSelectDbCommand(dmlSelectMgr, null));
        }
        /// <summary>
        /// The only constructor.
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        internal SignonControl(DataAccessMgr daMgr)
        {
            _daMgr = daMgr;
            DataTable dt = _daMgr.ExecuteDataSet(_daMgr.BuildSelectDbCommand(
                                                     "select * from " + DataAccess.Constants.SCHEMA_CORE + "." + Constants.SignonControl
                                                     , null), null, null).Tables[0];

            Refresh(dt);
        }
        /// <summary>
        /// Returns the DbCommand to get this list of registered tasks.
        /// </summary>
        /// <param name="daMgr">DataAccess manager object</param>
        /// <returns></returns>
        static DbCommand BuildCmdGetRegisteredTasksList(DataAccessMgr daMgr)
        {
            // get all the columns and all the rows
            DbTableDmlMgr dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.TaskRegistrations);

            // return the DbCommand object
            return(daMgr.BuildSelectDbCommand(dmlSelectMgr, null));
        }
        public ActionResult Users()
        {
            DataAccessMgr    daMgr    = Global.GetDataAccessMgr(this.HttpContext);
            B1SampleEntities entities = new B1SampleEntities();
            var query = from a in entities.UserMasters
                        select new { a.UserCode, a.UserId, a.FirstName };
            DbCommand dbCmd = daMgr.BuildSelectDbCommand(query, null);

            return(PartialView("_Users", daMgr.ExecuteCollection <UserMaster>(dbCmd, null)));
        }
        public ActionResult UserEditForm(int userCode)
        {
            B1SampleEntities entities = new B1SampleEntities();
            DataAccessMgr    daMgr    = Global.GetDataAccessMgr(this.HttpContext);

            var query = from a in entities.UserMasters
                        where a.UserCode == userCode
                        select new { a.UserCode, a.UserId, a.FirstName };
            DbCommand dbCmd = daMgr.BuildSelectDbCommand(query, null);

            return(PartialView(Constants._Page_UserEdit, daMgr.ExecuteCollection <UserMaster>(dbCmd, null).First()));
        }
Beispiel #8
0
        static DbCommand BuildGetUserMasterCmd(DataAccessMgr daMgr)
        {
            DbTableDmlMgr dmlMgr = new DbTableDmlMgr(daMgr, Constants.Schema_UserMaster, Constants.Table_UserMaster);

            dmlMgr.SetWhereCondition(w => ((w.Parameter(Constants.UserId) == null) ||
                                           w.Column(Constants.UserId) == w.Parameter(Constants.UserId)) &&
                                     ((w.Parameter(Constants.UserCode) == null) ||
                                      w.Column(Constants.UserCode) == w.Parameter(Constants.UserCode)));
            DbCommand dbCmd = daMgr.BuildSelectDbCommand(dmlMgr, null);

            return(dbCmd);
        }
 void LoadTaskIds()
 {
     if (_taskIds == null)
     {
         DbTableDmlMgr dmlMgr = _daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                               , TaskProcessing.Constants.TaskRegistrations, TaskProcessing.Constants.TaskId);
         _taskIds = _daMgr.ExecuteDataSet(_daMgr.BuildSelectDbCommand(dmlMgr, null), null, null).Tables[0];
         foreach (DataRow taskId in _taskIds.Rows)
         {
             cmbTaskId.Items.Add(taskId[TaskProcessing.Constants.TaskId].ToString());
         }
     }
 }
        /// <summary>
        /// Builds the DbCommand to get a list of task processing queue records
        /// sorted by taskId.
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <returns>DbCommand Object with DbNull Parameter values</returns>
        static DbCommand BuildCmdGetTPQListByTaskId(DataAccessMgr daMgr)
        {
            DbTableDmlMgr dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.TaskProcessingQueue);
            string joinTable = dmlSelectMgr.AddJoin(DataAccess.Constants.SCHEMA_CORE
                                                    , Constants.TaskStatusCodes
                                                    , DbTableJoinType.Inner
                                                    , j => j.AliasedColumn(Constants.StatusCode)
                                                    == j.JoinAliasedColumn(Constants.StatusCode)
                                                    , Constants.StatusName);

            dmlSelectMgr.AddOrderByColumnAscending(Constants.TaskId);
            return(daMgr.BuildSelectDbCommand(dmlSelectMgr, null));
        }
        static DbCommand BuildCmdGetInActiveUserSessionsList(DataAccessMgr daMgr)
        {
            DbTableDmlMgr dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.UserSessions);
            string joinTable = dmlSelectMgr.AddJoin(DataAccess.Constants.SCHEMA_CORE
                                                    , Constants.SignonControl
                                                    , DbTableJoinType.Cross, null);
            string dateAdd = daMgr.FormatDateMathSql(EnumDateDiffInterval.Second
                                                     , dmlSelectMgr.AliasedColumn(joinTable, Constants.StatusSeconds),
                                                     dmlSelectMgr.Column(Constants.SessionDateTime));

            dmlSelectMgr.SetWhereCondition(j => j.Function(dateAdd) <
                                           j.Function(daMgr.GetDbTimeAs(EnumDateTimeLocale.UTC, null)));
            return(daMgr.BuildSelectDbCommand(dmlSelectMgr, null));
        }
        /// <summary>
        /// Builds the DbCommand to get a list of a task's dependencies
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <returns>DbCommand Object with DbNull Parameter values</returns>
        static DbCommand BuildCmdGetTaskDependencies(DataAccessMgr daMgr)
        {
            DbTableDmlMgr dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.TaskDependencies);
            string jointable = dmlSelectMgr.AddJoin(DataAccess.Constants.SCHEMA_CORE
                                                    , Constants.TaskProcessingQueue
                                                    , DbTableJoinType.Inner
                                                    , j => j.AliasedColumn(Constants.WaitTaskQueueCode)
                                                    == j.JoinAliasedColumn(Constants.TaskQueueCode)
                                                    , Constants.TaskId);

            dmlSelectMgr.SetWhereCondition(w => w.Column(Constants.TaskQueueCode) == w.Parameter(Constants.TaskQueueCode));
            dmlSelectMgr.AddOrderByColumnAscending(Constants.TaskQueueCode);
            dmlSelectMgr.AddOrderByColumnAscending(DataAccess.Constants.SCHEMA_CORE, Constants.TaskProcessingQueue, Constants.TaskId);
            return(daMgr.BuildSelectDbCommand(dmlSelectMgr, null));
        }
Beispiel #13
0
        static DbCommand BuildCmdGetAccessControlRulesList(DataAccessMgr daMgr)
        {
            DbTableDmlMgr dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.AccessControlGroups);
            string joinTable = dmlSelectMgr.AddJoin(DataAccess.Constants.SCHEMA_CORE
                                                    , Constants.AccessControlGroupRules
                                                    , DbTableJoinType.Inner
                                                    , j => j.Column(Constants.AccessControlGroupCode)
                                                    == dmlSelectMgr.Column(Constants.AccessControlGroupCode)
                                                    , Constants.UIControlCode
                                                    , Constants.AccessDenied);

            dmlSelectMgr.SetWhereCondition(j => j.Column(Constants.AccessControlGroupCode) ==
                                           j.Parameter(Constants.AccessControlGroups, Constants.AccessControlGroupCode
                                                       , daMgr.BuildParamName(Constants.AccessControlGroupCode)));
            return(daMgr.BuildSelectDbCommand(dmlSelectMgr, null));
        }
Beispiel #14
0
        private static DbCommand CreateAppSettingsDbCommand(DataAccessMgr dbMgr)
        {
            DbTableDmlMgr dmlSelect = dbMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                    , DataAccess.Constants.TABLE_AppConfigSettings);

            dmlSelect.SetWhereCondition((t) =>
                                        t.Column(DataAccess.Constants.TABLE_AppConfigSettings, Constants.ConfigSetName) ==
                                        t.Parameter(DataAccess.Constants.TABLE_AppConfigSettings, Constants.ConfigSetName,
                                                    dbMgr.BuildParamName(Constants.ConfigSetName)));

            dmlSelect.OrderByColumns.Add(1,
                                         new DbQualifiedObject <DbIndexColumnStructure>(DataAccess.Constants.SCHEMA_CORE
                                                                                        , DataAccess.Constants.TABLE_AppConfigSettings,
                                                                                        dbMgr.BuildIndexColumnAscending(Constants.ConfigKey)));

            DbCommand dbCmd = dbMgr.BuildSelectDbCommand(dmlSelect, 5000);

            return(dbCmd);
        }
Beispiel #15
0
        /// <summary>
        /// Constructor for a new application session which verifies AppId.
        /// <para>To begin a new session, the Start method must be called.</para>
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="appId">Application's unique string identifier</param>
        /// <param name="appVersion">Application's version string</param>
        /// <param name="appName">Applications's name</param>
        /// <param name="heartBeatStatusHdlr">The application's delegate to call during every heartbeat to get the status</param>
        public AppSession(DataAccessMgr daMgr
                          , string appId
                          , string appVersion
                          , string appName
                          , HeartbeatStatusHandler heartBeatStatusHdlr)
        {
            _daMgr               = daMgr;
            _appId               = appId;
            _appName             = appName;
            _appVersion          = appVersion;
            _heartbeatStatusHdlr = heartBeatStatusHdlr;
            _signonControl       = new SignonControl(_daMgr);

            DbTableDmlMgr dmlSelectMgr = _daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                        , Constants.AppMaster, Constants.AppCode, Constants.AllowMultipleSessions);

            dmlSelectMgr.SetWhereCondition((j) => j.Column(Constants.AppId)
                                           == j.Parameter(dmlSelectMgr.MainTable.SchemaName
                                                          , dmlSelectMgr.MainTable.TableName
                                                          , Constants.AppId
                                                          , _daMgr.BuildParamName(Constants.AppId)));
            DbCommand cmdSelect = _daMgr.BuildSelectDbCommand(dmlSelectMgr, null);

            cmdSelect.Parameters[_daMgr.BuildParamName(Constants.AppId)].Value = appId;
            DataTable appMaster = _daMgr.ExecuteDataSet(cmdSelect, null, null).Tables[0];

            if (appMaster.Rows.Count == 0)
            {
                throw new ExceptionEvent(enumExceptionEventCodes.AppCodeNotFound
                                         , string.Format("AppId: {0}", appId));
            }

            _appCode = Convert.ToInt32(appMaster.Rows[0][Constants.AppCode]);
            _allowMultipleSessions = Convert.ToBoolean(appMaster.Rows[0][Constants.AllowMultipleSessions]);
            if (!_allowMultipleSessions)
            {
                _appSessionCode = 0;
            }
            else
            {
                _appSessionCode = _daMgr.GetNextSequenceNumber(Constants.MultipleSessionCode);
            }
        }
        /// <summary>
        /// Increases the signon failure account for the given user identifier and returns the latest count
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="userId">Unique user identifier</param>
        /// <returns>The icremented count of failed attempts</returns>
        static Int16 IncreaseFailedAttemptCount(DataAccessMgr daMgr, string userId)
        {
            DbTableDmlMgr dmlUpdate = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                    , Constants.UserMaster);

            DbFunctionStructure addOne = new DbFunctionStructure();

            addOne.FunctionBody = string.Format("{0} + 1", Constants.FailedSignonAttempts);
            dmlUpdate.AddColumn(Constants.FailedSignonAttempts
                                , addOne);

            dmlUpdate.SetWhereCondition((j) => j.Column(Constants.UserId)
                                        == j.Parameter(dmlUpdate.MainTable.SchemaName
                                                       , dmlUpdate.MainTable.TableName
                                                       , Constants.UserId
                                                       , daMgr.BuildParamName(Constants.UserId)));

            DbCommand cmdUpdate = daMgr.BuildUpdateDbCommand(dmlUpdate);

            cmdUpdate.Parameters[daMgr.BuildParamName(Constants.UserId)].Value
                = userId;

            DbTableDmlMgr dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.UserMaster
                                                                       , Constants.FailedSignonAttempts);

            dmlSelectMgr.SetWhereCondition((j) => j.Column(Constants.UserId)
                                           == j.Parameter(dmlSelectMgr.MainTable.SchemaName
                                                          , dmlSelectMgr.MainTable.TableName
                                                          , Constants.UserId
                                                          , daMgr.BuildParamName(Constants.UserId)));
            DbCommand cmdSelectUserMaster = daMgr.BuildSelectDbCommand(dmlSelectMgr, null);

            cmdSelectUserMaster.Parameters[daMgr.BuildParamName(Constants.UserId)].Value = userId;
            DbCommandMgr cmdMgr = new DbCommandMgr(daMgr);

            cmdMgr.AddDbCommand(cmdUpdate);
            cmdMgr.AddDbCommand(cmdSelectUserMaster);
            DataTable userMaster = cmdMgr.ExecuteDataTable();

            return(Convert.ToInt16(userMaster.Rows[0][Constants.FailedSignonAttempts]));
        }
        /// <summary>
        /// Implements the user signon operation
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="signonControl">SignonControl data structure</param>
        /// <param name="userId">Unique user identifier</param>
        /// <param name="userPassword">User's password (NULL for first time initialization)</param>
        /// <param name="userEnv">Meta data about user's environment</param>
        /// <param name="allowMultipleSessions">Indicates whether to allow multiple session for an account that was not setup for multiple sessions</param>
        /// <returns>SignonResult data structure</returns>
        public static SignonResultsStructure Signon(DataAccessMgr daMgr
                                                    , SignonControl signonControl
                                                    , string userId
                                                    , string userPassword
                                                    , UserEnvironmentStructure userEnv
                                                    , bool allowMultipleSessions = false)
        {
            SignonResultsStructure results = new SignonResultsStructure();

            results.ResultEnum    = SignonResultsEnum.Success;
            results.ResultMessage = null;

            DbTableDmlMgr dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.UserMaster
                                                                       , Constants.UserCode
                                                                       , Constants.UserPassword
                                                                       , Constants.PasswordSalt
                                                                       , Constants.SignonRestricted
                                                                       , Constants.LastSignonDateTime
                                                                       , Constants.FailedSignonAttempts
                                                                       , Constants.ForcePasswordChange
                                                                       , Constants.MultipleSignonAllowed
                                                                       , Constants.DefaultAccessGroupCode);

            dmlSelectMgr.SetWhereCondition((j) => j.Column(Constants.UserId)
                                           == j.Parameter(dmlSelectMgr.MainTable.SchemaName
                                                          , dmlSelectMgr.MainTable.TableName
                                                          , Constants.UserId
                                                          , daMgr.BuildParamName(Constants.UserId)));
            DbCommand cmdSelectUserMaster = daMgr.BuildSelectDbCommand(dmlSelectMgr, null);

            cmdSelectUserMaster.Parameters[daMgr.BuildParamName(Constants.UserId)].Value = userId;

            DbCommandMgr dbCmdMgr = new DbCommandMgr(daMgr);

            dbCmdMgr.AddDbCommand(cmdSelectUserMaster);
            if (!allowMultipleSessions)
            {
                dmlSelectMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                             , Constants.UserSessions
                                                             , Constants.SessionCode
                                                             , Constants.SessionDateTime
                                                             , Constants.ForceSignOff);
                dmlSelectMgr.SetWhereCondition((j) => j.Column(Constants.UserId)
                                               == j.Parameter(dmlSelectMgr.MainTable.SchemaName
                                                              , dmlSelectMgr.MainTable.TableName
                                                              , Constants.UserId
                                                              , daMgr.BuildParamName(Constants.UserId)));
                DbCommand cmdSelectSessions = daMgr.BuildSelectDbCommand(dmlSelectMgr, null);
                cmdSelectSessions.Parameters[daMgr.BuildParamName(Constants.UserId)].Value = userId;
                dbCmdMgr.AddDbCommand(cmdSelectSessions);
            }

            List <string> tableNames = new List <string>();

            tableNames.Add(Constants.UserMaster);

            if (!allowMultipleSessions)
            {
                tableNames.Add(Constants.UserSessions);
            }

            DataSet userSigonData = dbCmdMgr.ExecuteDataSet(tableNames);

            DataTable userMaster = userSigonData.Tables[Constants.UserMaster];

            // see if the userId exists and that the password is correct
            if (userMaster.Rows.Count == 0)
            {
                // userId does not exists, return an invalid credentials message
                results.ResultEnum    = SignonResultsEnum.InvaldCredentials;
                results.ResultMessage = "Incorrect UserId or Password, please try again.";
                return(results);
            }

            string storedUserPassword = userMaster.Rows[0][Constants.UserPassword].ToString();
            string passwordSalt       = userMaster.Rows[0][Constants.PasswordSalt].ToString();

            userPassword = Cryptography.HashOperation.ComputeHash(HashAlgorithmTypeEnum.SHA512HashAlgorithm, userPassword, passwordSalt);
            if (storedUserPassword != userPassword)
            {
                // invalid credentials;  do not indicate whether userId or password is incorrect
                results.ResultEnum    = SignonResultsEnum.InvaldCredentials;
                results.ResultMessage = "Incorrect UserId or Password, please try again.";
                Int16 failedAttempts = IncreaseFailedAttemptCount(daMgr, userId);
                // check for failed limit and restrict account
                if (failedAttempts >= signonControl.SignonControlData.FailedAttemptLimit)
                {
                    RestrictSignon(daMgr, userId);
                }
                return(results);
            }

            // Since the UserId and Password matched, we found the account,
            // now check for account level restrictions
            bool signonRestricted = Convert.ToBoolean(userMaster.Rows[0][Constants.SignonRestricted]);

            if (signonRestricted)
            {
                // invalid credentials;  do not indicate whether userId or password is incorrect
                results.ResultEnum    = SignonResultsEnum.SignonsRestricted;
                results.ResultMessage = "The account is restrcited from signing on.";
                return(results);
            }

            bool ForcePasswordChange = Convert.ToBoolean(userMaster.Rows[0][Constants.ForcePasswordChange]);

            if (ForcePasswordChange)
            {
                // invalid credentials;  do not indicate whether userId or password is incorrect
                results.ResultEnum    = SignonResultsEnum.PasswordChangeRequired;
                results.ResultMessage = "The account requires a password change before proceeding.";
                return(results);
            }

            if (!allowMultipleSessions)
            {
                bool      MultipleSignonAllowed = Convert.ToBoolean(userMaster.Rows[0][Constants.MultipleSignonAllowed]);
                DataTable userSessions          = userSigonData.Tables[Constants.UserSessions];
                Int16     sessionCount          = 0;
                foreach (DataRow userSession in userSessions.Rows)
                {
                    DateTime sessionDateTime = Convert.ToDateTime(userSession[Constants.SessionDateTime]);
                    TimeSpan sessionInterval = daMgr.DbSynchTime - sessionDateTime;
                    if (sessionInterval.TotalSeconds < signonControl.SignonControlData.TimeOutSeconds)
                    {
                        if (!MultipleSignonAllowed)
                        {
                            // if the user cannot have multiple signons, then we must check
                            // for existing (Active) session
                            results.ResultEnum    = SignonResultsEnum.MultipleSignonRestricted;
                            results.ResultMessage = "The account can only have a single signon session.  They must signOff the other session first.";
                            return(results);
                        }
                        ++sessionCount;
                    }
                }
            }

            // if the userId and password are correct, check signon control (general restrictions)
            if (signonControl.SignonControlData.RestrictSignon)
            {
                results.ResultEnum    = SignonResultsEnum.SignonsRestricted;
                results.ResultMessage = signonControl.SignonControlData.RestrictSignonMsg;
                return(results);
            }

            if (signonControl.SignonControlData.ForceSignoff)
            {
                results.ResultEnum    = SignonResultsEnum.ForcedSignoff;
                results.ResultMessage = signonControl.SignonControlData.SignoffWarningMsg;
                return(results);
            }

            // successful signon
            UserSignonSessionStructure uss = new UserSignonSessionStructure();

            uss.UserCode               = Convert.ToInt32(userMaster.Rows[0][Constants.UserCode]);
            uss.PasswordHash           = userMaster.Rows[0][Constants.UserPassword].ToString();
            uss.DefaultAccessGroupCode = Convert.ToInt32(userMaster.Rows[0][Constants.DefaultAccessGroupCode]);
            uss.UserId               = userId;
            uss.SignonApp.AppCode    = userEnv.AppCode;
            uss.SignonApp.AppId      = userEnv.AppId;
            uss.SignonApp.AppVersion = userEnv.AppVersion;
            uss.SessionCode          = AddSession(daMgr, userId, uss.UserCode, userEnv);
            UserSession sessionMgr = new UserSession(daMgr, uss);

            results.ResultMessage = "Welcome.";
            if (userMaster.Rows[0][Constants.LastSignonDateTime] != DBNull.Value)
            {
                DateTime signonDateTime = Convert.ToDateTime(userMaster.Rows[0][Constants.LastSignonDateTime]);
                results.ResultMessage += "  Your last signon was: ." + signonDateTime.ToString();
            }
            results.ResultEnum     = SignonResultsEnum.Success;
            results.UserSessionMgr = sessionMgr;
            return(results);
        }
Beispiel #18
0
 DataTable GetSessionControlData()
 {
     return(_daMgr.ExecuteDataSet(_daMgr.BuildSelectDbCommand("select * from B1.AppSessionControl", null), null, null).Tables[0]);
 }
Beispiel #19
0
        /// <summary>
        /// Method to begin session for the application.
        /// <para>Once started, the application session record will also be updated by the heartbeat process.</para>
        /// <para>The frequency of the heartbeat process is controlled by the SignonControl.StatusSeconds column.</para>
        /// <para>If the application is a TaskProcessingEngine, then there can be only a single active instance
        /// for a given AppId.  If there is a violation, a string message will be returned.  The caller, can recall
        /// this method with the overWrite parameter = true.  In that case the existing record will be removed.</para>
        /// </summary>
        /// <param name="configSettings">A string of configuration settings used by the application</param>
        /// <param name="statusMsg">A startup status message by the application</param>
        /// <param name="overwrite">Indicates whether or not to overwrite an existing record for the AppId</param>
        /// <param name="tpeEndpointAddress">Indentifies the WCF host endpoint address of when app is a TPE</param>
        /// <returns>Null for success; error message otherwise.</returns>
        public string Start(string configSettings, string statusMsg, bool overwrite, string tpeEndpointAddress = null)
        {
            DbTableDmlMgr dmlSelectMgr = _daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                        , Constants.AppSessions);
            DbCommand     dbCmdSelect  = _daMgr.BuildSelectDbCommand(dmlSelectMgr, null);
            DbTableDmlMgr dmlInsertMgr = _daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                        , Constants.AppSessions);

            dmlInsertMgr.AddColumn(Constants.AppId, _daMgr.BuildParamName(Constants.AppId));
            dmlInsertMgr.AddColumn(Constants.AppCode, _daMgr.BuildParamName(Constants.AppCode));
            dmlInsertMgr.AddColumn(Constants.AppVersion, _daMgr.BuildParamName(Constants.AppVersion));
            dmlInsertMgr.AddColumn(Constants.AppName, _daMgr.BuildParamName(Constants.AppName));
            dmlInsertMgr.AddColumn(Constants.MultipleSessionCode, _daMgr.BuildParamName(Constants.MultipleSessionCode));
            dmlInsertMgr.AddColumn(Constants.ProcessId, _daMgr.BuildParamName(Constants.ProcessId));
            dmlInsertMgr.AddColumn(Constants.StatusMessage, _daMgr.BuildParamName(Constants.StatusMessage));
            dmlInsertMgr.AddColumn(Constants.ConfigSettings, _daMgr.BuildParamName(Constants.ConfigSettings));
            dmlInsertMgr.AddColumn(Constants.EnvironmentSettings, _daMgr.BuildParamName(Constants.EnvironmentSettings));
            dmlInsertMgr.AddColumn(Constants.MachineName, _daMgr.BuildParamName(Constants.MachineName));
            dmlInsertMgr.AddColumn(Constants.TpeEndpointAddress, _daMgr.BuildParamName(Constants.TpeEndpointAddress));

            DbCommand     dbCmdInsert = _daMgr.BuildInsertDbCommand(dmlInsertMgr);
            DbCommandMgr  dbCmdMgr    = new DbCommandMgr(_daMgr);
            StringBuilder sb          = new StringBuilder();

            sb.AppendFormat("AllowMultipleSessions: {0} {1}", _allowMultipleSessions, Environment.NewLine);
            sb.AppendFormat("OS Version: {0} {1}", Environment.OSVersion, Environment.NewLine);
            sb.AppendFormat("ProcessName: {0} {1}", Process.GetCurrentProcess().ProcessName, Environment.NewLine);
            sb.AppendFormat("CLR Version: {0} {1}", Environment.Version, Environment.NewLine);
            sb.AppendFormat("DbProvider Version: {0} {1}", _daMgr.DbProviderVersion, Environment.NewLine);
            sb.AppendFormat("DbServer Version: {0} {1}", _daMgr.DbServerVersion, Environment.NewLine);
            sb.AppendFormat("Is x64bit OS: {0} {1}", Environment.Is64BitOperatingSystem, Environment.NewLine);
            sb.AppendFormat("Is x64bit process: {0} {1}", Environment.Is64BitProcess, Environment.NewLine);
            sb.AppendFormat("Processor Count: {0} {1}", Environment.ProcessorCount, Environment.NewLine);

            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.AppId)].Value               = _appId;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.AppCode)].Value             = _appCode;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.MachineName)].Value         = Environment.MachineName;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.ProcessId)].Value           = System.Diagnostics.Process.GetCurrentProcess().Id;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.AppVersion)].Value          = _appVersion;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.AppName)].Value             = _appName;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.MultipleSessionCode)].Value = _appSessionCode;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.ConfigSettings)].Value      = configSettings;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.EnvironmentSettings)].Value = sb.ToString();
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.StatusMessage)].Value       = statusMsg;
            dbCmdInsert.Parameters[_daMgr.BuildParamName(Constants.TpeEndpointAddress)].Value  = tpeEndpointAddress;

            if (overwrite)
            {
                dbCmdMgr.TransactionBeginBlock();
                DbCommand dbCmdDelete = GetDeleteSessionRecordCmd();
                dbCmdDelete.Parameters[_daMgr.BuildParamName(Constants.AppCode)].Value             = _appCode;
                dbCmdDelete.Parameters[_daMgr.BuildParamName(Constants.MultipleSessionCode)].Value = _appSessionCode;
                dbCmdMgr.AddDbCommand(dbCmdDelete);
                dbCmdMgr.AddDbCommand(dbCmdInsert);
                dbCmdMgr.TransactionEndBlock();
                dbCmdMgr.AddDbCommand(dbCmdSelect);
            }
            else
            {
                dbCmdMgr.AddDbCommand(dbCmdInsert);
                dbCmdMgr.AddDbCommand(dbCmdSelect);
            }
            try
            {
                _appSessions    = dbCmdMgr.ExecuteDataTable();
                _heartbeatTimer = new System.Threading.Timer(new TimerCallback(Heartbeat), null
                                                             , _signonControl.SignonControlData.StatusSeconds * 1000
                                                             , _signonControl.SignonControlData.StatusSeconds * 1000);

                if (_daMgr.loggingMgr != null)
                {
                    _daMgr.loggingMgr.WriteToLog(string.Format("AppId {0}; AppName: {1}; Version: {2}; TaskProcessingEngine: {3}; Session Started."
                                                               , _appId
                                                               , _appName
                                                               , _appVersion
                                                               , IsTaskProcessingEngine)
                                                 , EventLogEntryType.Information
                                                 , enumEventPriority.Critical);
                }
            }
            catch (ExceptionEvent e)
            {
                if (_daMgr.loggingMgr != null)
                {
                    _daMgr.loggingMgr.WriteToLog(e);
                }
                if (e.ExceptionEventCode == enumExceptionEventCodes.DbTablePrimaryKeyViolation)
                {
                    return("AppCode record already exists in AppSession table.  If you wish to cleanup record and continue,"
                           + " please resubmit.");
                }
                throw;
            }
            return(null);
        }