Esempio n. 1
0
        /// <summary>
        /// Consolidates EXIF GPS values into XMP style
        /// </summary>
        /// <param name="gps"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        private IEnumerable <XmpProperty> ProcessGps(IEnumerable <XmpProperty> gps, decimal priority)
        {
            GpsCoordinate latitude = null, longitude = null, destLatitude = null, destLongitude = null;
            string        latitudeRef = null, longitudeRef = null, destLatitudeRef = null, destLongitudeRef = null;

            foreach (XmpProperty property in gps)
            {
                if (!(property.Schema is ExifSchema))
                {
                    yield return(property);

                    continue;
                }

                switch ((ExifSchema)property.Schema)
                {
                case ExifSchema.GPSLatitude:
                {
                    GpsCoordinate.TryParse(Convert.ToString(property.Value), out latitude);
                    break;
                }

                case ExifSchema.GPSLatitudeRef:
                {
                    latitudeRef = Convert.ToString(property.Value);
                    break;
                }

                case ExifSchema.GPSLongitude:
                {
                    GpsCoordinate.TryParse(Convert.ToString(property.Value), out longitude);
                    break;
                }

                case ExifSchema.GPSLongitudeRef:
                {
                    longitudeRef = Convert.ToString(property.Value);
                    break;
                }

                case ExifSchema.GPSDestLatitude:
                {
                    GpsCoordinate.TryParse(Convert.ToString(property.Value), out destLatitude);
                    break;
                }

                case ExifSchema.GPSDestLatitudeRef:
                {
                    destLatitudeRef = Convert.ToString(property.Value);
                    break;
                }

                case ExifSchema.GPSDestLongitude:
                {
                    GpsCoordinate.TryParse(Convert.ToString(property.Value), out destLongitude);
                    break;
                }

                case ExifSchema.GPSDestLongitudeRef:
                {
                    destLongitudeRef = Convert.ToString(property.Value);
                    break;
                }

                case ExifSchema.GPSDateStamp:
                case ExifSchema.GPSTimeStamp:

                case ExifSchema.GPSAltitude:
                case ExifSchema.GPSAltitudeRef:

                case ExifSchema.GPSDestBearing:
                case ExifSchema.GPSDestBearingRef:

                case ExifSchema.GPSDestDistance:
                case ExifSchema.GPSDestDistanceRef:

                case ExifSchema.GPSImgDirection:
                case ExifSchema.GPSImgDirectionRef:

                case ExifSchema.GPSSpeed:
                case ExifSchema.GPSSpeedRef:

                case ExifSchema.GPSTrack:
                case ExifSchema.GPSTrackRef:
                default:
                {
                    // TODO: process other dual properties
                    yield return(property);

                    break;
                }
                }
            }

            if (latitude != null)
            {
                if (!String.IsNullOrEmpty(latitudeRef))
                {
                    latitude.Direction = latitudeRef;
                }

                yield return(new XmpProperty
                {
                    Schema = ExifSchema.GPSLatitude,
                    Value = latitude.ToString("X"),
                    Priority = priority
                });
            }

            if (longitude != null)
            {
                if (!String.IsNullOrEmpty(longitudeRef))
                {
                    longitude.Direction = longitudeRef;
                }

                yield return(new XmpProperty
                {
                    Schema = ExifSchema.GPSLongitude,
                    Value = longitude.ToString("X"),
                    Priority = priority
                });
            }

            if (destLatitude != null)
            {
                if (!String.IsNullOrEmpty(destLatitudeRef))
                {
                    destLatitude.Direction = destLatitudeRef;
                }

                yield return(new XmpProperty
                {
                    Schema = ExifSchema.GPSDestLatitude,
                    Value = destLatitude.ToString("X"),
                    Priority = priority
                });
            }

            if (destLongitude != null)
            {
                if (!String.IsNullOrEmpty(destLongitudeRef))
                {
                    destLongitude.Direction = destLongitudeRef;
                }

                yield return(new XmpProperty
                {
                    Schema = ExifSchema.GPSDestLongitude,
                    Value = destLongitude.ToString("X"),
                    Priority = priority
                });
            }
        }
Esempio n. 2
0
        internal static XmpProperty ProcessValue(XmpProperty property)
        {
            if (property.ValueType is XmpBasicType)
            {
                switch ((XmpBasicType)property.ValueType)
                {
                case XmpBasicType.Boolean:
                {
                    bool value;
                    if (Boolean.TryParse(Convert.ToString(property.Value), out value))
                    {
                        property.Value = value;
                    }
                    break;
                }

                case XmpBasicType.Date:
                {
                    DateTime value;
                    if (DateTime.TryParse(Convert.ToString(property.Value), out value))
                    {
                        property.Value = value;
                    }
                    break;
                }

                case XmpBasicType.Integer:
                {
                    int value;
                    if (Int32.TryParse(Convert.ToString(property.Value), out value))
                    {
                        property.Value = value;
                    }
                    break;
                }

                case XmpBasicType.Real:
                {
                    decimal value;
                    if (Decimal.TryParse(Convert.ToString(property.Value), out value))
                    {
                        property.Value = value;
                    }
                    break;
                }
                }
            }
            else if (property.ValueType is ExifType)
            {
                switch ((ExifType)property.ValueType)
                {
                case ExifType.GpsCoordinate:
                {
                    GpsCoordinate gps;
                    if (GpsCoordinate.TryParse(Convert.ToString(property.Value), out gps))
                    {
                        property.Value = gps;
                    }
                    break;
                }

                case ExifType.Rational:
                {
                    // TODO: how best to determine type of Rational<T>
                    XmpPropertyCollection.ProcessRational <long>(property);
                    break;
                }
                }
            }

            return(property);
        }