Example #1
0
 public FileLogEntry(string userIdStr, ulong fileID, FileLogEntryType fileLogEntryType, DateTime when, string extraInfo1, string extraInfo2)
 {
     _userIdStr = userIdStr;
     _fileID = fileID;
     _fileLogEntryType = fileLogEntryType;
     _when = when;
     _extraInfo1 = extraInfo1;
     _extraInfo2 = extraInfo2;
 }
Example #2
0
        internal static void AddLogEntry(string userIDStr, ulong fileID, FileLogEntryType fileLogEntryType, DateTime when, string extraInfo1, string extraInfo2)
        {
            string insertDateTime = StringUtils.GetAsZeroPaddedFourCharString (when.Year) + "-"
                                    + StringUtils.GetAsZeroPaddedTwoCharString (when.Month) + "-"
                                    + StringUtils.GetAsZeroPaddedTwoCharString (when.Day) + " "
                                    + StringUtils.GetAsZeroPaddedTwoCharString (when.Hour) + ":"
                                    + StringUtils.GetAsZeroPaddedTwoCharString (when.Minute) + ":"
                                    + StringUtils.GetAsZeroPaddedTwoCharString (when.Second);

            string sql = "insert into L_FileLogEntries (UserIDStr, fkey_FileID, AccessType, WhenDateTime, ExtraInfo1, ExtraInfo2) values ('" +
                userIDStr + "', " + fileID + ", '" + fileLogEntryType.ToString () + "', '" + insertDateTime + "', " +
                (extraInfo1 == null ? "null, " : "'" + extraInfo1 + "', ") +
                (extraInfo2 == null ? "null" : "'" + extraInfo2 + "'") +
                ")";
            Debug.Print ("Add file log entry: " + sql);

            SQLiteConnection cnn = null;
            SQLiteTransaction transaction = null;
            try {
                cnn = new SQLiteConnection (LOGDB_CONN_STR_FOR_WRITING);
                cnn.Open ();
                transaction = cnn.BeginTransaction ();

                SQLiteCommand myCommand = new SQLiteCommand (sql, cnn);
                myCommand.ExecuteNonQuery ();
            } catch (Exception e) {
                Trace.TraceError (e.Message);
                throw new MfsNonExistentResourceException (
                    MfsErrorMessages.GetMessage (MessageType.DB_EXC, e.Message)
                );
            } finally {
                if (transaction != null) {
                    transaction.Commit ();
                }
                if (cnn != null) {
                    cnn.Close ();
                }
            }
        }