예제 #1
0
        public void InitialListsAreEmpty()
        {
            var tracker = new PhotoFileTracker(null);

            Assert.AreEqual(0, tracker.OriginalFiles.Count());
            Assert.AreEqual(0, tracker.CopiedFiles.Count());
        }
예제 #2
0
		public void InitialListsAreEmpty ()
		{
			var tracker = new PhotoFileTracker (null);

			Assert.AreEqual (0, tracker.OriginalFiles.Count ());
			Assert.AreEqual (0, tracker.CopiedFiles.Count ());
		}
예제 #3
0
		public void CopyNewFile ()
		{
			var photo = PhotoMock.Create (sourceUri);
			var fileSystem = new FileSystemMock ();
			var tracker = new PhotoFileTracker (fileSystem);

			tracker.CopyIfNeeded (photo, targetBase);

			CollectionAssert.AreEquivalent (new[]{ sourceUri }, tracker.OriginalFiles);
			CollectionAssert.AreEquivalent (new[]{ targetUri }, tracker.CopiedFiles);
			Assert.AreEqual (targetUri, photo.DefaultVersion.Uri);
			fileSystem.FileMock.Verify (f => f.Copy (sourceUri, targetUri, false), Times.Once);
		}
예제 #4
0
		public void DontCopyIfSourceIsTargetFile ()
		{
			var photo = PhotoMock.Create (targetUri);
			var fileSystem = new FileSystemMock ();
			var tracker = new PhotoFileTracker (fileSystem);

			tracker.CopyIfNeeded (photo, targetBase);

			Assert.AreEqual (0, tracker.OriginalFiles.Count ());
			Assert.AreEqual (0, tracker.CopiedFiles.Count ());
			Assert.AreEqual (targetUri, photo.DefaultVersion.Uri);
			fileSystem.FileMock.Verify (f => f.Copy (It. IsAny<SafeUri> (), It.IsAny<SafeUri> (), It.IsAny<bool> ()), Times.Never);
		}
예제 #5
0
        public void CopyNewFile()
        {
            var photo      = PhotoMock.Create(sourceUri);
            var fileSystem = new FileSystemMock();
            var tracker    = new PhotoFileTracker(fileSystem);

            tracker.CopyIfNeeded(photo, targetBase);

            CollectionAssert.AreEquivalent(new[] { sourceUri }, tracker.OriginalFiles);
            CollectionAssert.AreEquivalent(new[] { targetUri }, tracker.CopiedFiles);
            Assert.AreEqual(targetUri, photo.DefaultVersion.Uri);
            fileSystem.FileMock.Verify(f => f.Copy(sourceUri, targetUri, false), Times.Once);
        }
예제 #6
0
        public void DontCopyIfSourceIsTargetFile()
        {
            var photo      = PhotoMock.Create(targetUri);
            var fileSystem = new FileSystemMock();
            var tracker    = new PhotoFileTracker(fileSystem);

            tracker.CopyIfNeeded(photo, targetBase);

            Assert.AreEqual(0, tracker.OriginalFiles.Count());
            Assert.AreEqual(0, tracker.CopiedFiles.Count());
            Assert.AreEqual(targetUri, photo.DefaultVersion.Uri);
            fileSystem.FileMock.Verify(f => f.Copy(It.IsAny <SafeUri> (), It.IsAny <SafeUri> (), It.IsAny <bool> ()), Times.Never);
        }
예제 #7
0
        public void PhotoWithVersionsAndXmpIsCopied()
        {
            var photo      = PhotoMock.Create(sourceUri, rawUri);
            var fileSystem = new FileSystemMock(xmpSourceUri);
            var tracker    = new PhotoFileTracker(fileSystem);

            tracker.CopyIfNeeded(photo, targetBase);

            CollectionAssert.AreEquivalent(new[] { sourceUri, rawUri, xmpSourceUri }, tracker.OriginalFiles);
            CollectionAssert.AreEquivalent(new[] { targetUri, targetRawUri, xmpTargetUri }, tracker.CopiedFiles);
            Assert.AreEqual(targetUri, photo.DefaultVersion.Uri);
            Assert.AreEqual(targetRawUri, photo.Versions.ElementAt(1).Uri);
            fileSystem.FileMock.Verify(f => f.Copy(sourceUri, targetUri, false), Times.Once);
            fileSystem.FileMock.Verify(f => f.Copy(rawUri, targetRawUri, false), Times.Once);
            fileSystem.FileMock.Verify(f => f.Copy(xmpSourceUri, xmpTargetUri, true), Times.Once);
        }
예제 #8
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> ();
            photo_file_tracker         = new PhotoFileTracker(file_system);
            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();
            }
        }
예제 #9
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);
            }
        }
예제 #10
0
		public void FilesAreRenamedToNextFreeIndex ()
		{
			var photo = PhotoMock.Create (sourceUri, rawUri);
			var fileSystem = new FileSystemMock (
				xmpSourceUri,
				targetUri, targetUri1,
				targetRawUri, targetRawUri1, targetRawUri2, targetRawUri4);
			var tracker = new PhotoFileTracker (fileSystem);

			tracker.CopyIfNeeded (photo, targetBase);

			CollectionAssert.AreEquivalent (new[]{ sourceUri, rawUri, xmpSourceUri }, tracker.OriginalFiles);
			CollectionAssert.AreEquivalent (new[]{ targetUri2, targetRawUri3, xmpTargetUri2 }, tracker.CopiedFiles);
			Assert.AreEqual (targetUri2, photo.DefaultVersion.Uri);
			Assert.AreEqual (targetRawUri3, photo.Versions.ElementAt(1).Uri);
			fileSystem.FileMock.Verify (f => f.Copy (sourceUri, targetUri2, false), Times.Once);
			fileSystem.FileMock.Verify (f => f.Copy (rawUri, targetRawUri3, false), Times.Once);
			fileSystem.FileMock.Verify (f => f.Copy (xmpSourceUri, xmpTargetUri2, true), Times.Once);
		}
예제 #11
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> ();
			photo_file_tracker = new PhotoFileTracker (file_system);
			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 ();
			}
		}