예제 #1
0
        public void Init(string path, bool create_if_missing)
        {
            uint timer  = Log.DebugTimerStart();
            bool new_db = !File.Exists(path);

            this.path = path;

            if (new_db && !create_if_missing)
            {
                throw new Exception(path + ": File not found");
            }

            Database = new FSpotDatabaseConnection(path);

            // Load or create the meta table
            Meta = new MetaStore(Database, new_db);

            // Update the database schema if necessary
            FSpot.Database.Updater.Run(Database);

            Database.BeginTransaction();

            Tags    = new TagStore(Database, new_db);
            Rolls   = new RollStore(Database, new_db);
            Exports = new ExportStore(Database, new_db);
            Jobs    = new JobStore(Database, new_db);
            Photos  = new PhotoStore(Database, new_db);

            Database.CommitTransaction();

            Empty = new_db;
            Log.DebugTimerPrint(timer, "Db Initialization took {0}");
        }
예제 #2
0
        // Constructor.

        public DbStore(FSpotDatabaseConnection database, bool cache_is_immortal)
        {
            Database = database;
            this.cache_is_immortal = cache_is_immortal;

            item_cache = new Dictionary <uint, object> ();
        }
예제 #3
0
        internal static void CreateTable(FSpotDatabaseConnection database)
        {
            if (database.TableExists(jobsTableName))
            {
                return;
            }

            database.Execute(
                $"CREATE TABLE {jobsTableName} (\n" +
                "  id           INTEGER PRIMARY KEY NOT NULL, \n" +
                "  job_type     TEXT NOT NULL, \n" +
                "  job_options  TEXT NOT NULL, \n" +
                "  run_at       INTEGER, \n" +
                "  job_priority INTEGER NOT NULL\n" +
                ")");
        }
예제 #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }
            disposed = true;

            // free managed resources
            if (disposing)
            {
                if (Tags != null)
                {
                    Tags.Dispose();
                    Tags = null;
                }
                if (Database != null)
                {
                    Database.Dispose();
                    Database = null;
                }
            }
            // free unmanaged resources
        }
예제 #5
0
파일: Db.cs 프로젝트: GNOME/f-spot
        public void Init(string path, bool create_if_missing)
        {
            uint timer = Log.DebugTimerStart ();
            bool new_db = !File.Exists (path);
            this.path = path;

            if (new_db && !create_if_missing)
                throw new Exception (path + ": File not found");

            Database = new FSpotDatabaseConnection (path);

            // Load or create the meta table
            Meta = new MetaStore (Database, new_db);

            // Update the database schema if necessary
            FSpot.Database.Updater.Run (Database);

            Database.BeginTransaction ();

            Tags = new TagStore (Database, new_db);
            Rolls = new RollStore (Database, new_db);
            Exports = new ExportStore (Database, new_db);
            Jobs = new JobStore (Database, new_db);
            Photos = new PhotoStore (Database, new_db);

            Database.CommitTransaction ();

            Empty = new_db;
            Log.DebugTimerPrint (timer, "Db Initialization took {0}");
        }
예제 #6
0
        public static void Run(FSpotDatabaseConnection database)
        {
            db         = database;
            db_version = GetDatabaseVersion();

            if (updates.Count == 0)
            {
                return;
            }

            if (db_version == LatestVersion)
            {
                return;
            }
            else if (db_version > LatestVersion)
            {
                if (!silent)
                {
                    Log.Information("The existing database version is more recent than this version of F-Spot expects.");
                }
                return;
            }

            uint timer = 0;

            if (!silent)
            {
                timer = Log.InformationTimerStart("Updating F-Spot Database");
            }

            // Only create and show the dialog if one or more of the updates to be done is
            // marked as being slow
            bool slow = false;

            foreach (Version version in updates.Keys)
            {
                if (version > db_version && (updates [version] as Update).IsSlow)
                {
                    slow = true;
                }
                break;
            }

            if (slow && !silent)
            {
                dialog = new ProgressDialog(Catalog.GetString("Updating F-Spot Database"), ProgressDialog.CancelButtonType.None, 0, null);
                dialog.Message.Text    = Catalog.GetString("Please wait while your F-Spot gallery's database is updated. This may take some time.");
                dialog.Bar.Fraction    = 0.0;
                dialog.Modal           = false;
                dialog.SkipTaskbarHint = true;
                dialog.WindowPosition  = WindowPosition.Center;
                dialog.ShowAll();
                dialog.Present();
                dialog.QueueDraw();
            }

            db.BeginTransaction();
            try {
                List <Version> keys = new List <Version> ();
                foreach (Version k in updates.Keys)
                {
                    keys.Add(k);
                }
                keys.Sort();
                foreach (Version version in keys)
                {
                    if (version <= db_version)
                    {
                        continue;
                    }
                    Pulse();
                    (updates [version] as Update).Execute(db, db_version);
                }

                db.CommitTransaction();
            } catch (Exception e) {
                if (!silent)
                {
                    Log.DebugException(e);
                    Log.Warning("Rolling back database changes because of Exception");
                }
                // There was an error, roll back the database
                db.RollbackTransaction();

                // Pass the exception on, this is fatal
                throw e;
            }

            if (dialog != null)
            {
                dialog.Destroy();
            }

            if (db_version == LatestVersion && !silent)
            {
                Log.InformationTimerPrint(timer, "Database updates completed successfully (in {0}).");
            }
        }
예제 #7
0
파일: Updater.cs 프로젝트: GNOME/f-spot
        public static void Run(FSpotDatabaseConnection database)
        {
            db = database;
            db_version = GetDatabaseVersion ();

            if (updates.Count == 0)
                return;

            if (db_version == LatestVersion)
                return;
            else if (db_version > LatestVersion) {
                if (!silent)
                    Log.Information ("The existing database version is more recent than this version of F-Spot expects.");
                return;
            }

            uint timer = 0;
            if (!silent)
                timer = Log.InformationTimerStart ("Updating F-Spot Database");

            // Only create and show the dialog if one or more of the updates to be done is
            // marked as being slow
            bool slow = false;
            foreach (Version version in updates.Keys) {
                if (version > db_version && (updates [version] as Update).IsSlow)
                    slow = true;
                break;
            }

            if (slow && !silent) {
                dialog = new ProgressDialog (Catalog.GetString ("Updating F-Spot Database"), ProgressDialog.CancelButtonType.None, 0, null);
                dialog.Message.Text = Catalog.GetString ("Please wait while your F-Spot gallery's database is updated. This may take some time.");
                dialog.Bar.Fraction = 0.0;
                dialog.Modal = false;
                dialog.SkipTaskbarHint = true;
                dialog.WindowPosition = WindowPosition.Center;
                dialog.ShowAll ();
                dialog.Present ();
                dialog.QueueDraw ();
            }

            db.BeginTransaction ();
            try {
                List<Version> keys = new List<Version> ();
                foreach (Version k in updates.Keys) {
                    keys.Add(k);
                }
                keys.Sort ();
                foreach (Version version in keys) {
                    if (version <= db_version)
                        continue;
                    Pulse ();
                    (updates [version] as Update).Execute (db, db_version);
                }

                db.CommitTransaction ();
            } catch (Exception e) {
                if (!silent) {
                    Log.DebugException (e);
                    Log.Warning ("Rolling back database changes because of Exception");
                }
                // There was an error, roll back the database
                db.RollbackTransaction ();

                // Pass the exception on, this is fatal
                throw e;
            }

            if (dialog != null)
                dialog.Destroy ();

            if (db_version == LatestVersion && !silent)
                Log.InformationTimerPrint (timer, "Database updates completed successfully (in {0}).");
        }
예제 #8
0
        public static void Run(FSpotDatabaseConnection database, IUpdaterUI updaterDialog)
        {
            db     = database;
            dialog = updaterDialog;

            db_version = GetDatabaseVersion();

            if (updates.Count == 0)
            {
                return;
            }

            if (db_version == LatestVersion)
            {
                return;
            }
            else if (db_version > LatestVersion)
            {
                if (!silent)
                {
                    Log.Information("The existing database version is more recent than this version of F-Spot expects.");
                }
                return;
            }

            uint timer = 0;

            if (!silent)
            {
                timer = Log.InformationTimerStart("Updating F-Spot Database");
            }

            // Only create and show the dialog if one or more of the updates to be done is
            // marked as being slow
            bool slow = false;

            foreach (Version version in updates.Keys)
            {
                if (version > db_version && (updates [version] as Update).IsSlow)
                {
                    slow = true;
                }
                break;
            }

            if (slow && !silent)
            {
                dialog.Show();
            }

            db.BeginTransaction();
            try {
                List <Version> keys = new List <Version> ();
                foreach (Version k in updates.Keys)
                {
                    keys.Add(k);
                }
                keys.Sort();
                foreach (Version version in keys)
                {
                    if (version <= db_version)
                    {
                        continue;
                    }
                    dialog.Pulse();
                    (updates [version] as Update).Execute(db, db_version);
                }

                db.CommitTransaction();
            } catch (Exception e) {
                if (!silent)
                {
                    Log.DebugException(e);
                    Log.Warning("Rolling back database changes because of Exception");
                }
                // There was an error, roll back the database
                db.RollbackTransaction();

                // Pass the exception on, this is fatal
                throw e;
            }

            dialog.Destroy();

            if (db_version == LatestVersion && !silent)
            {
                Log.InformationTimerPrint(timer, "Database updates completed successfully (in {0}).");
            }
        }