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);
        }
        public void AnalyzeFile(string filename)
        {
            DateTime?originalDateTime = null;
            int      imageHeight      = 0;
            int      imageWidth       = 0;
            string   extension        = System.IO.Path.GetExtension(filename).ToLower();
            IEnumerable <MetadataExtractor.Directory> imageDirectories = null;

            try
            {
                imageDirectories = ImageMetadataReader.ReadMetadata(filename);
                FileMetadataDirectory fileDirectory     = imageDirectories.OfType <FileMetadataDirectory>().FirstOrDefault();
                FileTypeDirectory     fileTypeDirectory = imageDirectories.OfType <FileTypeDirectory>().FirstOrDefault();

                //var fileSize = fileDirectory?.GetDescription(FileMetadataDirectory.TagFileSize);
                long fileSize = fileDirectory?.GetInt64(FileMetadataDirectory.TagFileSize) ?? 0;
                var  modDate  = fileDirectory?.GetDateTime(FileMetadataDirectory.TagFileModifiedDate);

                switch (extension)
                {
                case ".jpg":
                case ".jpeg":
                {
                    JpegDirectory       jpegDirectory       = imageDirectories.OfType <JpegDirectory>().FirstOrDefault();
                    ExifSubIfdDirectory exifSubIfdDirectory = imageDirectories.OfType <ExifSubIfdDirectory>().FirstOrDefault(d => d.ContainsTag(ExifDirectoryBase.TagDateTimeOriginal));

                    originalDateTime = exifSubIfdDirectory?.GetDateTime(ExifDirectoryBase.TagDateTimeOriginal);

                    if (jpegDirectory != null)
                    {
                        jpegDirectory.TryGetInt32(JpegDirectory.TagImageHeight, out imageHeight);
                        jpegDirectory.TryGetInt32(JpegDirectory.TagImageWidth, out imageWidth);
                    }

                    ImageFileInfo ifi = new ImageFileInfo()
                    {
                        FileFullPath          = filename,
                        ImageHeight           = imageHeight,
                        ImageSize             = fileSize,
                        ImageWidth            = imageWidth,
                        ImageModDateTime      = modDate,
                        ImageOriginalDateTime = originalDateTime,
                    };

                    ifi.SetFileSystemInfo();
                    ImageFiles.AddImageFileInfoToDictionary(ifi);
                    ifi.InsertImageFileInfo(DBOConn);
                }
                break;

                case ".png":
                {
                    PngDirectory pngDirectory = imageDirectories.OfType <PngDirectory>().FirstOrDefault(d => d.Name == "PNG-IHDR");

                    if (pngDirectory != null)
                    {
                        pngDirectory.TryGetInt32(PngDirectory.TagImageHeight, out imageHeight);
                        pngDirectory.TryGetInt32(PngDirectory.TagImageWidth, out imageWidth);
                    }

                    ImageFileInfo ifi = new ImageFileInfo()
                    {
                        FileFullPath          = filename,
                        ImageHeight           = imageHeight,
                        ImageSize             = fileSize,
                        ImageWidth            = imageWidth,
                        ImageModDateTime      = modDate,
                        ImageOriginalDateTime = originalDateTime,
                    };

                    ifi.SetFileSystemInfo();
                    ImageFiles.AddImageFileInfoToDictionary(ifi);
                    ifi.InsertImageFileInfo(DBOConn);
                }
                break;

                case ".nef":
                {
                    List <ExifSubIfdDirectory> exifSubIfdDirectories = imageDirectories.OfType <ExifSubIfdDirectory>().ToList();
                    ExifSubIfdDirectory        exifSubIfdDirectory   = imageDirectories.OfType <ExifSubIfdDirectory>().FirstOrDefault(d => d.GetDescription(ExifDirectoryBase.TagNewSubfileType) == "Full-resolution image");

                    if (exifSubIfdDirectory != null)
                    {
                        exifSubIfdDirectory.TryGetInt32(ExifDirectoryBase.TagImageHeight, out imageHeight);
                        exifSubIfdDirectory.TryGetInt32(ExifDirectoryBase.TagImageWidth, out imageWidth);
                    }

                    exifSubIfdDirectory = imageDirectories.OfType <ExifSubIfdDirectory>().FirstOrDefault(d => d.ContainsTag(ExifDirectoryBase.TagDateTimeOriginal));
                    originalDateTime    = exifSubIfdDirectory?.GetDateTime(ExifDirectoryBase.TagDateTimeOriginal);

                    ImageFileInfo ifi = new ImageFileInfo()
                    {
                        FileFullPath          = filename,
                        ImageHeight           = imageHeight,
                        ImageSize             = fileSize,
                        ImageWidth            = imageWidth,
                        ImageModDateTime      = modDate,
                        ImageOriginalDateTime = originalDateTime,
                    };

                    ifi.SetFileSystemInfo();
                    ImageFiles.AddImageFileInfoToDictionary(ifi);
                    ifi.InsertImageFileInfo(DBOConn);
                }
                break;

                case ".tiff":
                {
                    List <ExifSubIfdDirectory> exifSubIfdDirectories = imageDirectories.OfType <ExifSubIfdDirectory>().ToList();
                    ExifIfd0Directory          exifIfd0Directory     = imageDirectories.OfType <ExifIfd0Directory>().FirstOrDefault();

                    if (exifIfd0Directory != null)
                    {
                        exifIfd0Directory.TryGetInt32(ExifDirectoryBase.TagImageHeight, out imageHeight);
                        exifIfd0Directory.TryGetInt32(ExifDirectoryBase.TagImageWidth, out imageWidth);
                    }

                    ExifSubIfdDirectory exifSubIfdDirectory = imageDirectories.OfType <ExifSubIfdDirectory>().FirstOrDefault(d => d.ContainsTag(ExifDirectoryBase.TagDateTimeOriginal));
                    originalDateTime = exifSubIfdDirectory?.GetDateTime(ExifDirectoryBase.TagDateTimeOriginal);

                    ImageFileInfo ifi = new ImageFileInfo()
                    {
                        FileFullPath          = filename,
                        ImageHeight           = imageHeight,
                        ImageSize             = fileSize,
                        ImageWidth            = imageWidth,
                        ImageModDateTime      = modDate,
                        ImageOriginalDateTime = originalDateTime,
                    };

                    ifi.SetFileSystemInfo();
                    ImageFiles.AddImageFileInfoToDictionary(ifi);
                    ifi.InsertImageFileInfo(DBOConn);
                }
                break;

                case ".psd":
                {
                    List <ExifSubIfdDirectory> exifSubIfdDirectories = imageDirectories.OfType <ExifSubIfdDirectory>().ToList();

                    ExifSubIfdDirectory exifSubIfdDirectory = imageDirectories.OfType <ExifSubIfdDirectory>().FirstOrDefault(d => d.ContainsTag(ExifDirectoryBase.TagDateTimeOriginal));
                    originalDateTime = exifSubIfdDirectory?.GetDateTime(ExifDirectoryBase.TagDateTimeOriginal);
                    exifSubIfdDirectory?.TryGetInt32(ExifDirectoryBase.TagExifImageHeight, out imageHeight);
                    exifSubIfdDirectory?.TryGetInt32(ExifDirectoryBase.TagExifImageWidth, out imageWidth);

                    ImageFileInfo ifi = new ImageFileInfo()
                    {
                        FileFullPath          = filename,
                        ImageHeight           = imageHeight,
                        ImageSize             = fileSize,
                        ImageWidth            = imageWidth,
                        ImageModDateTime      = modDate,
                        ImageOriginalDateTime = originalDateTime,
                    };

                    ifi.SetFileSystemInfo();
                    ImageFiles.AddImageFileInfoToDictionary(ifi);
                    ifi.InsertImageFileInfo(DBOConn);
                }
                break;

                case ".bmp":
                    break;

                case ".gif":
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                ImageFileInfo ifi = new ImageFileInfo()
                {
                    FileFullPath = filename,
                };

                ifi.SetFileSystemInfo();
                ImageFiles.AddImageFileInfoToDictionary(ifi);
            }
        }