public ExiftoolData(ExiftoolData exifToolData, object newTristateValue, bool hasValueSet) { this.FileName = exifToolData.FileName; this.FileDirectory = exifToolData.FileDirectory; this.FileDateModified = exifToolData.FileDateModified; this.Region = exifToolData.Region; this.Command = exifToolData.Command; this.Parameter = exifToolData.Parameter; this.TristateValue = newTristateValue; this.HasValueSet = hasValueSet; }
public List <ExiftoolData> Read(FileEntry file) { List <ExiftoolData> exifToolDataList = new List <ExiftoolData>(); Mono.Data.Sqlite.SqliteTransaction sqlTransactionSelect; do { sqlTransactionSelect = dbTools.TransactionBeginSelect(); #region SELECT FROM MediaExiftoolTags string sqlCommand = "SELECT FileDirectory, FileName, FileDateModified, Region, Command, Parameter FROM " + "MediaExiftoolTags WHERE FileDirectory = @FileDirectory AND FileName = @FileName AND FileDateModified = @FileDateModified"; using (var commandDatabase = new CommonSqliteCommand(sqlCommand, dbTools.ConnectionDatabase, sqlTransactionSelect)) { //commandDatabase.Prepare(); commandDatabase.Parameters.AddWithValue("@FileDirectory", Path.GetDirectoryName(file.FileFullPath)); commandDatabase.Parameters.AddWithValue("@FileName", Path.GetFileName(file.FileFullPath)); commandDatabase.Parameters.AddWithValue("@FileDateModified", dbTools.ConvertFromDateTimeToDBVal(file.LastWriteDateTime)); using (CommonSqliteDataReader reader = commandDatabase.ExecuteReader()) { while (reader.Read()) { ExiftoolData exifToolData = new ExiftoolData(); exifToolData.FileDirectory = dbTools.ConvertFromDBValString(reader["FileDirectory"]); exifToolData.FileName = dbTools.ConvertFromDBValString(reader["FileName"]); exifToolData.FileDateModified = (DateTime)dbTools.ConvertFromDBValDateTimeLocal(reader["FileDateModified"]); exifToolData.Region = dbTools.ConvertFromDBValString(reader["Region"]); exifToolData.Command = dbTools.ConvertFromDBValString(reader["Command"]); exifToolData.Parameter = dbTools.ConvertFromDBValString(reader["Parameter"]); exifToolDataList.Add(exifToolData); } } } #endregion } while (!dbTools.TransactionCommitSelect(sqlTransactionSelect)); return(exifToolDataList); }
public void Write(ExiftoolData exifToolData) { int resultRowsAffected = 1; Mono.Data.Sqlite.SqliteTransaction sqlTransaction = null; do { #region If failed to updated data, delete and retry if (resultRowsAffected == -1) { Logger.Error("Delete MediaExiftoolTags data due to previous application crash for file: " + exifToolData.FullFilePath); dbTools.TransactionRollback(sqlTransaction); DeleteFileEntryMediaExiftoolTags(new FileEntry(exifToolData.FileDirectory, exifToolData.FileName, exifToolData.FileDateModified)); } #endregion sqlTransaction = dbTools.TransactionBegin(); #region INSERT INTO MediaExiftoolTags string sqlCommand = "INSERT INTO MediaExiftoolTags (FileDirectory, FileName, FileDateModified, Region, Command, Parameter) " + "Values (@FileDirectory, @FileName, @FileDateModified, @Region, @Command, @Parameter)"; using (var commandDatabase = new CommonSqliteCommand(sqlCommand, dbTools.ConnectionDatabase, sqlTransaction)) { //commandDatabase.Prepare(); commandDatabase.Parameters.AddWithValue("@FileDirectory", exifToolData.FileDirectory); commandDatabase.Parameters.AddWithValue("@FileName", exifToolData.FileName); commandDatabase.Parameters.AddWithValue("@FileDateModified", dbTools.ConvertFromDateTimeToDBVal(exifToolData.FileDateModified)); commandDatabase.Parameters.AddWithValue("@Region", exifToolData.Region); commandDatabase.Parameters.AddWithValue("@Command", exifToolData.Command); commandDatabase.Parameters.AddWithValue("@Parameter", exifToolData.Parameter); resultRowsAffected = commandDatabase.ExecuteNonQuery(); } #endregion } while (resultRowsAffected == -1 || !dbTools.TransactionCommit(sqlTransaction)); }
public void Write(ExiftoolData exifToolOldValue, ExiftoolData exifToolNewValue, string warning) { int resultRowsAffected = 1; Mono.Data.Sqlite.SqliteTransaction sqlTransaction = null; do { #region If failed to updated data, delete and retry if (resultRowsAffected == -1) { Logger.Error("Delete MediaExiftoolTagsWarning data due to previous application crash for file: " + exifToolNewValue.FullFilePath); try { dbTools.TransactionRollback(sqlTransaction); } catch { } //Delete all extries due to crash. DeleteFileEntryFromMediaExiftoolTagsWarning(new FileEntry(exifToolNewValue.FileDirectory, exifToolNewValue.FileName, exifToolNewValue.FileDateModified)); } #endregion sqlTransaction = dbTools.TransactionBegin(); #region SELECT Warning FROM MediaExiftoolTagsWarning warning = "(Logged: " + DateTime.Now.ToString() + ")\r\n" + warning; string sqlRead = "SELECT Warning FROM MediaExiftoolTagsWarning WHERE " + "FileDirectory = @FileDirectory AND FileName = @FileName AND FileDateModified = @FileDateModified AND " + "OldRegion = @OldRegion AND OldCommand = @OldCommand AND " + "NewRegion = @NewRegion AND NewCommand = @NewCommand"; bool oldRecordFound = false; using (var commandDatabase = new CommonSqliteCommand(sqlRead, dbTools.ConnectionDatabase, sqlTransaction)) { //commandDatabase.Prepare(); commandDatabase.Parameters.AddWithValue("@FileDirectory", exifToolNewValue.FileDirectory); commandDatabase.Parameters.AddWithValue("@FileName", exifToolNewValue.FileName); commandDatabase.Parameters.AddWithValue("@FileDateModified", dbTools.ConvertFromDateTimeToDBVal(exifToolNewValue.FileDateModified)); commandDatabase.Parameters.AddWithValue("@OldRegion", exifToolOldValue.Region); commandDatabase.Parameters.AddWithValue("@OldCommand", exifToolOldValue.Command); commandDatabase.Parameters.AddWithValue("@NewRegion", exifToolNewValue.Region); commandDatabase.Parameters.AddWithValue("@NewCommand", exifToolNewValue.Command); using (CommonSqliteDataReader reader = commandDatabase.ExecuteReader()) { while (reader.Read()) { warning = warning + "\r\n" + dbTools.ConvertFromDBValString(reader["Warning"]); } } oldRecordFound = true; } #endregion #region DELETE FROM MediaExiftoolTagsWarning if (oldRecordFound) { string sqlDelete = "DELETE FROM MediaExiftoolTagsWarning WHERE " + "FileDirectory = @FileDirectory AND FileName = @FileName AND FileDateModified = @FileDateModified AND " + "OldRegion = @OldRegion AND OldCommand = @OldCommand AND " + "NewRegion = @NewRegion AND NewCommand = @NewCommand"; using (var commandDatabase = new CommonSqliteCommand(sqlDelete, dbTools.ConnectionDatabase, sqlTransaction)) { //commandDatabase.Prepare(); commandDatabase.Parameters.AddWithValue("@FileDirectory", exifToolNewValue.FileDirectory); commandDatabase.Parameters.AddWithValue("@FileName", exifToolNewValue.FileName); commandDatabase.Parameters.AddWithValue("@FileDateModified", dbTools.ConvertFromDateTimeToDBVal(exifToolNewValue.FileDateModified)); commandDatabase.Parameters.AddWithValue("@OldRegion", exifToolOldValue.Region); commandDatabase.Parameters.AddWithValue("@OldCommand", exifToolOldValue.Command); commandDatabase.Parameters.AddWithValue("@NewRegion", exifToolNewValue.Region); commandDatabase.Parameters.AddWithValue("@NewCommand", exifToolNewValue.Command); resultRowsAffected = commandDatabase.ExecuteNonQuery(); } } #endregion #region INSERT INTO MediaExiftoolTagsWarning if (resultRowsAffected != -1) { string sqlCommand = "INSERT INTO MediaExiftoolTagsWarning (FileDirectory, FileName, FileDateModified, OldRegion, OldCommand, OldParameter, NewRegion, NewCommand, NewParameter, Warning) " + "Values (@FileDirectory, @FileName, @FileDateModified, @OldRegion, @OldCommand, @OldParameter, @NewRegion, @NewCommand, @NewParameter, @Warning)"; using (var commandDatabase = new CommonSqliteCommand(sqlCommand, dbTools.ConnectionDatabase, sqlTransaction)) { //commandDatabase.Prepare(); commandDatabase.Parameters.AddWithValue("@FileDirectory", exifToolNewValue.FileDirectory); commandDatabase.Parameters.AddWithValue("@FileName", exifToolNewValue.FileName); commandDatabase.Parameters.AddWithValue("@FileDateModified", dbTools.ConvertFromDateTimeToDBVal(exifToolNewValue.FileDateModified)); commandDatabase.Parameters.AddWithValue("@OldRegion", exifToolOldValue.Region); commandDatabase.Parameters.AddWithValue("@OldCommand", exifToolOldValue.Command); commandDatabase.Parameters.AddWithValue("@OldParameter", exifToolOldValue.Parameter); commandDatabase.Parameters.AddWithValue("@NewRegion", exifToolNewValue.Region); commandDatabase.Parameters.AddWithValue("@NewCommand", exifToolNewValue.Command); commandDatabase.Parameters.AddWithValue("@NewParameter", exifToolNewValue.Parameter); commandDatabase.Parameters.AddWithValue("@Warning", warning); resultRowsAffected = commandDatabase.ExecuteNonQuery(); } } #endregion } while (resultRowsAffected == -1 || !dbTools.TransactionCommit(sqlTransaction)); }