public static FileType Process(FileInfo file) { var discriminator = new FileDiscriminator(file); discriminator.GuessType(); return(discriminator.AssertType()); }
public Collision(KeyValuePair <PhotoAttributes, ICollection <FileInfo> > kvp) { Attribs = kvp.Key; foreach (var fileInfo in kvp.Value) { switch (FileDiscriminator.Process(fileInfo)) { case FileType.Raw: Images.Add(fileInfo); break; case FileType.Xmp: Xmp.Add(fileInfo); break; case FileType.Unknown: default: throw new InvalidOperationException(); } } }
public PhotoAttributes(FileInfo file) { var type = FileDiscriminator.Process(file); switch (type) { case FileType.Raw: var dirs = ImageMetadataReader.ReadMetadata(file.FullName); var subIfd = dirs.SingleOrDefault(d => d.Name.Equals("Exif SubIFD")); var xmpMeta = dirs.OfType <XmpDirectory>(); if (subIfd == null) { return; } var tagFNumber = subIfd.Tags.Single(t => t.Name.Equals("F-Number")); var tagFocalLen = subIfd.Tags.Single(t => t.Name.Equals("Focal Length")); var tagX = subIfd.Tags.SingleOrDefault(t => t.Name.Equals("Focal Plane X Resolution")); var tagY = subIfd.Tags.SingleOrDefault(t => t.Name.Equals("Focal Plane Y Resolution")); var tagDateOrig = subIfd.Tags.SingleOrDefault(t => t.Name.Equals("Date/Time Original")); var tagTime = subIfd.Tags.SingleOrDefault(t => t.Name.Equals("Exposure Time")); DateShutter = DateTimeManager.Parse(tagDateOrig?.Description); DateCreatedPhotoshop = WpfMetadataReader.GetPhotoshopCreateDate(file); FNumber = double.Parse(tagFNumber.Description.Replace("f/", "")); ExposureTime = Fraction.Parse(tagTime.Description.Replace("sec", "")); FocalPlaneXResolution = Fraction.Parse(tagX?.Description.Replace("inches", "")); FocalPlaneYResolution = Fraction.Parse(tagY?.Description.Replace("inches", "")); FocalLength = double.Parse(tagFocalLen.Description.Replace("mm", "")); break; case FileType.Xmp: var xmp = file.OpenText().ReadToEnd(); var matchFNumber = RegexFNumber.Match(xmp); var matchX = RegexX.Match(xmp); var matchY = RegexY.Match(xmp); var matchFocal = RegexFocal.Match(xmp); var matchTime = RegexTime.Match(xmp); DateShutter = DateTimeManager.FindAndParse(xmp, @"exif:DateTimeOriginal="); FNumber = Fraction.Parse(matchFNumber.Groups[1].Value); ExposureTime = Fraction.Parse(matchTime.Groups[1].Value); FocalLength = Fraction.Parse(matchFocal.Groups[1].Value); FocalPlaneXResolution = Fraction.Parse(matchX.Groups[1].Value); FocalPlaneYResolution = Fraction.Parse(matchY.Groups[1].Value); DateCreatedPhotoshop = DateTimeManager.FindAndParse(xmp, @"photoshop:DateCreated="); break; case FileType.Jpg: case FileType.Unknown: default: Logger.Warn($"Cannot process {type} file: {file.Name}"); throw new NotImplementedException(); } Logger.Debug($"File {file.Name} has attributes {this}"); }