Esempio n. 1
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);
        }
        /// <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);
        }
Esempio n. 3
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);
        }