Beispiel #1
0
 /// <summary>
 /// Extracts and caches the metadata for an image.
 /// </summary>
 /// <param name="pictureFileInfo">The FileInfo to the image.</param>
 /// <returns>The MetaData for the image.</returns>
 internal static Metadata GetImageData(FileInfo pictureFileInfo)
 {
     try
     {
         string cacheKey = "data(" + pictureFileInfo.FullName + ")";
         Cache  cache    = HttpContext.Current.Cache;
         object cached   = cache[cacheKey];
         if (cached == null)
         {
             Metadata   data = new Metadata();
             ExifReader exif = new ExifReader(pictureFileInfo);
             exif.Extract(data);
             IptcReader iptc = new IptcReader(pictureFileInfo);
             iptc.Extract(data);
             JpegReader jpeg = new JpegReader(pictureFileInfo);
             jpeg.Extract(data);
             cache.Insert(cacheKey, data, new CacheDependency(pictureFileInfo.FullName));
             return(data);
         }
         return((Metadata)cached);
     }
     catch
     {
         return(new Metadata());
     }
 }
Beispiel #2
0
        /// <summary>
        /// Gets and caches the most relevant date available for an image.
        /// It looks first at the EXIF date, then at the creation date from ITPC data,
        /// and then at the file's creation date if everything else failed.
        /// </summary>
        /// <param name="pictureFileInfo">The FileInfo for the image.</param>
        /// <returns>The date.</returns>
        internal static DateTime GetImageDate(FileInfo pictureFileInfo)
        {
            string   cacheKey = "date(" + pictureFileInfo.FullName + ")";
            Cache    cache    = HttpContext.Current.Cache;
            DateTime result   = DateTime.MinValue;
            object   cached   = cache[cacheKey];

            if (cached == null)
            {
                Metadata      data      = GetImageData(pictureFileInfo);
                ExifDirectory directory = (ExifDirectory)data.GetDirectory(typeof(ExifDirectory));
                if (directory.ContainsTag(ExifDirectory.TAG_DATETIME))
                {
                    try
                    {
                        result = directory.GetDate(ExifDirectory.TAG_DATETIME);
                    }
                    catch { }
                }
                else
                {
                    IptcDirectory iptcDir = (IptcDirectory)data.GetDirectory(typeof(IptcDirectory));
                    if (iptcDir.ContainsTag(IptcDirectory.TAG_DATE_CREATED))
                    {
                        try
                        {
                            result = iptcDir.GetDate(IptcDirectory.TAG_DATE_CREATED);
                        }
                        catch { }
                    }
                    else
                    {
                        result = pictureFileInfo.CreationTime;
                    }
                }
                cache.Insert(cacheKey, result, new CacheDependency(pictureFileInfo.FullName));
            }
            else
            {
                result = (DateTime)cached;
            }
            return(result);
        }
Beispiel #3
0
 /// <summary>
 /// Extracts and caches the metadata for an image.
 /// </summary>
 /// <param name="pictureFileInfo">The FileInfo to the image.</param>
 /// <returns>The MetaData for the image.</returns>
 internal static Metadata GetImageData(FileInfo pictureFileInfo)
 {
     try
     {
         string cacheKey = "data(" + pictureFileInfo.FullName + ")";
         Cache cache = HttpContext.Current.Cache;
         object cached = cache[cacheKey];
         if (cached == null)
         {
             Metadata data = new Metadata();
             ExifReader exif = new ExifReader(pictureFileInfo);
             exif.Extract(data);
             IptcReader iptc = new IptcReader(pictureFileInfo);
             iptc.Extract(data);
             JpegReader jpeg = new JpegReader(pictureFileInfo);
             jpeg.Extract(data);
             cache.Insert(cacheKey, data, new CacheDependency(pictureFileInfo.FullName));
             return data;
         }
         return (Metadata)cached;
     }
     catch
     {
         return new Metadata();
     }
 }