コード例 #1
0
        public async Task RunWithInputStreamTest()
        {
            // arrange
            var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create());
            var sw  = Stopwatch.StartNew();

            sut.Initialize();
            sw.Stop();
            output.WriteLine($"It took {sw.Elapsed.ToString()} to Initialize exiftool");

            // act
            sw.Reset();
            sw.Start();
            var version = string.Empty;

            for (var i = 0; i < Repeat; i++)
            {
                version = await sut.GetVersionAsync().ConfigureAwait(false);
            }
            sw.Stop();
            await sut.DisposeAsync().ConfigureAwait(false);

            // assert
            output.WriteLine($"It took {sw.Elapsed.ToString()} to retrieve exiftool version {Repeat} times");
            output.WriteLine($"Version: {version}");
            version.Should().NotBeNullOrEmpty();
        }
コード例 #2
0
        public async Task RunExiftoolForVersionAndImageErrorTest()
        {
            // arrange
            var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create());

            sut.Initialize();

            // act
            var         getMetadataNonExistingImageTask = sut.ExecuteAsync(image + "does not exist");
            Func <Task> act     = async() => await getMetadataNonExistingImageTask;
            var         version = await sut.GetVersionAsync().ConfigureAwait(false);

            // assert
            act.Should().Throw <Exception>();
            version.Should().NotBeNullOrEmpty();

            await sut.DisposeAsync().ConfigureAwait(false);
        }
コード例 #3
0
        public async Task DisposeAsyncShouldCancelAllPendingRequestsTest()
        {
            // arrange
            var       tasks = new Task <string> [Repeat];
            Stopwatch sw;

#if NETCOREAPP3_0
            await using (var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create()))
#else
            using (var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create()))
#endif
            {
                sw = Stopwatch.StartNew();
                sut.Initialize();
                sw.Stop();
                output.WriteLine($"It took {sw.Elapsed.ToString()} to Initialize exiftool");

                // act
                sw.Reset();
                sw.Start();
                for (var i = 0; i < Repeat; i++)
                {
                    tasks[i] = sut.GetVersionAsync();
                }
                sw.Stop();
            }

            // assert
            var countCancelled = 0;
            foreach (var t in tasks)
            {
                try
                {
                    output.WriteLine(await t.ConfigureAwait(false));
                }
                catch (TaskCanceledException)
                {
                    countCancelled++;
                }
            }

            countCancelled.Should().BeGreaterOrEqualTo(Repeat / 2).And.NotBe(Repeat);
            output.WriteLine($"It took {sw.Elapsed.ToString()} to retrieve exiftool version {Repeat - countCancelled} times");
        }
コード例 #4
0
        public async Task RunExiftoolForVersionAndImageTest()
        {
            // arrange
            var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create());

            sut.Initialize();

            // act
            var version = await sut.GetVersionAsync().ConfigureAwait(false);

            var result = await sut.ExecuteAsync(image).ConfigureAwait(false);

            // assert
            version.Should().NotBeNullOrEmpty();
            result.Should().NotBeNullOrEmpty();

            await sut.DisposeAsync().ConfigureAwait(false);

            // just for fun
            output.WriteLine(version);
            output.WriteLine(result);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: coenm/AsyncExifTool
        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();
        }