public static void InsertImageFileInfo(this ImageFileInfo imageFileInfo, string connectionString = null) { if (connectionString != null) { SQL_ImageFileInfo newSqlImageFileInfo = new SQL_ImageFileInfo(imageFileInfo.AsDataObjectsImageFileInfo(), connectionString); newSqlImageFileInfo.Save(); } }
public int LoadFromDatabase(FileStatus fileStatus, FileGrouping fileGrouping) { DataObjects.ImageFileInfoList sqlImageFileInfos = new DataObjects.ImageFileInfoList(); switch (fileGrouping) { case FileGrouping.All: if (fileStatus == FileStatus.All) { sqlImageFileInfos = SQL_ImageFileInfo.GetAll(DBOConn); } else { sqlImageFileInfos = SQL_ImageFileInfo.GetSingletons(fileStatus == FileStatus.Moved, DBOConn); sqlImageFileInfos.AddRange(SQL_ImageFileInfo.GetMultiples(fileStatus == FileStatus.Moved, DBOConn)); } break; case FileGrouping.Singleton: if (fileStatus == FileStatus.All) { sqlImageFileInfos = SQL_ImageFileInfo.GetSingletons(true, DBOConn); sqlImageFileInfos.AddRange(SQL_ImageFileInfo.GetSingletons(false, DBOConn)); } else { sqlImageFileInfos = SQL_ImageFileInfo.GetSingletons(fileStatus == FileStatus.Moved, DBOConn); } break; case FileGrouping.Multiple: if (fileStatus == FileStatus.All) { sqlImageFileInfos = SQL_ImageFileInfo.GetMultiples(true, DBOConn); sqlImageFileInfos.AddRange(SQL_ImageFileInfo.GetMultiples(false, DBOConn)); } else { sqlImageFileInfos = SQL_ImageFileInfo.GetMultiples(fileStatus == FileStatus.Moved, DBOConn); } break; default: break; } foreach (DataObjects.ImageFileInfo sqlImageFileInfo in sqlImageFileInfos) { ImageFileInfo imageFileInfo = sqlImageFileInfo.AsImageFileInfo(); ImageFiles.AddImageFileInfoToDictionary(imageFileInfo, DBOConn); } return(ImageFiles.Count); }
static void Main(string[] args) { string response = string.Empty; ImageFileProcessor imageProcessor = new ImageFileProcessor(); Console.WriteLine("Load and Analyze Files? => "); response = Console.ReadLine(); if (response?.ToLower().StartsWith("y") ?? false) { Console.WriteLine("Delete all Files from Database? => "); response = Console.ReadLine(); if (response?.ToLower().StartsWith("y") ?? false) { SQL_ImageFileInfo.DeleteAll(imageProcessor.DBOConn); } //int fileCount = imageProcessor.AnalyzeFiles("^*.(BMP|NEF|JPG|JPEG|PNG|PSD|TIF|TIFF)$", @"E:\Pictures\2017\2017-08-05"); int fileCount = imageProcessor.AnalyzeFiles("^*.(BMP|NEF|JPG|JPEG|PNG|PSD|TIF|TIFF)$", @"E:\Pictures"); } if (imageProcessor.ImageFiles.Count == 0) { Console.WriteLine("Load from database? => "); response = Console.ReadLine(); if (response?.ToLower().StartsWith("y") ?? false) { FileGrouping fileGrouping; Console.WriteLine("Load All(a), Singletons(s), or Multiples(m)? => "); response = Console.ReadLine(); switch (response?.ToLower().PadRight(1).Substring(0, 1)) { case "s": fileGrouping = FileGrouping.Singleton; break; case "m": fileGrouping = FileGrouping.Multiple; break; case "a": default: fileGrouping = FileGrouping.All; break; } FileStatus fileStatus; Console.WriteLine("Load All(a), Moved(y), or Not Moved(n)? => "); response = Console.ReadLine(); switch (response?.ToLower().PadRight(1).Substring(0, 1)) { case "y": fileStatus = FileStatus.Moved; break; case "n": fileStatus = FileStatus.NotMoved; break; case "a": default: fileStatus = FileStatus.All; break; } int fileCount = imageProcessor.LoadFromDatabase(fileStatus, fileGrouping); } } //int fileCount = imageProcessor.AnalyzeFiles("^*.(nef|NEF)$", @"\\MEGAMINI\edward_figarsky\Documents\WindowsData\DCIM\100NCD80"); //int fileCount = imageProcessor.AnalyzeFiles("^*.(BMP|NEF|JPG|JPEG|PNG|PSD|TIF|TIFF)$", @"E:\AdobeStockPhotos"); if ((imageProcessor.ImageFiles.Count > 0) && (imageProcessor.ImageFiles.Where(i => i.Value.Count == 1).Count() > 0)) { Console.WriteLine("Output Singleton Files? => "); response = Console.ReadLine(); if (response?.ToLower().StartsWith("y") ?? false) { imageProcessor.ProcessSingletonImages(@"E:\PhotoRepository"); imageProcessor.GenerateReport($@"E:PictureReport_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.csv", ","); } } //IEnumerable<MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(@"\\192.168.1.148\Macintosh HD\Users\edward_figarsky 1\Pictures\Dupe\IMG_0605.JPG"); //var subIfdDirectory = directories.OfType<ExifSubIfdDirectory>().FirstOrDefault(); //var dateTime = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagDateTime); //foreach (var directory in directories) // foreach (var tag in directory.Tags) // Console.WriteLine($"{ directory.Name} - {tag.Name} = {tag.Description}"); //var poop = imageProcessor.ImageFiles.Where(i => i.Value.Count > 1).SelectMany(s => s.Value).Distinct(new ImageFileInfo_Comparer()); //foreach(var imageList in imageProcessor.ImageFiles.Where(i => i.Value.Count > 1)) //{ // var distinctImages = imageList.Value.Distinct(new ImageFileInfo_Comparer()); // foreach (var extraItem in imageList.Value.Where(v => !distinctImages.ToList().Exists(d => d.FileFullPath == v.FileFullPath)).ToList()) // { // imageList.Value.Remove(extraItem); // } //} Console.WriteLine("Press Enter to Finish => "); response = Console.ReadLine(); }