示例#1
0
    public void Init(string path, bool create_if_missing)
    {
        bool new_db = !File.Exists(path);

        this.path = path;

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

        database = new QueuedSqliteDatabase(path);

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

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

        Database.BeginTransaction();

        face_store   = new FaceStore(Database, new_db);
        tag_store    = new TagStore(Database, new_db);
        roll_store   = new RollStore(Database, new_db);
        export_store = new ExportStore(Database, new_db);
        job_store    = new JobStore(Database, new_db);
        photo_store  = new PhotoStore(Database, new_db);

        Database.CommitTransaction();

        empty = new_db;
    }
示例#2
0
        public void DetectNewFiles_Twice_NewPhotosOnFirstCall()
        {
            _photoStore = new PhotoStore(new PhotoRepo(forceNew: true), _localFileFolder, _locationService);

            _tripCreationService = new TripCreationService(_tripStore, _photoStore, _locationService);

            var result = _tripCreationService.TripCreationDetectResult;

            Assert.IsTrue(result.NumNewPhotos == 0);

            Assert.IsTrue(result.State.TaskState == BuildTaskState.Idle);

            result = _tripCreationService.BuildPhotos();

            Assert.IsTrue(result.NumNewPhotos > 0);
            Assert.IsTrue(result.State.TaskState == BuildTaskState.Running);

            _tripCreationService.Stop();
            _tripCreationService.RejectAll();

            result = _tripCreationService.TripCreationDetectResult;

            Assert.IsTrue(result.State.TaskState == BuildTaskState.Stopped);
            Assert.IsTrue(result.NumNewPhotos > 0);

            // second time
            _tripCreationService = new TripCreationService(_tripStore, _photoStore, _locationService);

            var result2 = _tripCreationService.BuildPhotos();

            Assert.IsTrue(result2.NumNewPhotos == 0);
        }
        private async Task IsDeleted(Guid profileId, IIdentity identity)
        {
            var accountReference = new Account(identity.Name);
            var storageAccount   = CloudStorageAccount.Parse(Config.AzureConnectionString);
            var operation        = TableOperation.Retrieve <AccountAdapter>(accountReference.Provider, accountReference.Subject);

            var client = storageAccount.CreateCloudTableClient();
            var table  = client.GetTableReference("Accounts");

            var accountResult = await table.ExecuteAsync(operation).ConfigureAwait(false);

            accountResult.HttpStatusCode.Should().Be(404);

            var profileStore = new ProfileStore(Config.Storage);

            var storedProfile = await profileStore.GetProfile(profileId, CancellationToken.None).ConfigureAwait(false);

            storedProfile.Should().BeNull();

            var photoStore = new PhotoStore(Config.Storage);

            var storedPhotos = await photoStore.GetPhotos(profileId, CancellationToken.None).ConfigureAwait(false);

            storedPhotos.Should().BeEmpty();
        }
示例#4
0
        public async Task GetPhotosReturnsMultipleProfilePhotoIdsTest()
        {
            var profileId = Guid.NewGuid();
            var expected  = new List <Guid>();

            var sut = new PhotoStore(Config.Storage);

            for (int index = 0; index < 10; index++)
            {
                var photo     = Model.Ignoring <Photo>(x => x.Data).Create <Photo>().Set(x => x.ProfileId = profileId).Set(x => x.ContentType = ".jpg");
                var photoData = Model.Create <byte[]>();

                using (var inputStream = new MemoryStream(photoData))
                {
                    photo.Data = inputStream;

                    var photoDetails = await sut.StorePhoto(photo, CancellationToken.None).ConfigureAwait(false);

                    expected.Add(photoDetails.Id);
                }
            }

            var actual = await sut.GetPhotos(profileId, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(expected);
        }
示例#5
0
 public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
 {
     foreach (Photo photo in photos)
     {
         new_parent.AddTag(photo.Tags);
         foreach (uint version_id in photo.VersionIds)
         {
             try {
                 new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion);
                 store.Commit(new_parent);
             } catch (Exception e) {
                 Console.WriteLine(e);
             }
         }
         uint [] version_ids = photo.VersionIds;
         Array.Reverse(version_ids);
         foreach (uint version_id in version_ids)
         {
             try {
                 photo.DeleteVersion(version_id, true, true);
             } catch (Exception e) {
                 Console.WriteLine(e);
             }
         }
         store.Commit(photo);
         MainWindow.Toplevel.Database.Photos.Remove(photo);
     }
     return(true);
 }
示例#6
0
 public DebugInfoViewModel(TripStore tripStore, PhotoStore photoStore, LocationService locationService) : base("Highlite")
 {
     _tripStore       = tripStore;
     _photoStore      = photoStore;
     _mainViewModel   = MainViewModel.Instance;
     _locationService = locationService;
 }
示例#7
0
    public void DeleteVersion(uint version_id, bool remove_original)
    {
        if (version_id == OriginalVersionId && !remove_original)
        {
            throw new Exception("Cannot delete original version");
        }

        string path = GetVersionPath(version_id);

        if (File.Exists(path))
        {
            File.Delete(path);
        }

        try {
            string thumb_path = ThumbnailGenerator.ThumbnailPath(path);
            File.Delete(thumb_path);
        } catch (System.Exception) {
            //ignore an error here we don't really care.
        }

        PhotoStore.DeleteThumbnail(path);

        version_names.Remove(version_id);

        do
        {
            version_id--;
            if (version_names.Contains(version_id))
            {
                DefaultVersionId = version_id;
                break;
            }
        } while (version_id > OriginalVersionId);
    }
示例#8
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            VersionNameRequest request = new VersionNameRequest(VersionNameRequest.RequestType.Create,
                                                                photo, parent_window);

            string       name;
            ResponseType response = request.Run(out name);

            if (response != ResponseType.Ok)
            {
                return(false);
            }

            try {
                photo.DefaultVersionId = photo.CreateVersion(name, photo.DefaultVersionId, true);
                store.Commit(photo);
            } catch (Exception e) {
                string msg  = Catalog.GetString("Could not create a new version");
                string desc = String.Format(Catalog.GetString("Received exception \"{0}\". Unable to create version \"{1}\""),
                                            e.Message, name);

                HigMessageDialog md = new HigMessageDialog(parent_window, DialogFlags.DestroyWithParent,
                                                           Gtk.MessageType.Error, ButtonsType.Ok,
                                                           msg,
                                                           desc);
                md.Run();
                md.Destroy();
                return(false);
            }

            return(true);
        }
示例#9
0
    public void RenameVersion(uint version_id, string new_name)
    {
        if (version_id == OriginalVersionId)
        {
            throw new Exception("Cannot rename original version");
        }

        if (VersionNameExists(new_name))
        {
            throw new Exception("This name already exists");
        }

        string original_name = version_names [version_id] as string;

        string old_path = GetPathForVersionName(original_name);
        string new_path = GetPathForVersionName(new_name);

        if (File.Exists(new_path))
        {
            throw new Exception("File with this name already exists");
        }

        File.Move(old_path, new_path);
        PhotoStore.MoveThumbnail(old_path, new_path);

        version_names [version_id] = new_name;
    }
示例#10
0
 public TripWizardNewTripViewModel(TripCreationService tripCreationService, PhotoStore photoStore,
                                   LocationService locationService) : base("TripWizard")
 {
     _tripCreationService = tripCreationService;
     _photoStore          = photoStore;
     _locationService     = locationService;
 }
示例#11
0
 public HighliteViewModel(PhotoStore photoStore, HighliteService highliteService) : base("Highlite")
 {
     _photoStore      = photoStore;
     _highliteService = highliteService;
     _mainViewModel   = MainViewModel.Instance;
     Load();
 }
示例#12
0
        public void DetectNewFiles_AfterNewTripsHaveBeenRejected_GotNone()
        {
            _photoStore = new PhotoStore(new PhotoRepo(forceNew: true), _localFileFolder, _locationService);

            _tripCreationService = new TripCreationService(_tripStore, _photoStore, _locationService);

            var result = _tripCreationService.Build();

            Assert.IsTrue(result.NumNewPhotos > 0);
            Assert.IsTrue(result.NumNewTrips > 0);
            Assert.IsTrue(result.NumNewDestinations > 0);
            Assert.IsTrue(result.NumNewTravelPhotos > 0);

            Assert.IsTrue(result.State.TaskState == BuildTaskState.Stopped);

            _tripCreationService.Stop();
            _tripCreationService.RejectAll();

            // second time
            _tripCreationService = new TripCreationService(_tripStore, _photoStore, _locationService);

            var result2 = _tripCreationService.BuildPhotos();

            Assert.IsTrue(result2.NumNewPhotos == 0);
        }
示例#13
0
        public async Task StorePhotoStoresNewPhotoTest()
        {
            var photo    = Model.Ignoring <Photo>(x => x.Data).Create <Photo>().Set(x => x.ContentType = ".jpg");
            var expected = Model.Create <byte[]>();

            var sut = new PhotoStore(Config.Storage);

            using (var inputStream = new MemoryStream(expected))
            {
                photo.Data = inputStream;

                var photoDetails = await sut.StorePhoto(photo, CancellationToken.None).ConfigureAwait(false);

                photoDetails.Should().BeEquivalentTo(photo, opt => opt.ExcludingMissingMembers().Excluding(x => x.Hash));
                photoDetails.Hash.Should().NotBeNullOrWhiteSpace();
                var retrievedPhoto = await sut.GetPhoto(photo.ProfileId, photo.Id, CancellationToken.None)
                                     .ConfigureAwait(false);

                retrievedPhoto.Should().BeEquivalentTo(photoDetails, opt => opt.ExcludingMissingMembers());

                using (var outputStream = retrievedPhoto.Data)
                {
                    outputStream.Position.Should().Be(0);
                    outputStream.Length.Should().Be(expected.Length);

                    var actual = new byte[expected.Length];

                    var length = outputStream.Read(actual, 0, expected.Length);

                    length.Should().Be(expected.Length);
                    expected.SequenceEqual(actual).Should().BeTrue();
                }
            }
        }
示例#14
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            VersionNameRequest request = new VersionNameRequest (VersionNameRequest.RequestType.Create,
                                         photo, parent_window);

            string name;
            ResponseType response = request.Run (out name);

            if (response != ResponseType.Ok)
                return false;

            try {
                photo.DefaultVersionId = photo.CreateVersion (name, photo.DefaultVersionId, true);
                store.Commit (photo);
            } catch (Exception e) {
                    string msg = Catalog.GetString ("Could not create a new version");
                    string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to create version \"{1}\""),
                                     e.Message, name);

                    HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent,
                                            Gtk.MessageType.Error, ButtonsType.Ok,
                                            msg,
                                            desc);
                    md.Run ();
                    md.Destroy ();
                    return false;
            }

            return true;
        }
示例#15
0
        private void OnPhotoUploaded(IPhoto item)
        {
            Debug.Assert(null != item);

            if (!model.AttachTags && !model.RemoveTags)
            {
                return;
            }

            PhotoStore photo_store = FSpot.App.Instance.Database.Photos;

            FSpot.Photo photo = photo_store.GetByUri(
                item.DefaultVersion.Uri);
            Debug.Assert(null != photo);
            if (null == photo)
            {
                return;
            }

            if (model.AttachTags)
            {
                photo.AddTag(model.AttachedTags);
            }
            if (model.RemoveTags)
            {
                photo.RemoveTag(model.RemovedTags);
            }
            photo_store.Commit(photo);
        }
示例#16
0
        public void StorePhotoThrowsExceptionWithNullPhotoTest()
        {
            var sut = new PhotoStore(Config.Storage);

            Func <Task> action = async() =>
                                 await sut.StorePhoto(null, CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentNullException>();
        }
示例#17
0
        public void GetPhotoThrowsExceptionWithEmptyProfileIdTest()
        {
            var sut = new PhotoStore(Config.Storage);

            Func <Task> action = async() =>
                                 await sut.GetPhoto(Guid.Empty, Guid.NewGuid(), CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentException>();
        }
示例#18
0
 public FileImportBackend(PhotoStore store, string [] base_paths, bool copy, bool recurse, Tag [] tags, Gtk.Window parent)
 {
     this.store      = store;
     this.copy       = copy;
     this.base_paths = base_paths;
     this.recurse    = recurse;
     this.tags       = tags;
     this.parent     = parent;
 }
    public int ImportFromPaths(PhotoStore store, string [] paths, Tag [] tags, bool copy)
    {
        collection = new FSpot.PhotoList(new Photo [0]);
        int count = DoImport(new FileImportBackend(store, paths, copy, true, tags, main_window));

        Finish();

        return(count);
    }
示例#20
0
 public FileImportBackend(PhotoStore store, string [] base_paths, bool copy, bool recurse, bool detect_duplicates, Tag [] tags, Gtk.Window parent)
 {
     this.store = store;
     this.copy = copy;
     this.base_paths = base_paths;
     this.recurse = recurse;
     this.detect_duplicates = detect_duplicates;
     this.tags = tags;
     this.parent = parent;
 }
示例#21
0
        public void Run()
        {
            var libraryDir = String.IsNullOrWhiteSpace(_libraryDir) ?
                             Directory.GetCurrentDirectory() :
                             _libraryDir;

            var outputDir = String.IsNullOrWhiteSpace(_outputDir) ?
                            Path.Combine(Directory.GetCurrentDirectory(), "Extracted Photos") :
                            _outputDir;

            var dbPath = Path.Combine(libraryDir, "iPhotoMain.db");

            if (!File.Exists(dbPath))
            {
                Console.WriteLine($"File '{dbPath}' not found.");
                return;
            }

            if (Directory.Exists(outputDir))
            {
                Console.Write($"Warning: directory '{outputDir}' already exists. Continue (y/n)? ");
                var response = Console.ReadLine().Trim().ToLower();

                if (response != "y" && response != "yes")
                {
                    return;
                }
            }

            Directory.CreateDirectory(outputDir);

            var          photoStore = new PhotoStore(dbPath);
            List <Photo> photos     = photoStore.GetAllPhotos();

            Dictionary <string, List <Photo> > albums = photos
                                                        .GroupBy(p => p.AlbumName)
                                                        .ToDictionary(g => g.Key, g => g.ToList());

            Console.WriteLine($"Found {albums.Keys.Count} albums.");
            var counter = 1;

            foreach (string album in albums.Keys)
            {
                var albumPhotos = albums[album];
                var s           = albumPhotos.Count == 1 ? "" : "s";

                Console.WriteLine($"[{counter}/{albums.Keys.Count}] Extracting album '{album}' " +
                                  $"({albumPhotos.Count} photo{s})...");

                ExtractAlbum(libraryDir, outputDir, album, albumPhotos);
                counter++;
            }

            Console.WriteLine("Done.");
        }
示例#22
0
        public XmpTagsImporter(PhotoStore photo_store, TagStore tag_store)
        {
            this.tag_store = tag_store;
            tags_created = new Stack<Tag> ();

            li_root_tag = new TagInfo (Catalog.GetString ("Imported Tags"), LastImportIcon);
            taginfo_table [(Entity)Location] = new TagInfo (Catalog.GetString ("Location"), PlacesIcon);
            taginfo_table [(Entity)Country] = new TagInfo (Catalog.GetString ("Country"), PlacesIcon);
            taginfo_table [(Entity)City] = new TagInfo (Catalog.GetString ("City"), PlacesIcon);
            taginfo_table [(Entity)State] = new TagInfo (Catalog.GetString ("State"), PlacesIcon);
        }
        public XmpTagsImporter(PhotoStore photo_store, TagStore tag_store)
        {
            this.tag_store = tag_store;
            tags_created   = new Stack();

            li_root_tag = new TagInfo(Catalog.GetString("Import Tags"), LastImportIcon);
            taginfo_table [(Entity)Location] = new TagInfo(Catalog.GetString("Location"), PlacesIcon);
            taginfo_table [(Entity)Country]  = new TagInfo(Catalog.GetString("Country"), PlacesIcon);
            taginfo_table [(Entity)City]     = new TagInfo(Catalog.GetString("City"), PlacesIcon);
            taginfo_table [(Entity)State]    = new TagInfo(Catalog.GetString("State"), PlacesIcon);
        }
示例#24
0
        public TripCreationService ConstructorTest(
            TripStore tripStore,
            PhotoStore photoStore,
            LocationService locationService
            )
        {
            TripCreationService target
                = new TripCreationService(tripStore, photoStore, locationService);

            return(target);
            // TODO: add assertions to method TripCreationServiceTest.ConstructorTest(TripStore, PhotoStore, LocationService)
        }
示例#25
0
        public LocationServiceTests()
        {
            _exifReader = new PictureExifInformationReader();

            _googleClient = new GoogleClient();
            _locationRepo = new LocationRepo(TripLineConfig.LocationRepoPath, forceNew: false);
            _placeRepo    = new PlaceRepo(TripLineConfig.PlaceRepoPath);

            _locationService = new LocationService(_googleClient, _locationRepo, _placeRepo);

            _localFileFolder = new LocalFileFolders(_exifReader);
            _photoStore      = new PhotoStore(new PhotoRepo(forceNew: false), _localFileFolder, _locationService);
        }
示例#26
0
 public AlbumViewModel(TripStore tripStore, PhotoStore photoStore, HighliteService highliteService, AlbumService albumService,
                       LocationService locationService, DebugInfoViewModel debugInfo) : base("Highlite")
 {
     _tripStore               = tripStore;
     _photoStore              = photoStore;
     _albumService            = albumService;
     _highliteService         = highliteService;
     _locationService         = locationService;
     _debugInfoVModel         = debugInfo;
     _mainViewModel           = MainViewModel.Instance;
     _mainViewModel.OnRemove += _mainViewModel_OnRemove;
     Load();
 }
示例#27
0
		public void CreateFromWithVersionIgnored()
		{
			var store = new PhotoStore (new FSpotDatabaseConnection (database), true);
			var photoMock = PhotoMock.CreateWithVersion (uri, originalName, modifiedUri, modifiedName);

			var photo = store.CreateFrom (photoMock, true, 1);

			Assert.AreEqual (Catalog.GetString ("Original"), photo.DefaultVersion.Name);
			Assert.AreEqual (uri, photo.DefaultVersion.BaseUri);
			// CreateFrom ignores any versions except the default version
			Assert.AreEqual (1, photo.Versions.Count ());

			Assert.AreEqual (1, store.TotalPhotos);
		}
示例#28
0
        public async Task DropEverythingAsync()
        {
            Settings.Current.UpdateDatabaseId();
            await TripStore.DropTable();

            await PhotoStore.DropTable();

            await UserStore.DropTable();

            await IOTHubStore.DropTable();

            IsInitialized = false;
            await InitializeAsync();
        }
示例#29
0
		public void CreateFrom()
		{
			var store = new PhotoStore (new FSpotDatabaseConnection (database), true);
			var photoMock = PhotoMock.Create (uri, originalName);

			var photo = store.CreateFrom (photoMock, true, 1);

			// default version name is ignored on import
			Assert.AreEqual (Catalog.GetString ("Original"), photo.DefaultVersion.Name);
			Assert.AreEqual (uri, photo.DefaultVersion.BaseUri);
			Assert.AreEqual (1, photo.Versions.Count ());

			Assert.AreEqual (1, store.TotalPhotos);
		}
示例#30
0
        public TripCreationServiceTests()
        {
            _googleClient = new GoogleClient();
            _locationRepo = new LocationRepo(TripLineConfig.LocationRepoPath, forceNew: true);
            _placeRepo    = new PlaceRepo(TripLineConfig.PlaceRepoPath);

            _locationService = new LocationService(_googleClient, _locationRepo, _placeRepo);

            _pictureExifReader = new PictureExifInformationReader();
            _localFileFolder   = new LocalFileFolders(_pictureExifReader);
            _photoStore        = new PhotoStore(new PhotoRepo(), _localFileFolder, _locationService);

            _tripSmartBuilder = new TripSmartBuilder(_locationService, _photoStore, new DestinationBuilder(_locationService));
            _tripStore        = new TripStore(_photoStore, _locationService, _tripSmartBuilder, new TripsRepo());
        }
示例#31
0
        public bool Execute(PhotoStore store, Photo[] photos, Photo new_parent, Gtk.Window parent_window)
        {
            string ok_caption = Strings.ReparentButton;
            string msg        = Catalog.GetPluralString(
                Strings.ReallyReparentXAsVersionOfYQuestion(new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__")),
                Strings.ReallyReparentXPhotosAsVersionOfYQuestion(new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__")),
                photos.Length);

            string desc = Strings.ThisMakesThePhotosAppearAsASingleOneInTheLibraryTheVersionsCanBeDetachedUsingThePhotoMenu;

            try {
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                                                           MessageType.Warning, msg, desc, ok_caption))
                {
                    uint   highest_rating  = new_parent.Rating;
                    string new_description = new_parent.Description;
                    foreach (var photo in photos)
                    {
                        highest_rating = Math.Max(photo.Rating, highest_rating);
                        if (string.IsNullOrEmpty(new_description))
                        {
                            new_description = photo.Description;
                        }
                        new_parent.AddTag(photo.Tags);

                        foreach (uint version_id in photo.VersionIds)
                        {
                            new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion);
                            store.Commit(new_parent);
                        }
                        uint[] version_ids = photo.VersionIds;
                        Array.Reverse(version_ids);
                        foreach (uint version_id in version_ids)
                        {
                            photo.DeleteVersion(version_id, true, true);
                        }
                        store.Remove(photo);
                    }
                    new_parent.Rating      = highest_rating;
                    new_parent.Description = new_description;
                    store.Commit(new_parent);
                    return(true);
                }
            } catch (Exception e) {
                HandleException("Could not reparent photos", e, parent_window);
            }
            return(false);
        }
        public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
        {
            string ok_caption = Catalog.GetString("Re_parent");
            string msg        = String.Format(Catalog.GetPluralString("Really reparent \"{0}\" as version of \"{1}\"?",
                                                                      "Really reparent {2} photos as versions of \"{1}\"?", photos.Length),
                                              new_parent.Name.Replace("_", "__"), photos[0].Name.Replace("_", "__"), photos.Length);
            string desc = Catalog.GetString("This makes the photos appear as a single one in the library. The versions can be detached using the Photo menu.");

            try {
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                                                           MessageType.Warning, msg, desc, ok_caption))
                {
                    uint   highest_rating  = new_parent.Rating;
                    string new_description = new_parent.Description;
                    foreach (Photo photo in photos)
                    {
                        highest_rating = Math.Max(photo.Rating, highest_rating);
                        if (string.IsNullOrEmpty(new_description))
                        {
                            new_description = photo.Description;
                        }
                        new_parent.AddTag(photo.Tags);

                        foreach (uint version_id in photo.VersionIds)
                        {
                            new_parent.DefaultVersionId = new_parent.CreateReparentedVersion(photo.GetVersion(version_id) as PhotoVersion);
                            store.Commit(new_parent);
                        }
                        uint [] version_ids = photo.VersionIds;
                        Array.Reverse(version_ids);
                        foreach (uint version_id in version_ids)
                        {
                            photo.DeleteVersion(version_id, true, true);
                        }
                        store.Remove(photo);
                    }
                    new_parent.Rating      = highest_rating;
                    new_parent.Description = new_description;
                    store.Commit(new_parent);
                    return(true);
                }
            }
            catch (Exception e) {
                HandleException("Could not reparent photos", e, parent_window);
            }
            return(false);
        }
示例#33
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            // FIXME HIG-ify.
            Dialog dialog = new Dialog();

            dialog.BorderWidth  = 6;
            dialog.TransientFor = parent_window;
            dialog.HasSeparator = false;
            dialog.Title        = Catalog.GetString("Really Delete?");
            dialog.AddButton(Catalog.GetString("Cancel"), (int)ResponseType.Cancel);
            dialog.AddButton(Catalog.GetString("Delete"), (int)ResponseType.Ok);
            dialog.DefaultResponse = ResponseType.Ok;

            string version_name = photo.GetVersionName(photo.DefaultVersionId);
            Label  label        = new Label(String.Format(Catalog.GetString("Really delete version \"{0}\"?"), version_name));

            label.Show();
            dialog.VBox.PackStart(label, false, true, 6);;

            if (dialog.Run() == (int)ResponseType.Ok)
            {
                try {
                    photo.DeleteVersion(photo.DefaultVersionId);
                    store.Commit(photo);
                } catch (Exception e) {
                    // FIXME show error dialog.
                    string msg  = Catalog.GetString("Could not delete a version");
                    string desc = String.Format(Catalog.GetString("Received exception \"{0}\". Unable to delete version \"{1}\""),
                                                e.Message, photo.Name);

                    HigMessageDialog md = new HigMessageDialog(parent_window, DialogFlags.DestroyWithParent,
                                                               Gtk.MessageType.Error, ButtonsType.Ok,
                                                               msg,
                                                               desc);
                    md.Run();
                    md.Destroy();
                    dialog.Destroy();                      // Delete confirmation window.
                    return(false);
                }

                dialog.Destroy();
                return(true);
            }

            dialog.Destroy();
            return(false);
        }
示例#34
0
        public async Task DeletePhotoReturnsSuccessfullyWhenContainerNotFoundTest()
        {
            // Retrieve storage account from connection-string
            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);

            // Create the client
            var client = storageAccount.CreateCloudBlobClient();

            var container = client.GetContainerReference("photos");

            await container.DeleteIfExistsAsync().ConfigureAwait(false);

            var sut = new PhotoStore(Config.Storage);

            // This should not throw an exception
            await sut.DeletePhoto(Guid.NewGuid(), Guid.NewGuid(), CancellationToken.None).ConfigureAwait(false);
        }
示例#35
0
        public async Task StorePhotoCreatesContainerWhenNotFoundTest()
        {
            // Retrieve storage account from connection-string
            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);

            // Create the client
            var client = storageAccount.CreateCloudBlobClient();

            var container = client.GetContainerReference("photos");

            await container.DeleteIfExistsAsync().ConfigureAwait(false);

            var photo    = Model.Ignoring <Photo>(x => x.Data).Create <Photo>().Set(x => x.ContentType = ".jpg");
            var expected = Model.Create <byte[]>();

            var sut = new PhotoStore(Config.Storage);

            using (var inputStream = new MemoryStream(expected))
            {
                photo.Data = inputStream;

                var photoDetails = await sut.StorePhoto(photo, CancellationToken.None).ConfigureAwait(false);

                photoDetails.Should().BeEquivalentTo(photo, opt => opt.ExcludingMissingMembers().Excluding(x => x.Hash));
                photoDetails.Hash.Should().NotBeNullOrWhiteSpace();

                var retrievedPhoto = await sut.GetPhoto(photo.ProfileId, photo.Id, CancellationToken.None)
                                     .ConfigureAwait(false);

                retrievedPhoto.Should().BeEquivalentTo(photoDetails, opt => opt.ExcludingMissingMembers());

                using (var outputStream = retrievedPhoto.Data)
                {
                    outputStream.Position.Should().Be(0);
                    outputStream.Length.Should().Be(expected.Length);

                    var actual = new byte[expected.Length];

                    var length = outputStream.Read(actual, 0, expected.Length);

                    length.Should().Be(expected.Length);
                    expected.SequenceEqual(actual).Should().BeTrue();
                }
            }
        }
示例#36
0
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            // FIXME HIG-ify.
            Dialog dialog = new Dialog ();
            dialog.BorderWidth = 6;
            dialog.TransientFor = parent_window;
            dialog.HasSeparator = false;
            dialog.Title = Catalog.GetString ("Really Delete?");
            dialog.AddButton (Catalog.GetString ("Cancel"), (int) ResponseType.Cancel);
            dialog.AddButton (Catalog.GetString ("Delete"), (int) ResponseType.Ok);
            dialog.DefaultResponse = ResponseType.Ok;

            string version_name = photo.GetVersion (photo.DefaultVersionId).Name;
            Label label = new Label (String.Format (Catalog.GetString ("Really delete version \"{0}\"?"), version_name));
            label.Show ();
            dialog.VBox.PackStart (label, false, true, 6);;

            if (dialog.Run () == (int) ResponseType.Ok) {
                try {
                    photo.DeleteVersion (photo.DefaultVersionId);
                    store.Commit (photo);
                } catch (Exception e) {
                    Log.DebugException (e);
                    string msg = Catalog.GetString ("Could not delete a version");
                    string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Unable to delete version \"{1}\""),
                                     e.Message, photo.Name);

                    HigMessageDialog md = new HigMessageDialog (parent_window, DialogFlags.DestroyWithParent,
                                            Gtk.MessageType.Error, ButtonsType.Ok,
                                            msg,
                                            desc);
                    md.Run ();
                    md.Destroy ();
                    dialog.Destroy (); // Delete confirmation window.
                    return false;
                }

                dialog.Destroy ();
                return true;
            }

            dialog.Destroy ();
            return false;
        }
        public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
        {
            VersionNameRequest request = new VersionNameRequest (VersionNameRequest.RequestType.Create,
                                         photo, parent_window);

            string name;
            ResponseType response = request.Run (out name);

            if (response != ResponseType.Ok)
                return false;

            try {
                photo.DefaultVersionId = photo.CreateVersion (name, photo.DefaultVersionId, true);
                store.Commit (photo);
                return true;
            } catch (Exception e) {
                HandleException ("Could not create a new version", e, parent_window);
                return false;
            }
        }
示例#38
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}");
        }
示例#39
0
 public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
 {
     foreach (Photo photo in photos) {
         new_parent.AddTag (photo.Tags);
         foreach (uint version_id in photo.VersionIds) {
             try {
                 new_parent.DefaultVersionId = new_parent.CreateReparentedVersion (photo.GetVersion (version_id) as PhotoVersion);
                 store.Commit (new_parent);
             } catch (Exception e) {
                 Log.DebugException (e);
             }
         }
         uint [] version_ids = photo.VersionIds;
         Array.Reverse (version_ids);
         foreach (uint version_id in version_ids) {
             try {
                 photo.DeleteVersion (version_id, true, true);
             } catch (Exception e) {
                 Log.DebugException (e);
             }
         }
         MainWindow.Toplevel.Database.Photos.Remove (photo);
     }
     return true;
 }
	public int ImportFromPaths (PhotoStore store, string [] paths, Tag [] tags, bool copy)
	{
		collection = new FSpot.PhotoList (new Photo [0]);
		int count = DoImport (new FileImportBackend (store, paths, copy, true, tags, main_window ));

		Finish ();

		return count;
	}
	public int ImportFromPaths (PhotoStore store, string [] paths, Tag [] tags)
	{
		return ImportFromPaths (store, paths, tags, false);
	}
示例#42
0
	public void Init (string path, bool create_if_missing)
	{
		bool new_db = ! File.Exists (path);
		this.path = path;

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

		database = new QueuedSqliteDatabase(path);	

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

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

		Database.BeginTransaction ();
		
		face_store = new FaceStore (Database, new_db);
		tag_store = new TagStore (Database, new_db);
		roll_store = new RollStore (Database, new_db);
		export_store = new ExportStore (Database, new_db);
		job_store = new JobStore (Database, new_db);
 		photo_store = new PhotoStore (Database, new_db);
		
		Database.CommitTransaction ();

		empty = new_db;
	}
        public bool Execute(PhotoStore store, Photo [] photos, Photo new_parent, Gtk.Window parent_window)
        {
            string ok_caption = Catalog.GetString ("Re_parent");
            string msg = String.Format (Catalog.GetPluralString ("Really reparent \"{0}\" as version of \"{1}\"?",
                                                                 "Really reparent {2} photos as versions of \"{1}\"?", photos.Length),
                                        new_parent.Name.Replace ("_", "__"), photos[0].Name.Replace ("_", "__"), photos.Length);
            string desc = Catalog.GetString ("This makes the photos appear as a single one in the library. The versions can be detached using the Photo menu.");

            try {
                if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                       MessageType.Warning, msg, desc, ok_caption)) {
                    uint highest_rating = new_parent.Rating;
                    string new_description = new_parent.Description;
                    foreach (Photo photo in photos) {
                        highest_rating = Math.Max(photo.Rating, highest_rating);
                        if (string.IsNullOrEmpty(new_description))
                            new_description = photo.Description;
                        new_parent.AddTag (photo.Tags);

                        foreach (uint version_id in photo.VersionIds) {
                            new_parent.DefaultVersionId = new_parent.CreateReparentedVersion (photo.GetVersion (version_id) as PhotoVersion);
                            store.Commit (new_parent);
                        }
                        uint [] version_ids = photo.VersionIds;
                        Array.Reverse (version_ids);
                        foreach (uint version_id in version_ids) {
                            photo.DeleteVersion (version_id, true, true);
                        }
                        store.Remove (photo);
                    }
                    new_parent.Rating = highest_rating;
                    new_parent.Description = new_description;
                    store.Commit (new_parent);
                    return true;
                }
            }
            catch (Exception e) {
                HandleException ("Could not reparent photos", e, parent_window);
            }
            return false;
        }
 public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
 {
     string ok_caption = Catalog.GetString ("De_tach");
     string msg = String.Format (Catalog.GetString ("Really detach version \"{0}\" from \"{1}\"?"), photo.DefaultVersion.Name, photo.Name.Replace("_", "__"));
     string desc = Catalog.GetString ("This makes the version appear as a separate photo in the library. To undo, drag the new photo back to its parent.");
     try {
         if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                MessageType.Warning, msg, desc, ok_caption)) {
             Photo new_photo = store.CreateFrom (photo, photo.RollId);
             new_photo.CopyAttributesFrom (photo);
             photo.DeleteVersion (photo.DefaultVersionId, false, true);
             store.Commit (new Photo[] {new_photo, photo});
             return true;
         }
     } catch (Exception e) {
         HandleException ("Could not detach a version", e, parent_window);
     }
     return false;
 }
 public bool Execute(PhotoStore store, Photo photo, Gtk.Window parent_window)
 {
     string ok_caption = Catalog.GetString ("Delete");
     string msg = String.Format (Catalog.GetString ("Really delete version \"{0}\"?"), photo.DefaultVersion.Name);
     string desc = Catalog.GetString ("This removes the version and deletes the corresponding file from disk.");
     try {
         if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation(parent_window, DialogFlags.DestroyWithParent,
                                MessageType.Warning, msg, desc, ok_caption)) {
             photo.DeleteVersion (photo.DefaultVersionId);
             store.Commit (photo);
             return true;
         }
     } catch (Exception e) {
         HandleException ("Could not delete a version", e, parent_window);
     }
     return false;
 }
示例#46
0
		public void CreateFromWithVersionAdded()
		{
			var store = new PhotoStore (new FSpotDatabaseConnection (database), true);
			var photoMock = PhotoMock.CreateWithVersion (uri, originalName, modifiedUri, modifiedName);

			var photo = store.CreateFrom (photoMock, false, 1);

			Assert.AreEqual (modifiedName, photo.DefaultVersion.Name);
			Assert.AreEqual (modifiedUri, photo.DefaultVersion.BaseUri);
			Assert.AreEqual (2, photo.Versions.Count ());
			// version id 1 is the first photo added - the original photo
			Assert.AreEqual (originalName, photo.GetVersion(1).Name);
			Assert.AreEqual (uri, photo.GetVersion(1).BaseUri);

			Assert.AreEqual (1, store.TotalPhotos);
		}
	public FileImportBackend (PhotoStore store, string [] base_paths, bool recurse, Gtk.Window parent) : this (store, base_paths, false, recurse, null, parent) {}
	public int ImportFromFile (PhotoStore store, string path)
	{
		this.store = store;
		this.CreateDialog ("import_dialog");
		
		this.Dialog.TransientFor = main_window;
		this.Dialog.WindowPosition = Gtk.WindowPosition.CenterOnParent;
		this.Dialog.Response += HandleDialogResponse;

	        AllowFinish = false;
		
		this.Dialog.DefaultResponse = ResponseType.Ok;
		
		//import_folder_entry.Activated += HandleEntryActivate;
		recurse_check.Toggled += HandleRecurseToggled;
		copy_check.Toggled += HandleRecurseToggled;

		menu = new SourceMenu (this);
		source_option_menu.Menu = menu;

		collection = new FSpot.PhotoList (new Photo [0]);
		tray = new FSpot.ScalingIconView (collection);
		tray.Selection.Changed += HandleTraySelectionChanged;
		icon_scrolled.SetSizeRequest (200, 200);
		icon_scrolled.Add (tray);
		//icon_scrolled.Visible = false;
		tray.DisplayTags = false;
		tray.Show ();

		photo_view = new FSpot.PhotoImageView (collection);
		photo_scrolled.Add (photo_view);
		photo_scrolled.SetSizeRequest (200, 200);
		photo_view.Show ();

		//FSpot.Global.ModifyColors (frame_eventbox);
		FSpot.Global.ModifyColors (photo_scrolled);
		FSpot.Global.ModifyColors (photo_view);

		photo_view.Pixbuf = PixbufUtils.LoadFromAssembly ("f-spot-48.png");
		photo_view.Fit = true;
			
		tag_entry = new FSpot.Widgets.TagEntry (MainWindow.Toplevel.Database.Tags, false);
		tag_entry.UpdateFromTagNames (new string []{});
		tagentry_box.Add (tag_entry);

		tag_entry.Show ();

		this.Dialog.Show ();
		//source_option_menu.Changed += HandleSourceChanged;
		if (path != null) {
			SetImportPath (path);
			int i = menu.FindItemPosition (path);

			if (i > 0) {
				source_option_menu.SetHistory ((uint)i);
			} else if (Directory.Exists (path)) {
				SourceItem path_item = new SourceItem (new VfsSource (path));
				menu.Prepend (path_item);
				path_item.ShowAll ();
				SetImportPath (path);
				source_option_menu.SetHistory (0);
			} 
			idle_start.Start ();
		}
						
		ResponseType response = (ResponseType) this.Dialog.Run ();
		
		while (response == ResponseType.Ok) {
			try {
				if (Directory.Exists (this.ImportPath))
					break;
			} catch (System.Exception e){
				System.Console.WriteLine (e);
				break;
			}

			HigMessageDialog md = new HigMessageDialog (this.Dialog,
			        DialogFlags.DestroyWithParent,
				MessageType.Error,
				ButtonsType.Ok,
				Catalog.GetString ("Directory does not exist."),
				String.Format (Catalog.GetString ("The directory you selected \"{0}\" does not exist.  " + 
								  "Please choose a different directory"), this.ImportPath));

			md.Run ();
			md.Destroy ();

			response = (Gtk.ResponseType) this.Dialog.Run ();
		}

		if (response == ResponseType.Ok) {
			this.UpdateTagStore (tag_entry.GetTypedTagNames ());
			this.Finish ();

			if (tags_selected != null && tags_selected.Count > 0) {
				for (int i = 0; i < collection.Count; i++) {
					Photo p = collection [i] as Photo;
					
					if (p == null)
						continue;
					
					p.AddTag ((Tag [])tags_selected.ToArray(typeof(Tag)));
					store.Commit (p);
				}
			}

			this.Dialog.Destroy ();
			return collection.Count;
		} else {
			this.Cancel ();
			//this.Dialog.Destroy();
			return 0;
		}
	}
	public int ImportFromPaths (PhotoStore store, string [] paths, bool copy)
	{
		return ImportFromPaths (store, paths, null, copy);
	}
示例#50
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 QueuedSqliteDatabase(path);
		database.ExceptionThrown += HandleDbException;

		if (database.GetFileVersion(path) == 2)
			SqliteUpgrade ();

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

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

		Database.BeginTransaction ();

		tag_store = new TagStore (Database, new_db);
		roll_store = new RollStore (Database, new_db);
		export_store = new ExportStore (Database, new_db);
		job_store = new JobStore (Database, new_db);
 		photo_store = new PhotoStore (Database, new_db);

		Database.CommitTransaction ();

		empty = new_db;
		Log.DebugTimerPrint (timer, "Db Initialization took {0}");
	}
		// Constructor
		public PhotoQuery (PhotoStore store)
		{
			this.store = store;
			photos = store.Query ((Tag [])null, null, range, roll_set);
		}