Example #1
0
        /// <summary>
        /// This method returns the entire list of activity log entries from the
        /// persistent database.  Note that no filters are applied and every
        /// entry is returned.
        /// </summary>
        /// <remarks>
        ///  Revision History
        ///  MM/DD/YY Who Version Issue# Description
        ///  -------- --- ------- ------ -------------------------------------------
        ///  04/04/08 MAH		Created
        ///
        /// </remarks>
        private List <MeterActivityLogEntry> ReadAll(OleDbConnection dbActivityLog)
        {
            List <MeterActivityLogEntry> lstEntries = new List <MeterActivityLogEntry>();

            if (dbActivityLog.State == ConnectionState.Open)
            {
                OleDbCommand dbCommand = dbActivityLog.CreateCommand();

                String strCommandText = "SELECT * FROM ACTIVITYLOG";

                dbCommand.CommandText = strCommandText;

                OleDbDataReader reader = dbCommand.ExecuteReader();

                while (reader.Read())
                {
                    MeterActivityLogEntry logEntry = new MeterActivityLogEntry();

                    ReadActivityRecord(reader, logEntry);

                    lstEntries.Add(logEntry);
                }
            }

            return(lstEntries);
        }
Example #2
0
        public Boolean Add(MeterActivityLogEntry newLogEntry)
        {
            Boolean boolSuccess = false;

            try
            {
                // Make sure that all of the environment and application related
                // properties for this log entry have been set correctly.
                SetEnvironmentProperties(newLogEntry);

                // Before we try to add anything to the database, do a sanity check
                // first and make sure that the connection to the DB is open and
                // usable
                if (m_OleDbConnection.State == ConnectionState.Open)
                {
                    OleDbCommand dbCommand = m_OleDbConnection.CreateCommand();

                    dbCommand.CommandText = "INSERT INTO ACTIVITYLOG " +
                                            "(EVENTTIME,UNITID,SERIALNUMBER,DEVICETYPE,ACTIVITYID,ACTIVITYSTATUS,SOURCE,SOURCEVERSION,RESULTFILE,APPLICATION,APPLICATIONVERSION,MACHINENAME,USERID)" +
                                            "VALUES " +
                                            "(?,?,?,?,?,?,?,?,?,?,?,?,?)";

                    dbCommand.Parameters.Add(new OleDbParameter("EVENTTIME", newLogEntry.EventTime.ToString(CultureInfo.InvariantCulture)));
                    dbCommand.Parameters.Add(new OleDbParameter("UNITID", newLogEntry.UnitID));
                    dbCommand.Parameters.Add(new OleDbParameter("SERIALNUMBER", newLogEntry.SerialNumber));
                    dbCommand.Parameters.Add(new OleDbParameter("DEVICETYPE", newLogEntry.MeterType));
                    dbCommand.Parameters.Add(new OleDbParameter("ACTIVITYID", (int)newLogEntry.ActivityType));
                    dbCommand.Parameters.Add(new OleDbParameter("ACTIVITYSTATUS", (int)newLogEntry.ActivityStatus));
                    dbCommand.Parameters.Add(new OleDbParameter("SOURCE", newLogEntry.Source));
                    dbCommand.Parameters.Add(new OleDbParameter("SOURCEVERSION", newLogEntry.SourceVersion));
                    dbCommand.Parameters.Add(new OleDbParameter("RESULTFILE", newLogEntry.ResultFile));
                    dbCommand.Parameters.Add(new OleDbParameter("APPLICATION", newLogEntry.ApplicationName));
                    dbCommand.Parameters.Add(new OleDbParameter("APPLICATIONVERSION", newLogEntry.ApplicationVersion));
                    dbCommand.Parameters.Add(new OleDbParameter("MACHINENAME", newLogEntry.MachineName));
                    dbCommand.Parameters.Add(new OleDbParameter("USERID", newLogEntry.UserName));

                    int nRowsInserted = dbCommand.ExecuteNonQuery();

                    boolSuccess = (nRowsInserted == 1);
                }
                else
                {
                    boolSuccess = false;
                }
            }

            catch (Exception err)
            {
                MessageBox.Show("Unable to add activity log entry: " + err.Message);                 // TODO: handle this...
            }

            return(boolSuccess);
        }
Example #3
0
        /// <summary>
        /// This method is responsible for insuring that the default values of a meter
        /// activity log record are set appropriately prior to posting the record to
        /// the persistent database
        /// </summary>
        /// <remarks>
        ///  Revision History
        ///  MM/DD/YY Who Version Issue# Description
        ///  -------- --- ------- ------ -------------------------------------------
        ///  04/04/08 MAH		Created
        ///
        /// </remarks>
        private static void SetEnvironmentProperties(MeterActivityLogEntry newLogEntry)
        {
            if (String.IsNullOrEmpty(newLogEntry.ApplicationName))
            {
                newLogEntry.ApplicationName = Application.ProductName;
            }

            if (String.IsNullOrEmpty(newLogEntry.ApplicationVersion))
            {
                newLogEntry.ApplicationVersion = Application.ProductVersion;
            }

            if (String.IsNullOrEmpty(newLogEntry.MachineName))
            {
                newLogEntry.MachineName = Environment.MachineName;
            }

            if (String.IsNullOrEmpty(newLogEntry.UserName))
            {
                newLogEntry.UserName = Environment.UserName;
            }
        }
Example #4
0
        /// <summary>
        /// This method is responsible for extracting a meter activity log entry
        /// object from an OLE DB query result set
        /// </summary>
        /// <remarks>
        ///  Revision History
        ///  MM/DD/YY Who Version Issue# Description
        ///  -------- --- ------- ------ -------------------------------------------
        ///  04/04/08 MAH		Created
        ///
        /// </remarks>
        private static void ReadActivityRecord(OleDbDataReader reader, MeterActivityLogEntry logEntry)
        {
            for (int nColumn = 0; nColumn < reader.FieldCount; nColumn++)
            {
                String strColumnName = reader.GetName(nColumn).ToUpper(CultureInfo.InvariantCulture);

                switch (strColumnName)
                {
                case "EVENTTIME":
                    logEntry.EventTime = reader.GetDateTime(nColumn);
                    break;

                case "UNITID":
                    logEntry.UnitID = reader[nColumn].ToString();
                    break;

                case "SERIALNUMBER":
                    logEntry.SerialNumber = reader[nColumn].ToString();
                    break;

                case "DEVICETYPE":
                    logEntry.MeterType = reader[nColumn].ToString();
                    break;

                case "ACTIVITYID":
                    logEntry.ActivityType = (MeterActivityLogEntry.ActivityTypeEnum)reader[nColumn];
                    break;

                case "ACTIVITYSTATUS":
                    logEntry.ActivityStatus = (MeterActivityLogEntry.ActivityStatusEnum)reader[nColumn];
                    break;

                case "SOURCE":
                    logEntry.Source = reader[nColumn].ToString();
                    break;

                case "SOURCEVERSION":
                    logEntry.SourceVersion = reader[nColumn].ToString();
                    break;

                case "RESULTFILE":
                    logEntry.ResultFile = reader[nColumn].ToString();
                    break;

                case "APPLICATION":
                    logEntry.ApplicationName = reader[nColumn].ToString();
                    break;

                case "APPLICATIONVERSION":
                    logEntry.ApplicationVersion = reader[nColumn].ToString();
                    break;

                case "MACHINENAME":
                    logEntry.MachineName = reader[nColumn].ToString();
                    break;

                case "USERID":
                    logEntry.UserName = reader[nColumn].ToString();
                    break;

                default:
                    break;
                }
            }
        }