예제 #1
0
 /// <summary>
 /// Update MetaData information.
 /// </summary>
 /// <param name="oldMetadata">Outdated metadata.</param>
 /// <param name="newMetada">Updated metadata.</param>
 /// <returns>true if update successful.</returns>
 public abstract bool Update(Metadata oldMetadata, Metadata newMetada);
예제 #2
0
        /// <summary>
        /// Update meta data including file metadata and folder metadata
        /// </summary>
        /// <param name="oldMetadata"></param>
        /// <param name="newMetada"></param>
        /// <returns></returns>
        public override bool Update(Metadata oldMetadata, Metadata newMetada)
        {
            var db = new SQLiteAccess(Path.Combine(this.StoragePath, Configuration.DATABASE_NAME),false);
            using (SqliteConnection con = db.NewSQLiteConnection())
            {
                if (con == null)
                    throw new DatabaseException(String.Format(m_ResourceManager.GetString("err_somethingNotFound"), Path.Combine(this.StoragePath, Configuration.DATABASE_NAME)));

                var trasaction = (SqliteTransaction)con.BeginTransaction();
                // TODO: make 3 actions atomic
                try
                {
                    if (!UpdateFileMetadata(oldMetadata.FileMetadata, newMetada.FileMetadata, con))
                        throw new Exception();
                    if (!UpdateFolderMetadata(oldMetadata.FolderMetadata, newMetada.FolderMetadata, con))
                        throw new Exception();
                    trasaction.Commit();
                }
                catch (Exception)
                {
                    trasaction.Rollback();
                    return false;
                }
            }
            return true;
        }