Beispiel #1
0
            public void Execute(Db db, MetaItem db_version)
            {
                code();

                Console.WriteLine("Updated database from version {0} to {1}",
                                  db_version.Value,
                                  Version.ToString());


                db_version.Value = Version.ToString();
                db.Meta.Commit(db_version);
            }
Beispiel #2
0
        public static void Run(Db database)
        {
            db         = database;
            db_version = db.Meta.DatabaseVersion;

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

            Version current_version = new Version(db_version.Value);

            if (current_version == LatestVersion)
            {
                return;
            }
            else if (current_version > LatestVersion)
            {
                Console.WriteLine("The existing database version is more recent than this version of F-Spot expects.");
                return;
            }

            Console.WriteLine("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 > current_version && (updates[version] as Update).IsSlow)
                {
                    slow = true;
                }
                break;
            }

            if (slow)
            {
                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 {
                ArrayList keys = new ArrayList(updates.Keys);
                keys.Sort();
                foreach (Version version in keys)
                {
                    if (version <= current_version)
                    {
                        continue;
                    }

                    Pulse();
                    (updates[version] as Update).Execute(db, db_version);
                }

                db.CommitTransaction();
            } catch (Exception e) {
                Console.WriteLine("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 (new Version(db_version.Value) == LatestVersion)
            {
                Console.WriteLine("Database updates completed successfully.");
            }
        }