public async Task RunExifToolWithThreeCommands() { // arrange var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create()); sut.Initialize(); // act var task1 = sut.ExecuteAsync(image); var task2 = sut.ExecuteAsync(image); var task3 = sut.ExecuteAsync(image); // assert var result3 = await task3.ConfigureAwait(false); result3.Should().NotBeNullOrEmpty(); var result2 = await task2.ConfigureAwait(false); result2.Should().NotBeNullOrEmpty(); var result1 = await task1.ConfigureAwait(false); result1.Should().NotBeNullOrEmpty(); await sut.DisposeAsync().ConfigureAwait(false); }
public async Task RunExiftoolGetImageSizeAndExposureTime() { // arrange var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create()); sut.Initialize(); // act var result = await sut.ExecuteAsync( new[] { "-s", "-ImageSize", "-ExposureTime", image, }) .ConfigureAwait(false); // assert result.Should().Be("ImageSize : 1712x2288" + Environment.NewLine); await sut.DisposeAsync().ConfigureAwait(false); // just for fun output.WriteLine(image); output.WriteLine(result); }
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(); }
public async Task RunExiftool_ShouldReturnEmpty_WhenQueriedTagDoesNotExist() { // arrange var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create()); sut.Initialize(); // act var result = await sut.ExecuteAsync( new[] { "-ExposureTime", image, }) .ConfigureAwait(false); // assert result.Should().Be(string.Empty); await sut.DisposeAsync().ConfigureAwait(false); // just for fun output.WriteLine(image); output.WriteLine(result); }
public async Task InitAndDisposeTest() { // arrange var sut = new AsyncExifTool(AsyncExifToolConfigurationFactory.Create()); // act sut.Initialize(); await sut.DisposeAsync().ConfigureAwait(false); // assert // sut.IsClosed.Should().Be(true); }
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); }
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); }
public async Task DisposeAsyncShouldCancelAllPendingRequestsTest() { // arrange var tasks = new Task <string> [Repeat]; 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(); for (var i = 0; i < Repeat; i++) { tasks[i] = sut.GetVersionAsync(); } sw.Stop(); await sut.DisposeAsync().ConfigureAwait(false); // assert var countCancelled = 0; foreach (var t in tasks) { try { 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"); }
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("--------------------------------------------------------------"); }