Esempio n. 1
0
        void DoImport()
        {
            while (photo_scan_running)
            {
                Thread.Sleep(1000);  // FIXME: we can do this with a better primitive!
            }

            FireEvent(ImportEvent.ImportStarted);
            App.Instance.Database.Sync = false;
            created_directories        = new Stack <SafeUri> ();
            imported_photos            = new List <uint> ();
            copied_files      = new List <SafeUri> ();
            original_files    = new List <SafeUri> ();
            metadata_importer = new MetadataImporter();
            CreatedRoll       = rolls.Create();

            EnsureDirectory(Global.PhotoUri);

            try {
                int i     = 0;
                int total = Photos.Count;
                foreach (var info in Photos.Items)
                {
                    if (import_cancelled)
                    {
                        RollbackImport();
                        return;
                    }

                    ThreadAssist.ProxyToMain(() => ReportProgress(i++, total));
                    try {
                        ImportPhoto(info, CreatedRoll);
                    } catch (Exception e) {
                        Log.DebugFormat("Failed to import {0}", info.DefaultVersion.Uri);
                        Log.DebugException(e);
                        FailedImports.Add(info.DefaultVersion.Uri);
                    }
                }

                PhotosImported = imported_photos.Count;
                FinishImport();
            } catch (Exception e) {
                RollbackImport();
                throw e;
            } finally {
                Cleanup();
            }
        }
Esempio n. 2
0
        public void DoImport(IDb db, IBrowsableCollection photos, IList <Tag> tagsToAttach, bool duplicateDetect,
                             bool copyFiles, bool removeOriginals, Action <int, int> reportProgress, CancellationToken token)
        {
            db.Sync             = false;
            created_directories = new Stack <SafeUri> ();
            imported_photos     = new List <uint> ();
            photo_file_tracker  = new PhotoFileTracker(fileSystem);
            metadata_importer   = new MetadataImporter(db.Tags);

            createdRoll = db.Rolls.Create();

            fileSystem.Directory.CreateDirectory(Global.PhotoUri);

            try {
                int i     = 0;
                int total = photos.Count;
                foreach (var info in photos.Items)
                {
                    if (token.IsCancellationRequested)
                    {
                        RollbackImport(db);
                        return;
                    }

                    reportProgress(i++, total);
                    try {
                        ImportPhoto(db, info, createdRoll, tagsToAttach, duplicateDetect, copyFiles);
                    } catch (Exception e) {
                        Log.DebugFormat("Failed to import {0}", info.DefaultVersion.Uri);
                        Log.DebugException(e);
                        failedImports.Add(info.DefaultVersion.Uri);
                    }
                }

                FinishImport(removeOriginals);
            } catch (Exception e) {
                RollbackImport(db);
                throw e;
            } finally {
                Cleanup(db);
            }
        }
Esempio n. 3
0
        void DoImport()
        {
            while (photo_scan_running) {
                Thread.Sleep (1000); // FIXME: we can do this with a better primitive!
            }

            FireEvent (ImportEvent.ImportStarted);
            App.Instance.Database.Sync = false;
            created_directories = new Stack<SafeUri> ();
            imported_photos = new List<uint> ();
            copied_files = new List<SafeUri> ();
            original_files = new List<SafeUri> ();
            metadata_importer = new MetadataImporter ();
            CreatedRoll = rolls.Create ();

            EnsureDirectory (Global.PhotoUri);

            try {
                int i = 0;
                int total = Photos.Count;
                foreach (var info in Photos.Items) {
                    if (import_cancelled) {
                        RollbackImport ();
                        return;
                    }

                    ThreadAssist.ProxyToMain (() => ReportProgress (i++, total));
                    try {
                        ImportPhoto (info, CreatedRoll);
                    } catch (Exception e) {
                        Log.DebugFormat ("Failed to import {0}", info.DefaultVersion.Uri);
                        Log.DebugException (e);
                        FailedImports.Add (info.DefaultVersion.Uri);
                    }
                }

                PhotosImported = imported_photos.Count;
                FinishImport ();
            } catch (Exception e) {
                RollbackImport ();
                throw e;
            } finally {
                Cleanup ();
            }
        }