Example #1
0
File: Photo.cs Project: ishui/rms
 internal Photo(SessionToken token, string name, string virtualPath, DateTime dateTaken, long filesize) : base(token)
 {
     this.beDeleted   = false;
     this.name        = name;
     this.virtualPath = virtualPath;
     this.dateTaken   = dateTaken;
     this.filesize    = filesize;
     ThumbnailUtilities.CreateThumbnail(token.MapPath(this.FullVirtualPath));
 }
Example #2
0
        public static Photos GetPhotos(SessionToken token, PhotoDirectory obj)
        {
            PhotoDB odb     = new PhotoDB(token.DBConnection);
            Photos  photos  = odb.GetPhotos(token, obj);
            Photos  photos2 = (Photos)photos.Clone();

            FileInfo[] files = new DirectoryInfo(token.MapPath(obj.FullVirtualPath)).GetFiles("*.*");
            if (photos.Count != files.Length)
            {
                foreach (FileInfo info2 in files)
                {
                    string fullVirtualPath = GetVirtualPath(token, info2.FullName);
                    if (!photos.Contains(fullVirtualPath))
                    {
                        string   virtualPath = fullVirtualPath.Substring(0, (fullVirtualPath.Length - info2.Name.Length) - 1);
                        DateTime dateTaken   = DateTime.MinValue;
                        try
                        {
                            using (Image image = Image.FromFile(info2.FullName))
                            {
                                try
                                {
                                    dateTaken = ParseExifDateTime(image.GetPropertyItem(0x9003).Value);
                                }
                                catch (ArgumentException)
                                {
                                }
                            }
                            Photo photo = new Photo(token, info2.Name, virtualPath, dateTaken, info2.Length);
                            odb.Insert(obj, photo);
                            photos.Add(photo);
                        }
                        catch
                        {
                        }
                    }
                    photos2.Remove(fullVirtualPath);
                }
                foreach (Photo photo in photos2)
                {
                    ThumbnailUtilities.DeleteThumbnail(token.MapPath(photo.FullThumbnailVirtualPath));
                    odb.Delete(photo);
                    photos.Remove(photo);
                }
            }
            return(photos);
        }
Example #3
0
        /// <summary>
        /// Returns the details of the photos contained within a directory.
        /// </summary>
        /// <param name="token">A reference to the current session token object.</param>
        /// <param name="obj">The directory whos photos we want to retrieve.</param>
        /// <returns>A collection of Photo objects.</returns>
        public static Photos GetPhotos(SessionToken token, PhotoDirectory obj)
        {
            PhotoDB db = new PhotoDB(token.DBConnection);

            Photos results = db.GetPhotos(token, obj);

            Photos originalResults = (Photos)results.Clone();

            // Get a list of directories from the root path from the file system
            DirectoryInfo dirInfo = new DirectoryInfo(token.MapPath(obj.FullVirtualPath));

            FileInfo[] fileInfos = dirInfo.GetFiles("*.jpg");

            // Only need to update the database if the number of files in the database are
            // different to those on the file system.
            // TODO: Currently won't detect changes in file names. Ideas to enable this
            //       and still be fast?
            if (results.Count != fileInfos.Length)
            {
                foreach (FileInfo file in fileInfos)
                {
                    string virtualPath = GetVirtualPath(token, file.FullName);

                    // Do we have a Photo for this directory already? If not then we need to
                    // add it to the database
                    if (!results.Contains(virtualPath))
                    {
                        string dirVirtualPath = virtualPath.Substring(0, virtualPath.Length - file.Name.Length - 1);

                        DateTime dateTaken = DateTime.MinValue;
                        using (Image image = Image.FromFile(file.FullName))
                        {
                            try
                            {
                                PropertyItem date = image.GetPropertyItem((int)KnownEXIFIDCodes.DateTimeOriginal);
                                dateTaken = ParseExifDateTime(date.Value);
                            }
                            catch (ArgumentException)
                            {
                                // image does not have a date value
                            }
                        }
                        Photo photo = new Photo(token, file.Name, dirVirtualPath, dateTaken, file.Length);

                        // insert this fire into the database
                        db.Insert(obj, photo);

                        results.Add(photo);
                    }

                    originalResults.Remove(virtualPath);
                }

                // Are there any Photo objects in the original result set that aren't in
                // the list of files from the file system? If so, delete 'em
                foreach (Photo photo in originalResults)
                {
                    // Delete the associated thumbnail
                    ThumbnailUtilities.DeleteThumbnail(token.MapPath(photo.FullThumbnailVirtualPath));

                    db.Delete(photo);
                    results.Remove(photo);
                }
            }

            return(results);
        }