#pragma warning restore 1591 // restore the xmlComments warning

        /// <summary>
        /// Returns the entire data table of application session records in the
        /// database based on the given enumeration.
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="tpqList">Enumeration indicating what type of session records to return</param>
        /// <returns>DataTable of Task Processing Queue records</returns>
        public static DataTable TaskProcessingQueueList(DataAccessMgr daMgr, ListEnum tpqList)
        {
            DbCommand dbCmd;

            switch (tpqList)
            {
            case ListEnum.Queued:
                dbCmd = daMgr.DbCmdCacheGetOrAdd("BuildCmdGetTPQListByWaitDateTime"
                                                 , BuildCmdGetTPQListByWaitDateTime);
                dbCmd.Parameters[daMgr.BuildParamName(Constants.StatusCode)].Value = Convert.ToByte(tpqList);
                break;

            case ListEnum.Failed:
            case ListEnum.Succeeded:
            case ListEnum.InProcess:
            case ListEnum.NotQueued:
                dbCmd = daMgr.DbCmdCacheGetOrAdd("BuildCmdGetTPQListByStatusDateTime"
                                                 , BuildCmdGetTPQListByStatusDateTime);
                dbCmd.Parameters[daMgr.BuildParamName(Constants.StatusCode)].Value = Convert.ToByte(tpqList);
                break;

            default:
                dbCmd = daMgr.DbCmdCacheGetOrAdd("BuildCmdGetTPQListByTaskId", BuildCmdGetTPQListByTaskId);
                break;
            }

            return(daMgr.ExecuteDataSet(dbCmd, null, null).Tables[0]);
        }
        /// <summary>
        /// Builds the DbCommand to delete the task dependency(s) for the given taskQueueCode.
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="taskQueueItem">Datarow containing the parameter values</param>
        /// <param name="deleteAll">Indicates whether or not to delete all dependencies.</param>
        /// <returns>DbCommand Object with DbNull Parameter values</returns>
        public static DbCommand GetDeleteQueueItemCmd(DataAccessMgr daMgr, DataRow taskQueueItem, bool deleteAll)
        {
            if (taskQueueItem == null ||
                !taskQueueItem.Table.Columns.Contains(TaskProcessing.Constants.TaskQueueCode))
            {
                throw new ExceptionEvent(enumExceptionEventCodes.NullOrEmptyParameter
                                         , "DataRow (taskQueueItem) containing TaskDependency data was empty");
            }

            DbTableDmlMgr dmlMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                 , TaskProcessing.Constants.TaskDependencies);

            dmlMgr.SetWhereCondition(w => w.Column(TaskProcessing.Constants.TaskQueueCode)
                                     == w.Parameter(TaskProcessing.Constants.TaskQueueCode));
            if (!deleteAll)
            {
                System.Linq.Expressions.Expression waitTaskExp =
                    DbPredicate.CreatePredicatePart(w => w.Column(TaskProcessing.Constants.WaitTaskQueueCode)
                                                    == w.Parameter(TaskProcessing.Constants.WaitTaskQueueCode));
                dmlMgr.AddToWhereCondition(System.Linq.Expressions.ExpressionType.AndAlso, waitTaskExp);
            }
            DbCommand dbCmd = daMgr.BuildDeleteDbCommand(dmlMgr);

            dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.TaskQueueCode)].Value
                = Convert.ToInt32(taskQueueItem[TaskProcessing.Constants.TaskQueueCode]);
            if (!deleteAll)
            {
                dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.WaitTaskQueueCode)].Value
                    = Convert.ToInt32(taskQueueItem[TaskProcessing.Constants.WaitTaskQueueCode]);
            }
            return(dbCmd);
        }
        public ActionResult EditProfile(EditProfileModel editProfile)
        {
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(editProfile.ChangedFields))
                {
                    DataAccessMgr daMgr = Global.GetDataAccessMgr(this.HttpContext);

                    DbTableDmlMgr dmlUpdate = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                            , DataManagement.Constants.Table_UserMaster);
                    foreach (string column in dmlUpdate.MainTable.Columns.Keys)
                    {
                        if (editProfile.ChangedFields.Contains(column))
                        {
                            dmlUpdate.AddColumn(column);
                        }
                    }

                    dmlUpdate.AddColumn(SessionManagement.Constants.LastModifiedUserCode);
                    dmlUpdate.AddColumn(SessionManagement.Constants.LastModifiedDateTime
                                        , Core.EnumDateTimeLocale.Default);

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

                    DbCommand   cmdUpdate      = daMgr.BuildUpdateDbCommand(dmlUpdate);
                    UserSession userSessionMgr = (UserSession)Session[SessionManagement.Constants.UserSessionMgr];
                    cmdUpdate.Parameters[daMgr.BuildParamName(DataManagement.Constants.UserId)].Value = userSessionMgr.UserId;
                    cmdUpdate.Parameters[daMgr.BuildParamName(SessionManagement.Constants.LastModifiedUserCode)].Value = userSessionMgr.UserCode;

                    foreach (DbParameter param in cmdUpdate.Parameters)
                    {
                        if (param.Value == DBNull.Value)
                        {
                            param.Value = GetValueFromModelState(ModelState, param.ParameterName.Substring(1));
                        }
                    }
                    daMgr.ExecuteNonQuery(cmdUpdate, null, null);
                }
                else
                {
                    ViewBag.NoDataChanged = true;
                }
            }
            return(View(editProfile));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes the session record for the given session code.
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="sessionCode">Unique session code</param>
        public static void Signoff(DataAccessMgr daMgr, Int64 sessionCode)
        {
            DbTableDmlMgr dmlDeleteMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.UserSessions);

            dmlDeleteMgr.SetWhereCondition((j) => j.Column(Constants.SessionCode)
                                           == j.Parameter(dmlDeleteMgr.MainTable.SchemaName
                                                          , dmlDeleteMgr.MainTable.TableName
                                                          , Constants.SessionCode
                                                          , daMgr.BuildParamName(Constants.SessionCode)));
            DbCommand cmdDeleteUserSession = daMgr.BuildDeleteDbCommand(dmlDeleteMgr);

            cmdDeleteUserSession.Parameters[daMgr.BuildParamName(Constants.SessionCode)].Value = sessionCode;
            daMgr.ExecuteNonQuery(cmdDeleteUserSession, null, null);
        }
Ejemplo n.º 5
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;
                    }
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Loads the access control rules for the given user's access control group
 /// </summary>
 /// <returns>Access control rules for the given user's access control group</returns>
 AccessControlGroupStructure LoadAccessControl()
 {
     if (!_accessControlCache.Exists(_userSignon.DefaultAccessGroupCode.ToString()))
     {
         AccessControlGroupStructure accessControlGroup = new AccessControlGroupStructure();
         accessControlGroup.AccessGroupCode = _userSignon.DefaultAccessGroupCode;
         CacheMgr <bool> accessControlRules = new CacheMgr <bool>();
         DbCommand       dbCmd = _daMgr.DbCmdCacheGetOrAdd(Constants.AccessControlGroupRules,
                                                           BuildCmdGetAccessControlRulesList);
         dbCmd.Parameters[_daMgr.BuildParamName(Constants.AccessControlGroupCode)].Value
             = _userSignon.DefaultAccessGroupCode;
         DataTable accessRules = _daMgr.ExecuteDataSet(dbCmd, null, null).Tables[0];
         foreach (DataRow accessRule in accessRules.Rows)
         {
             accessControlGroup.DefaultAccessDenied = Convert.ToBoolean(
                 accessRule[Constants.DefaultAccessDenied]);
             accessControlGroup.AccessGroupName = accessRule[Constants.AccessControlGroupName].ToString();
             if (accessRule[Constants.UIControlCode] != DBNull.Value)
             {
                 Int32 uiControlCode = Convert.ToInt32(accessRule[Constants.UIControlCode]);
                 bool  accessDenied  = Convert.ToBoolean(accessRule[Constants.AccessDenied]);
                 accessControlRules.Set(uiControlCode.ToString(), accessDenied);
             }
             accessControlGroup.AccessControlRules = accessControlRules;
         }
         _accessControlCache.Set(_userSignon.DefaultAccessGroupCode.ToString(), accessControlGroup);
     }
     return(_accessControlCache.Get(_userSignon.DefaultAccessGroupCode.ToString()));
 }
Ejemplo n.º 7
0
        private Dictionary <string, IEnumerable <string> > GetAppConfigSettings(string sysConfigSetName, string appConfigSetName)
        {
            // Get the AppSettings DbCommand from the cache - create one if NOT exist in the cache
            DbCommand dbCmd = _daMgr.DbCmdCacheGetOrAdd(Configuration.Constants.AppSettingCacheName, CreateAppSettingsDbCommand);

            // Get the system config set name
            Dictionary <string, IEnumerable <string> > sys =
                _daMgr.ExecuteReader(dbCmd, null, rdr => CreateAppConfigSettingDictionary(rdr, sysConfigSetName),
                                     _daMgr.BuildParamName(Configuration.Constants.ConfigSetName), sysConfigSetName);

            // Get the application config set name
            Dictionary <string, IEnumerable <string> > app =
                _daMgr.ExecuteReader(dbCmd, null, rdr => CreateAppConfigSettingDictionary(rdr, null),
                                     _daMgr.BuildParamName(Configuration.Constants.ConfigSetName), appConfigSetName);

            return(sys.Union(app).ToDictionary(kv => kv.Key, kv => kv.Value));
        }
        /// <summary>
        /// Builds the DbCommand to get a list of the given task's dependency records
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="taskQueueCode">Unique identifier of the task whose dependencies will be returned</param>
        /// <returns>DateTable of the given task's dependencies</returns>
        public static DataTable TaskDependenciesList(DataAccessMgr daMgr, Int32 taskQueueCode)
        {
            DbCommand dbCmd = daMgr.DbCmdCacheGetOrAdd("BuildCmdGetTaskDependencies"
                                                       , BuildCmdGetTaskDependencies);

            dbCmd.Parameters[daMgr.BuildParamName(Constants.TaskQueueCode)].Value = taskQueueCode;
            return(daMgr.ExecuteDataSet(dbCmd, null, null).Tables[0]);
        }
        /// <summary>
        /// Constructor accepting the assembly and a usercode performing the registration
        /// </summary>
        /// <param name="daMgr">DataAccess manager object</param>
        /// <param name="assemblyName">Fully qualified assembly name</param>
        /// <param name="assemblyFileName">Fully qualified assembly path and filename</param>
        /// <param name="userCode">Usercode of user performing registration</param>
        /// <returns></returns>
        public static Int32 RegisterAssemblyTasks(DataAccessMgr daMgr
                                                  , string assemblyName
                                                  , string assemblyFileName
                                                  , Int32?userCode)
        {
            // Load the assemlb
            Assembly      asm    = Assembly.LoadFrom(assemblyFileName);
            DbCommandMgr  cmdMgr = new DbCommandMgr(daMgr);
            DbTableDmlMgr dmlMgr = new DbTableDmlMgr(daMgr, DataAccess.Constants.SCHEMA_CORE, Constants.TaskRegistrations);

            dmlMgr.AddColumn(Constants.TaskId, daMgr.BuildParamName(Constants.TaskId), DbTableColumnType.ForInsertOnly);
            dmlMgr.AddColumn(Constants.AssemblyName, daMgr.BuildParamName(Constants.AssemblyName));
            dmlMgr.AddColumn(Constants.TaskDescription, daMgr.BuildParamName(Constants.TaskDescription));
            dmlMgr.AddColumn(Constants.LastRegisteredDate, EnumDateTimeLocale.Default);
            // if usercode was provided add it to last mod key
            if (userCode.HasValue)
            {
                dmlMgr.AddColumn(Constants.LastModifiedUserCode, daMgr.BuildParamName(Constants.LastModifiedUserCode));
                dmlMgr.AddColumn(Constants.LastModifiedDateTime, EnumDateTimeLocale.Default);
            }
            dmlMgr.SetWhereCondition((j) =>
                                     j.Column(Constants.TaskId) ==
                                     j.Parameter(Constants.TaskRegistrations
                                                 , Constants.TaskId
                                                 , daMgr.BuildParamName(Constants.TaskId)));
            // build a merge statement
            DbCommand dbCmd = daMgr.BuildMergeDbCommand(dmlMgr);

            int typesFound = 0;

            // set the values for the dbCommand
            foreach (Type t in ObjectFactory.SearchTypes <TaskProcess>(asm))
            {
                // we must create the task object in or to have access to the TaskDesve
                TaskProcess tp = ObjectFactory.Create <TaskProcess>(assemblyFileName, t.FullName, null, null, null, null, null, null);
                dbCmd.Parameters[daMgr.BuildParamName(Constants.TaskId)].Value          = t.FullName;
                dbCmd.Parameters[daMgr.BuildParamName(Constants.AssemblyName)].Value    = assemblyName;
                dbCmd.Parameters[daMgr.BuildParamName(Constants.TaskDescription)].Value = tp.TaskDescription();
                if (userCode.HasValue)
                {
                    dbCmd.Parameters[daMgr.BuildParamName(Constants.LastModifiedUserCode)].Value = userCode.Value;
                }
                cmdMgr.AddDbCommand(dbCmd);
                ++typesFound;
            }
            // register the task (update it if exists otherwise insert)
            cmdMgr.ExecuteNonQuery();
            return(typesFound);
        }
Ejemplo n.º 10
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>
        /// Returns the set of dependency relationships where the given task is the dependent task
        /// </summary>
        /// <param name="daMgr">DbAccessMgr object instance</param>
        /// <param name="waitTaskQueueCode">The taskQueueCode that other tasks may be dependent on</param>
        /// <returns>The DataTable of dependency relationhips</returns>
        public static DataTable GetDependentTasks(DataAccessMgr daMgr
                                                  , Int32 waitTaskQueueCode)
        {
            DbCommand dbCmd = daMgr.DbCmdCacheGetOrAdd("GetDependentTasksCmd", GetDependentTasksCmd);

            dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.WaitTaskQueueCode)].Value
                = waitTaskQueueCode;

            return(daMgr.ExecuteDataSet(dbCmd, null, null).Tables[0]);
        }
Ejemplo n.º 12
0
        /// <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]));
        }
Ejemplo n.º 13
0
        static DbCommand BuildCmdGetUpdateUserSession(DataAccessMgr daMgr)
        {
            DbTableDmlMgr dmlUpdateMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                       , Constants.UserSessions);

            dmlUpdateMgr.AddColumn(Constants.SessionDateTime, EnumDateTimeLocale.UTC);
            dmlUpdateMgr.SetWhereCondition(j => j.Column(Constants.SessionCode) ==
                                           j.Parameter(Constants.UserSessions, Constants.SessionCode
                                                       , daMgr.BuildParamName(Constants.SessionCode)));
            return(daMgr.BuildUpdateDbCommand(dmlUpdateMgr));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets or resets an account restriction for the given user identifier
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="userId">Unique user identifier</param>
        /// <param name="removeRestriction">Indicates whether to set or reset the restriction</param>
        static void Restriction(DataAccessMgr daMgr, string userId, bool removeRestriction)
        {
            DbTableDmlMgr dmlUpdate = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                    , Constants.UserMaster);

            dmlUpdate.AddColumn(Constants.SignonRestricted
                                , daMgr.BuildParamName(Constants.SignonRestricted));

            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;
            cmdUpdate.Parameters[daMgr.BuildParamName(Constants.SignonRestricted)].Value
                = removeRestriction ? 0 : 1;
            daMgr.ExecuteNonQuery(cmdUpdate, null, null);
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
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);
        }
        /// <summary>
        /// Builds the DbCommand to delete a task queue record for the given taskQueueItem from the
        /// TaskProcessingQueue table.
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="taskQueueItem">Unique Identifier of the TaskProcessingQueue record to delete</param>
        /// <returns>DbCommand Object with given Parameter values</returns>
        public static DbCommand GetDeleteQueueItemCmd(DataAccessMgr daMgr, DataRow taskQueueItem)
        {
            if (taskQueueItem == null ||
                !taskQueueItem.Table.Columns.Contains(TaskProcessing.Constants.TaskQueueCode))
            {
                throw new ExceptionEvent(enumExceptionEventCodes.NullOrEmptyParameter
                                         , "DataRow (taskQueueItem) containing TaskProcessingQueue data was empty");
            }

            DbTableDmlMgr dmlMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                 , TaskProcessing.Constants.TaskProcessingQueue);

            dmlMgr.SetWhereCondition(w => w.Column(TaskProcessing.Constants.TaskQueueCode)
                                     == w.Parameter(TaskProcessing.Constants.TaskQueueCode));
            DbCommand dbCmd = daMgr.BuildDeleteDbCommand(dmlMgr);

            dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.TaskQueueCode)].Value
                = Convert.ToInt32(taskQueueItem[TaskProcessing.Constants.TaskQueueCode]);
            return(dbCmd);
        }
        public ActionResult EditProfile()
        {
            UserSession userSessionMgr = (UserSession)Session[SessionManagement.Constants.UserSessionMgr];

            if (userSessionMgr == null) // we were not signed on yet
            {
                return(RedirectToAction(Constants.SignOn, Constants.Account, Constants.Admin));
            }
            if (userSessionMgr.IsAccessAllowed(Constants.UIControlCode_AdminEditProfile_Code))
            {
                DataAccessMgr daMgr = Global.GetDataAccessMgr(this.HttpContext);
                DbCommand     dbCmd = UserMaster.GetUserMasterCmd(daMgr);
                dbCmd.Parameters[daMgr.BuildParamName(DataManagement.Constants.UserId)].Value = this.HttpContext.User.Identity.Name;
                EditProfileModel profileData = daMgr.ExecuteCollection <EditProfileModel>(dbCmd, null).First();
                return(View(Constants._Page_EditProfile, profileData));
            }
            ViewBag.Status = "Insufficient privileges for the action." + Request.Url;
            string referUrl = Request.QueryString[Constants.UrlReferrer];

            System.Web.Routing.RouteValueDictionary dictionary = new System.Web.Routing.RouteValueDictionary();
            dictionary.Add(Constants.UrlReferrer, referUrl);
            return(RedirectToAction(Constants.AccessDenied, Constants.Home, dictionary));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Returns the proper parameter name based upon back end db type.
 /// For commands that Set a Value only where its current value is a specific value
 /// e.g. Set x = 1 where x = 2
 /// We have to name 1 of the parameters differently, we have chosen the SetParam (NewValue)
 /// If IsNewValueParam is true, we will use a special suffix
 /// NOTE: For SQLServer this is the same as BindVariable, but not so for oracle.
 /// </summary>
 /// <param name="variableName"></param>
 /// <param name="isNewValueParam"></param>
 /// <returns></returns>
 public string BuildParamName(string variableName, bool isNewValueParam)
 {
     return(_daMgr.BuildParamName(variableName, isNewValueParam));
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Changes the given user's password to the new password and resets any account restrictions
        /// depending on given parameter.
        /// <para>The method assumes the caller has verified the spelling of the new password.</para>
        /// <para>The method also assumes the caller has verified the existing password if applicable.</para>
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="userId">Unique user identifier</param>
        /// <param name="newPassword">The new password (unhashed) plain text</param>
        /// <param name="resetSignonRestrictions">Indicates whether the accounts restrictions will be reset</param>
        public static void ChangePassword(DataAccessMgr daMgr
                                          , string userId
                                          , string newPassword
                                          , bool resetSignonRestrictions)
        {
            string salt = Cryptography.HashOperation.CreateRandomSalt(Cryptography.HashAlgorithmTypeEnum.SHA512HashAlgorithm);
            string hash = Cryptography.HashOperation.ComputeHash(Cryptography.HashAlgorithmTypeEnum.SHA512HashAlgorithm
                                                                 , newPassword
                                                                 , salt);
            DbTableDmlMgr dmlUpdate = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                    , Constants.UserMaster);

            dmlUpdate.AddColumn(Constants.UserPassword
                                , daMgr.BuildParamName(Constants.UserPassword));
            dmlUpdate.AddColumn(Constants.PasswordSalt
                                , daMgr.BuildParamName(Constants.PasswordSalt));
            dmlUpdate.AddColumn(Constants.FailedSignonAttempts
                                , daMgr.BuildParamName(Constants.FailedSignonAttempts));
            dmlUpdate.AddColumn(Constants.ForcePasswordChange
                                , daMgr.BuildParamName(Constants.ForcePasswordChange));

            if (resetSignonRestrictions)
            {
                dmlUpdate.AddColumn(Constants.SignonRestricted
                                    , daMgr.BuildParamName(Constants.SignonRestricted));
            }

            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;
            cmdUpdate.Parameters[daMgr.BuildParamName(Constants.UserPassword)].Value
                = hash;
            cmdUpdate.Parameters[daMgr.BuildParamName(Constants.PasswordSalt)].Value
                = salt;
            if (resetSignonRestrictions)
            {
                cmdUpdate.Parameters[daMgr.BuildParamName(Constants.SignonRestricted)].Value
                    = 0;
            }
            cmdUpdate.Parameters[daMgr.BuildParamName(Constants.FailedSignonAttempts)].Value
                = 0;
            cmdUpdate.Parameters[daMgr.BuildParamName(Constants.ForcePasswordChange)].Value
                = 0;
            daMgr.ExecuteNonQuery(cmdUpdate, null, null);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Method with change the settings of the SignonControl table to the given new settings only if they have not already been changed.
        /// <para>If </para>
        /// </summary>
        /// <param name="lastModifiedUser">The userCode of the user who last updated the record (or null if not changed)</param>
        /// <param name="lastModifiedDateTime">The DateTime of when the user last updated the record (or null if not changed)</param>
        /// <param name="newControlSettings">Signon Control Data Strcutre containing the new values.</param>
        /// <returns>Boolean indicating if record was changed or not.</returns>
        internal bool ChangeControl(int?lastModifiedByUserCode
                                    , DateTime?lastModifiedDateTime
                                    , SignonControlStructure newControlSettings)
        {
            DbTableDmlMgr dmlChange = _daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                     , Constants.SignonControl);

            dmlChange.AddColumn(Constants.TimeoutSeconds);
            dmlChange.AddColumn(Constants.SignoffWarningMsg);
            dmlChange.AddColumn(Constants.ForceSignOff);
            dmlChange.AddColumn(Constants.RestrictSignon);
            dmlChange.AddColumn(Constants.StatusSeconds);
            dmlChange.AddColumn(Constants.RestrictSignonMsg);
            dmlChange.AddColumn(Constants.FailedAttemptLimit);

            dmlChange.SetWhereCondition((j) =>
                                        j.Column(Constants.SignonControl) ==
                                        j.Parameter(Constants.SignonControl));

            DbCommandMgr dbCmdMgr      = new DbCommandMgr(_daMgr);
            DbCommand    cmdChangeOrig = _daMgr.BuildChangeDbCommand(dmlChange
                                                                     , Constants.LastModifiedUserCode
                                                                     , Constants.LastModifiedDateTime);

            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.ControlCode)].Value
                = newControlSettings.SessionControlCode;
            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.TimeoutSeconds)].Value
                = Convert.ToInt16(newControlSettings.TimeOutSeconds);
            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.SignoffWarningMsg)].Value
                = newControlSettings.SignoffWarningMsg;
            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.ForceSignOff)].Value
                = newControlSettings.ForceSignoff;
            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.RestrictSignon)].Value
                = newControlSettings.RestrictSignon;
            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.RestrictSignonMsg)].Value
                = newControlSettings.RestrictSignonMsg;
            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.StatusSeconds)].Value
                = newControlSettings.StatusSeconds;
            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.FailedAttemptLimit)].Value
                = newControlSettings.FailedAttemptLimit;
            if (lastModifiedByUserCode.HasValue)
            {
                cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.LastModifiedUserCode)].Value
                    = lastModifiedByUserCode.Value;
            }
            if (lastModifiedDateTime.HasValue)
            {
                cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.LastModifiedDateTime)].Value
                    = lastModifiedDateTime.Value;
            }
            if (newControlSettings.LastModifiedByUserCode.HasValue)
            {
                cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.LastModifiedUserCode, true)].Value
                    = newControlSettings.LastModifiedByUserCode.Value;
            }
            cmdChangeOrig.Parameters[_daMgr.BuildParamName(Constants.LastModifiedDateTime, true)].Value
                = newControlSettings.LastModifiedByDateTime.Value;

            int rowsAffected = _daMgr.ExecuteNonQuery(cmdChangeOrig, null, null);

            if (rowsAffected == 1)
            {
                _signonControl.FailedAttemptLimit     = newControlSettings.FailedAttemptLimit;
                _signonControl.ForceSignoff           = newControlSettings.ForceSignoff;
                _signonControl.RestrictSignon         = newControlSettings.RestrictSignon;
                _signonControl.RestrictSignonMsg      = newControlSettings.RestrictSignonMsg;
                _signonControl.SignoffWarningMsg      = newControlSettings.SignoffWarningMsg;
                _signonControl.StatusSeconds          = newControlSettings.StatusSeconds;
                _signonControl.TimeOutSeconds         = newControlSettings.TimeOutSeconds;
                _signonControl.LastModifiedByUserCode = newControlSettings.LastModifiedByUserCode;
                _signonControl.LastModifiedByDateTime = newControlSettings.LastModifiedByDateTime;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Adds a record to the session database table
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="userId">Unique user identifier</param>
        /// <param name="userCode">Unique numeric user identifier</param>
        /// <param name="userEnv">MetaData about the user's environment</param>
        /// <returns>A unique session code</returns>
        static Int64 AddSession(DataAccessMgr daMgr, string userId, Int32 userCode, UserEnvironmentStructure userEnv)
        {
            Int64         sessionCode = daMgr.GetNextSequenceNumber(Constants.SessionCode);
            DbTableDmlMgr dmlInsert   = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                      , Constants.UserSessions);

            dmlInsert.AddColumn(Constants.SessionCode, daMgr.BuildParamName(Constants.SessionCode));
            dmlInsert.AddColumn(Constants.UserCode, daMgr.BuildParamName(Constants.UserCode));
            dmlInsert.AddColumn(Constants.UserId, daMgr.BuildParamName(Constants.UserId));
            dmlInsert.AddColumn(Constants.AppCode, daMgr.BuildParamName(Constants.AppCode));
            dmlInsert.AddColumn(Constants.AppId, daMgr.BuildParamName(Constants.AppId));
            dmlInsert.AddColumn(Constants.AppMachine, daMgr.BuildParamName(Constants.AppMachine));
            dmlInsert.AddColumn(Constants.AppVersion, daMgr.BuildParamName(Constants.AppVersion));
            dmlInsert.AddColumn(Constants.RemoteAddress, daMgr.BuildParamName(Constants.RemoteAddress));

            DbCommand cmdInsert = daMgr.BuildInsertDbCommand(dmlInsert);

            cmdInsert.Parameters[daMgr.BuildParamName(Constants.SessionCode)].Value   = sessionCode;
            cmdInsert.Parameters[daMgr.BuildParamName(Constants.UserId)].Value        = userId;
            cmdInsert.Parameters[daMgr.BuildParamName(Constants.UserCode)].Value      = userCode;
            cmdInsert.Parameters[daMgr.BuildParamName(Constants.AppId)].Value         = userEnv.AppId;
            cmdInsert.Parameters[daMgr.BuildParamName(Constants.AppCode)].Value       = userEnv.AppCode;
            cmdInsert.Parameters[daMgr.BuildParamName(Constants.AppVersion)].Value    = userEnv.AppVersion;
            cmdInsert.Parameters[daMgr.BuildParamName(Constants.RemoteAddress)].Value = userEnv.RemoteAddress;
            cmdInsert.Parameters[daMgr.BuildParamName(Constants.AppMachine)].Value    = Environment.MachineName;

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

            dmlUpdate.AddColumn(Constants.FailedSignonAttempts
                                , daMgr.BuildParamName(Constants.FailedSignonAttempts));
            dmlUpdate.AddColumn(Constants.LastSignonDateTime
                                , EnumDateTimeLocale.Default);

            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;
            cmdUpdate.Parameters[daMgr.BuildParamName(Constants.FailedSignonAttempts)].Value
                = 0;
            DbCommandMgr cmdMgr = new DbCommandMgr(daMgr);

            cmdMgr.AddDbCommand(cmdInsert);
            cmdMgr.AddDbCommand(cmdUpdate);
            cmdMgr.ExecuteNonQuery();
            return(sessionCode);
        }
Ejemplo n.º 24
0
        /// <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);
        }
        /// <summary>
        /// Builds the DbCommand to Change the value of the edited columns found in the given dictionary.
        /// </summary>
        /// <param name="daMgr">DataAccessMgr object</param>
        /// <param name="taskQueueItem">The data row containing the values of the parameters</param>
        /// <param name="editedColumns">The columns that need to be updated</param>
        /// <param name="userCode">The userCode that updated the data</param>
        /// <returns>DbCommand Object with DbNull Parameter values</returns>
        public static DbCommand GetDependencyDmlCmd(DataAccessMgr daMgr
                                                    , DataRow taskQueueItem
                                                    , Dictionary <string, object> editedColumns
                                                    , Int32?userCode = null)
        {
            DbCommand     dbCmd  = null;
            DbTableDmlMgr dmlMgr = daMgr.DbCatalogGetTableDmlMgr(DataAccess.Constants.SCHEMA_CORE
                                                                 , TaskProcessing.Constants.TaskDependencies);

            foreach (string column in editedColumns.Keys)
            {
                dmlMgr.AddColumn(column);
            }
            if (taskQueueItem == null) // add new item
            {
                dmlMgr.AddColumn(TaskProcessing.Constants.LastModifiedUserCode);
                dmlMgr.AddColumn(TaskProcessing.Constants.LastModifiedDateTime);
                dbCmd = daMgr.BuildInsertDbCommand(dmlMgr);
            }

            else
            {
                dbCmd = daMgr.BuildChangeDbCommand(dmlMgr, TaskProcessing.Constants.LastModifiedUserCode
                                                   , TaskProcessing.Constants.LastModifiedDateTime);
            }

            foreach (string column in editedColumns.Keys)
            {
                dbCmd.Parameters[daMgr.BuildParamName(column)].Value
                    = editedColumns[column];
            }

            if (taskQueueItem == null) // add new
            {
                if (userCode.HasValue)
                {
                    dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedUserCode)].Value
                        = userCode.Value;
                    dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedDateTime)].Value
                        = daMgr.DbSynchTime;
                }
                else
                {
                    dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedUserCode)].Value
                        = DBNull.Value;

                    dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedDateTime)].Value
                        = DBNull.Value;
                }
            }
            else  // change; where condition params
            {
                dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedUserCode)].Value
                    = taskQueueItem[TaskProcessing.Constants.LastModifiedUserCode];
                dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedDateTime)].Value
                    = taskQueueItem[TaskProcessing.Constants.LastModifiedDateTime];
                // set portion of the update
                if (userCode.HasValue)
                {
                    dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedUserCode, true)].Value
                        = userCode.Value;
                    dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedDateTime, true)].Value
                        = daMgr.DbSynchTime;
                }
                else
                {
                    dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedUserCode, true)].Value
                        = DBNull.Value;
                    dbCmd.Parameters[daMgr.BuildParamName(TaskProcessing.Constants.LastModifiedDateTime, true)].Value
                        = DBNull.Value;
                }
            }

            return(dbCmd);
        }