internal static bool IsJpegRawPair(SafeUri file1, SafeUri file2) { return(file1.GetBaseUri().ToString() == file2.GetBaseUri().ToString() && file1.GetFilenameWithoutExtension() == file2.GetFilenameWithoutExtension() && ((ImageFile.IsJpeg(file1) && ImageFile.IsRaw(file2)) || (ImageFile.IsRaw(file1) && ImageFile.IsJpeg(file2)))); }
public void TestFileUris() { foreach (var test in tests) { var suri = new SafeUri(test.Uri); Assert.AreEqual(suri.AbsoluteUri, test.AbsoluteUri, String.Format("AbsoluteUri for {0}", test.Uri)); Assert.AreEqual(suri.GetExtension(), test.Extension, String.Format("Extension for {0}", test.Uri)); Assert.AreEqual(suri.GetBaseUri().ToString(), test.BaseUri, String.Format("BaseUri for {0}", test.Uri)); Assert.AreEqual(suri.GetFilename(), test.Filename, String.Format("Filename for {0}", test.Uri)); Assert.AreEqual(suri.GetFilenameWithoutExtension(), test.FilenameWithoutExtension, String.Format("FilenameWithoutExtension for {0}", test.Uri)); } }
SafeUri GetUniqueFilename(SafeUri dest) { // Find an unused name int i = 1; var base_uri = dest.GetBaseUri(); var filename = dest.GetFilenameWithoutExtension(); var extension = dest.GetExtension(); while (file_system.File.Exists(dest)) { dest = base_uri.Append(String.Format("{0}-{1}{2}", filename, i++, extension)); } return(dest); }
public Photo GetByUri(SafeUri uri) { Photo photo = null; var base_uri = uri.GetBaseUri(); var filename = uri.GetFilename(); Hyena.Data.Sqlite.IDataReader reader = Database.Query(new HyenaSqliteCommand("SELECT id, time, description, roll_id, default_version_id, rating " + " FROM photos " + " LEFT JOIN photo_versions AS pv ON photos.id = pv.photo_id" + " WHERE (photos.base_uri = ? AND photos.filename = ?)" + " OR (pv.base_uri = ? AND pv.filename = ?)", base_uri.ToString(), filename, base_uri.ToString(), filename)); if (reader.Read()) { photo = new Photo(Convert.ToUInt32(reader ["id"]), Convert.ToInt64(reader ["time"])); photo.Description = reader["description"].ToString(); photo.RollId = Convert.ToUInt32(reader["roll_id"]); photo.DefaultVersionId = Convert.ToUInt32(reader["default_version_id"]); photo.Rating = Convert.ToUInt32(reader ["rating"]); } reader.Dispose(); if (photo == null) { return(null); } Photo cached = LookupInCache(photo.Id); if (cached != null) { return(cached); } AddToCache(photo); GetTags(photo); GetVersions(photo); return(photo); }
public Photo [] Query(SafeUri uri) { string filename = uri.GetFilename(); /* query by file */ if (!String.IsNullOrEmpty(filename)) { return(Query(new HyenaSqliteCommand( "SELECT id, " + "time, " + "base_uri, " + "filename, " + "description, " + "roll_id, " + "default_version_id, " + "rating " + "FROM photos " + "WHERE base_uri LIKE ?" + "AND filename LIKE ?", uri.GetBaseUri().ToString(), filename))); } /* query by directory */ return(Query(new HyenaSqliteCommand( "SELECT id, " + "time, " + "base_uri, " + "filename, " + "description, " + "roll_id, " + "default_version_id, " + "rating " + "FROM photos " + "WHERE base_uri LIKE ?" + "AND base_uri NOT LIKE ?", uri + "%", uri + "/%/%"))); }
public static SafeUri ReplaceExtension(this SafeUri uri, string extension) { return(uri.GetBaseUri().Append(uri.GetFilenameWithoutExtension() + extension)); }