public AsyncExifToolRotationService()
        {
            // var logger = new ExifToolConsoleLogger();
            var configuration = new AsyncExifToolConfiguration("exiftool.exe", Encoding.UTF8, Environment.NewLine, new List <string>());

            asyncExifTool = new AsyncExifTool(configuration);
            asyncExifTool.Initialize();
        }
Exemplo n.º 2
0
        public void Ctor_ShouldThrow_WhenConfigurationIsNull()
        {
            // arrange
            AsyncExifToolConfiguration configuration = null;

            // act
            Action act = () => _ = new AsyncExifTool(configuration);

            // assert
            act.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 3
0
        public static async Task Main()
        {
            ConfigureNLog();
            var nlogLogger = LogManager.GetCurrentClassLogger(typeof(AsyncExifTool));

            Console.WriteLine("Sample application using AsyncExifTool in combination with NLog");

            // AsyncExifTool configuration. Please make sure exiftool.exe is accessible.
            var commonArgs = new List <string>();
            var asyncExifToolConfiguration = new AsyncExifToolConfiguration(
                "exiftool.exe",
                Encoding.UTF8,
                commonArgs);

            // Create a logger for AsyncExifTool. AsyncExifTool does not require any logging framework. You have to write your own adapter.
            var logger = new AsyncExifToolToNLogAdapter(nlogLogger);

            // Create AsyncExifTool instance. You can also do this without a logger.
            // ie:
            // await using var exiftool = new AsyncExifTool(asyncExifToolConfiguration);
            await using var exiftool = new AsyncExifTool(asyncExifToolConfiguration, logger);
            try
            {
                // initialize. At this point the exiftool process is started.
                // this call might throw an exception.
                exiftool.Initialize();
            }
            catch (AsyncExifToolInitialisationException e)
            {
                Console.WriteLine(e);
                Console.WriteLine("press enter to exit");
                Console.ReadKey();
                return;
            }

            // Just some calls to ExifTool (using an extension method)
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine(await exiftool.GetVersionAsync());
            }

            try
            {
                var result = await exiftool.ExecuteAsync("dummy command");

                Console.WriteLine("dummy command result: " + result);
            }
            catch (Exception e)
            {
                Console.WriteLine("dummy command result exception: " + e.Message);
            }

            var file = @"1.jpg";

            try
            {
                Console.WriteLine("Add person to existing image.");
                var result = await exiftool.ExecuteAsync(new[] { "-Xmp:PersonInImage+=\"Test person\"", file });

                Console.WriteLine($"RESULT: {result}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"ERROR MSG: {e.Message}");
            }

            Console.WriteLine(string.Empty);

            try
            {
                Console.WriteLine("Add person to NON existing image.");
                var result = await exiftool.ExecuteAsync(new[] { "-Xmp:PersonInImage+=\"Test person\"", file + @"xxx" });

                Console.WriteLine($"RESULT: {result}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"ERROR MSG: {e.Message}");
            }
            Console.WriteLine(string.Empty);

            try
            {
                Console.WriteLine("Get person information from image.");
                var result = await exiftool.ExecuteAsync(new[] { "-Xmp:PersonInImage", file });

                Console.WriteLine($"RESULT: {result}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"ERROR MSG: {e.Message}");
            }

            Console.WriteLine(string.Empty);

            // we are done
            Console.WriteLine("press enter to exit");
            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            if (args.Count() < 1)
            {
                Console.WriteLine("Include a file name or multiple file names as parameters");
                return;
            }

            var location   = Path.GetDirectoryName(Assembly.GetEntryAssembly().GetFiles()[0].Name);
            var homeFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            var options    = ReadOptions(".imagedetailscataloger_options.json", homeFolder);

            if (options == null)
            {
                // Fall-back to the default options.
                Console.WriteLine("Using default options, user options not found");
                options = ReadOptions("options.json", location);
                if (options == null)
                {
                    Console.Error.WriteLine("Cannot find the Options JSON file in the application folder");
                }
            }

            var databaseLocation = Path.Combine(options.UseHomeFolder ? homeFolder : location, "ImageDetails.sqlite");

            var exifToolPath           = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? @"exiftool.exe" : @"exiftool";
            var exifToolResultEncoding = Encoding.UTF8;
            var config        = new AsyncExifToolConfiguration(exifToolPath, exifToolResultEncoding, null);
            var asyncExifTool = new AsyncExifTool(config);

            asyncExifTool.Initialize();

            if (!File.Exists(databaseLocation))
            {
                Console.WriteLine("Creating SQLite DB");

                SQLiteConnection.CreateFile(databaseLocation);
            }
            var sqlite = new SQLiteConnection("Data Source='" + databaseLocation + "'");

            sqlite.Open();

            var command1 = new SQLiteCommand("CREATE TABLE IF NOT EXISTS image_details (id integer PRIMARY KEY, file TEXT NOT NULL UNIQUE);", sqlite);

            command1.ExecuteNonQuery();

            var data       = new Dictionary <string, Dictionary <string, ExifData> >();
            var statistics = new Statistics();

            foreach (var arg in args)
            {
                if (Directory.Exists(arg))
                {
                    var searchOptions = options.RecursiveFolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
                    var files         = Directory.GetFiles(arg, "*.*", searchOptions);
                    Array.Sort(files, StringComparer.OrdinalIgnoreCase);
                    foreach (var filePath in files)
                    {
                        if (options.FolderSearchExtensions.Any(extension => string.Equals(Path.GetExtension(filePath), extension, StringComparison.OrdinalIgnoreCase)))
                        {
                            ParseImageFile(filePath, asyncExifTool, data);
                            if (data.Keys.Count >= options.FilesInBatch)
                            {
                                if (options.RecycleExifTool)
                                {
                                    asyncExifTool.DisposeAsync().AsTask().Wait();
                                }

                                // To avoid memory issues, write to the DB every so many files.
                                WriteDataToDB(sqlite, data, statistics);

                                if (options.RecycleExifTool)
                                {
                                    asyncExifTool = new AsyncExifTool(config);
                                    asyncExifTool.Initialize();
                                }
                            }
                        }
                    }
                }
                else if (File.Exists(arg))
                {
                    ParseImageFile(arg, asyncExifTool, data);
                }
                else
                {
                    Console.WriteLine("Could not load file {0}...", arg);
                }
            }


            WriteDataToDB(sqlite, data, statistics);

            sqlite.Close();

            Console.WriteLine("--------------------------------------------------------------");
            Console.WriteLine(" Added {0} files to the database", statistics.Added);
            Console.WriteLine(" Updated {0} files in the database", statistics.Updated);
            Console.WriteLine(" Added {0} columns to the database", statistics.ColumnsAdded);
            Console.WriteLine("--------------------------------------------------------------");
        }