Beispiel #1
0
        /// <summary>TBD</summary>
        /// <param name="imageTagCollection">TBD</param>
        /// <param name="hasLatLong">TBD</param>
        /// <returns>TBD</returns>
        private static decimal[] InnerGetImageLatLong(Exif.ExifTagCollection imageTagCollection, out bool hasLatLong)
        {
            decimal[] imageLatLong = new decimal[2];
            hasLatLong = false;
            Hashtable latLongValues = new Hashtable();

            foreach (Exif.ExifTag tag in imageTagCollection)
            {
                if ((string.Compare(tag.FieldName, "GPSLATITUDEREF", true) == 0) ||
                    (string.Compare(tag.FieldName, "GPSLATITUDE", true) == 0) ||
                    (string.Compare(tag.FieldName, "GPSLONGITUDEREF", true) == 0) ||
                    (string.Compare(tag.FieldName, "GPSLONGITUDE", true) == 0))
                {
                    latLongValues.Add(tag.FieldName.ToUpper(), tag.Value);
                    hasLatLong = true;
                }
            }
            if (hasLatLong)
            {
                //Lat first
                imageLatLong[0] = ConvertToDecimalDegrees(Convert.ToString(latLongValues["GPSLATITUDE"]), Convert.ToString(latLongValues["GPSLATITUDEREF"]).ToUpper().Contains("SOUTH"));
                //Then Long
                imageLatLong[1] = ConvertToDecimalDegrees(Convert.ToString(latLongValues["GPSLONGITUDE"]), Convert.ToString(latLongValues["GPSLONGITUDEREF"]).ToUpper().Contains("WEST"));
            }
            else
            {
                imageLatLong[0] = -1;
                imageLatLong[1] = -1;
            }
            return(imageLatLong);
        }
Beispiel #2
0
        public static DateTime GetImageTimestamp(System.Drawing.Image image)
        {
            Exif.ExifTagCollection imageTagCollection = new Exif.ExifTagCollection(image);
            string dateTimeOriginalValue = string.Empty;

            foreach (Exif.ExifTag tag in imageTagCollection)
            {
                if (string.Compare(tag.FieldName, "DateTimeOriginal", true) == 0)
                {
                    dateTimeOriginalValue = tag.Value;
                    //WebCommon.WriteDebugMessage(string.Format("Date Taken found in Exif: {0}", tag.Value));
                    break;
                }
            }
            DateTime dateTimeOriginal = DateTime.MinValue;

            if (String.IsNullOrEmpty(dateTimeOriginalValue))
            {
                return(DateTime.MinValue);
            }
            if (!DateTime.TryParseExact(dateTimeOriginalValue, "yyyy:MM:dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dateTimeOriginal))
            {
                return(DateTime.MinValue);
            }
            return(dateTimeOriginal);
        }
Beispiel #3
0
        /// <summary>Retrieve data related to a Digital Library document</summary>
        /// <param name="values">Value collection from</param>
        /// <returns>An HTML-formatted Table containing File and Exif properties</returns>
        public static string GetImageProperties(Hashtable values)
        {
            StringBuilder properties    = new StringBuilder();
            int           imageId       = Convert.ToInt32(values["ID"]);
            Hashtable     spParams      = new Hashtable();
            Hashtable     latLongValues = new Hashtable();
            bool          hasLatLong    = false;

            spParams.Add("ID", imageId);
            latLongValues.Add("ID", imageId);
            DataSet imageProperties;

            using (IO io = new IO(WebCommon.ConnectionString))
            {
                imageProperties = io.ExecuteDataSetQuery(IO.CreateCommandFromStoredProc("DigitalLibrary_GetImageProperties", Param.CreateParam("ID", SqlDbType.Int, Convert.ToInt32(values["ID"]))));
            }
            //Load properties from Digital Library table
            properties.AppendLine(@"<table class=""vs_property"">");
            properties.AppendLine(@"<tr><td colspan=""2"" class=""title"">File</td></tr>");
            properties.AppendFormat(@"<tr><td>Uploaded By&nbsp;</td><td>{0}&nbsp;</td></tr>", Security.GetFullUserNameFromId((string)IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "UPLOADED_BY", "&nbsp;")));
            properties.AppendFormat(@"<tr><td>Original Name&nbsp;</td><td>{0}&nbsp;</td></tr>", IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "ORIGINAL_NAME", "&nbsp;"));
            properties.AppendFormat(@"<tr><td>Uploaded At&nbsp;</td><td>{0}&nbsp;</td></tr>", IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "DATE_UPLOADED", "&nbsp;"));
            properties.AppendFormat(@"<tr><td>Size&nbsp;</td><td>{0}&nbsp;</td></tr>", IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "FILE_SIZE", "&nbsp;"));
            properties.AppendFormat(@"<tr><td>Status&nbsp;</td><td>{0}&nbsp;</td></tr>", IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "STATUS", "&nbsp;"));
            if (((string)values["FILE_TYPE"]).ToUpper() == "I")
            {
                //Load properties from Exif Tag
                properties.AppendLine(@"<tr><td colspan=""2"" class=""title"">Image Header Information (exif)</td></tr>");
                if (!File.Exists(HostingEnvironment.MapPath(ImageFilePath + GetDigitalLibraryFileFolder(imageId) + "/" + imageId + ".jpg")))
                {
                    properties.AppendLine(@"<tr><td colspan=""2"">Image Header Information (exif) could not be retrieved for this image.</td></tr>");
                }
                else
                {
                    try
                    {
                        Exif.ExifTagCollection imageTagCollection = new Exif.ExifTagCollection(HostingEnvironment.MapPath(ImageFilePath + GetDigitalLibraryFileFolder(imageId) + "/" + imageId + ".jpg"));
                        foreach (Exif.ExifTag tag in imageTagCollection)
                        {
                            if (tag.FieldName.ToUpper() != "MAKERNOTE")
                            {
                                properties.AppendFormat(@"<tr><td>{0}&nbsp;</td><td>&nbsp;{1}</td></tr>", HttpUtility.HtmlEncode(tag.FieldName), HttpUtility.HtmlEncode(tag.Value));
                            }
                            if ((string.Compare(tag.FieldName, "GPSLATITUDEREF", true) == 0) ||
                                (string.Compare(tag.FieldName, "GPSLATITUDE", true) == 0) ||
                                (string.Compare(tag.FieldName, "GPSLONGITUDEREF", true) == 0) ||
                                (string.Compare(tag.FieldName, "GPSLONGITUDE", true) == 0))
                            {
                                latLongValues.Add(tag.FieldName.ToUpper(), tag.Value);
                                hasLatLong = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WebCommon.LogExceptionInfo(new Exception(string.Format("EXIF Tags could not be retrieved for Image: {0}", values["ID"]), ex));
                        properties.AppendLine(@"<tr><td colspan=""2"">Image Header Information (exif) could not be retrieved for this image.</td></tr>");
                    }
                }
            }
            if (hasLatLong)
            {
                properties.AppendLine(GenerateMapRow(latLongValues));
            }
            properties.AppendLine(@"<table>");
            return(properties.ToString());
        }
 public static DateTime GetImageTimestamp(System.Drawing.Image image)
 {
     Exif.ExifTagCollection imageTagCollection = new Exif.ExifTagCollection(image);
     string dateTimeOriginalValue = string.Empty;
     foreach (Exif.ExifTag tag in imageTagCollection)
     {
         if (string.Compare(tag.FieldName, "DateTimeOriginal", true) == 0)
         {
             dateTimeOriginalValue = tag.Value;
             //WebCommon.WriteDebugMessage(string.Format("Date Taken found in Exif: {0}", tag.Value));
             break;
         }
     }
     DateTime dateTimeOriginal = DateTime.MinValue;
     if (String.IsNullOrEmpty(dateTimeOriginalValue))
     {
         return DateTime.MinValue;
     }
     if (!DateTime.TryParseExact(dateTimeOriginalValue, "yyyy:MM:dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dateTimeOriginal))
     {
         return DateTime.MinValue;
     }
     return dateTimeOriginal;
 }
 /// <summary>Retrieve data related to a Digital Library document</summary>
 /// <param name="values">Value collection from</param>
 /// <returns>An HTML-formatted Table containing File and Exif properties</returns>
 public static string GetImageProperties(Hashtable values)
 {
     StringBuilder properties = new StringBuilder();
     int imageId = Convert.ToInt32(values["ID"]);
     Hashtable spParams = new Hashtable();
     Hashtable latLongValues = new Hashtable();
     bool hasLatLong = false;
     spParams.Add("ID", imageId);
     latLongValues.Add("ID", imageId);
     DataSet imageProperties;
     using (IO io = new IO(WebCommon.ConnectionString))
     {
         imageProperties = io.ExecuteDataSetQuery(IO.CreateCommandFromStoredProc("DigitalLibrary_GetImageProperties", Param.CreateParam("ID", SqlDbType.Int, Convert.ToInt32(values["ID"]))));
     }
     //Load properties from Digital Library table
     properties.AppendLine(@"<table class=""vs_property"">");
     properties.AppendLine(@"<tr><td colspan=""2"" class=""title"">File</td></tr>");
     properties.AppendFormat(@"<tr><td>Uploaded By&nbsp;</td><td>{0}&nbsp;</td></tr>", Security.GetFullUserNameFromId((string)IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "UPLOADED_BY", "&nbsp;")));
     properties.AppendFormat(@"<tr><td>Original Name&nbsp;</td><td>{0}&nbsp;</td></tr>", IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "ORIGINAL_NAME", "&nbsp;"));
     properties.AppendFormat(@"<tr><td>Uploaded At&nbsp;</td><td>{0}&nbsp;</td></tr>", IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "DATE_UPLOADED", "&nbsp;"));
     properties.AppendFormat(@"<tr><td>Size&nbsp;</td><td>{0}&nbsp;</td></tr>", IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "FILE_SIZE", "&nbsp;"));
     properties.AppendFormat(@"<tr><td>Status&nbsp;</td><td>{0}&nbsp;</td></tr>", IO.GetDataRowValue(imageProperties.Tables[0].Rows[0], "STATUS", "&nbsp;"));
     if (((string)values["FILE_TYPE"]).ToUpper() == "I")
     {
         //Load properties from Exif Tag
         properties.AppendLine(@"<tr><td colspan=""2"" class=""title"">Image Header Information (exif)</td></tr>");
         if (!File.Exists(HostingEnvironment.MapPath(ImageFilePath + GetDigitalLibraryFileFolder(imageId) + "/" + imageId + ".jpg")))
         {
             properties.AppendLine(@"<tr><td colspan=""2"">Image Header Information (exif) could not be retrieved for this image.</td></tr>");
         }
         else
         {
             try
             {
                 Exif.ExifTagCollection imageTagCollection = new Exif.ExifTagCollection(HostingEnvironment.MapPath(ImageFilePath + GetDigitalLibraryFileFolder(imageId) + "/" + imageId + ".jpg"));
                 foreach (Exif.ExifTag tag in imageTagCollection)
                 {
                     if (tag.FieldName.ToUpper() != "MAKERNOTE")
                     {
                         properties.AppendFormat(@"<tr><td>{0}&nbsp;</td><td>&nbsp;{1}</td></tr>", HttpUtility.HtmlEncode(tag.FieldName), HttpUtility.HtmlEncode(tag.Value));
                     }
                     if ((string.Compare(tag.FieldName, "GPSLATITUDEREF", true) == 0)
                     || (string.Compare(tag.FieldName, "GPSLATITUDE", true) == 0)
                     || (string.Compare(tag.FieldName, "GPSLONGITUDEREF", true) == 0)
                     || (string.Compare(tag.FieldName, "GPSLONGITUDE", true) == 0))
                     {
                         latLongValues.Add(tag.FieldName.ToUpper(), tag.Value);
                         hasLatLong = true;
                     }
                 }
             }
             catch (Exception ex)
             {
                 WebCommon.LogExceptionInfo(new Exception(string.Format("EXIF Tags could not be retrieved for Image: {0}", values["ID"]), ex));
                 properties.AppendLine(@"<tr><td colspan=""2"">Image Header Information (exif) could not be retrieved for this image.</td></tr>");
             }
         }
     }
     if (hasLatLong)
     {
         properties.AppendLine(GenerateMapRow(latLongValues));
     }
     properties.AppendLine(@"<table>");
     return properties.ToString();
 }