async Task PerformExifOperationAsync(string[] paths, bool backup, string operation, CancellationToken token) { _ = paths ?? throw new ArgumentNullException(nameof(paths)); _ = operation ?? throw new ArgumentNullException(nameof(operation)); var backupArg = backup ? null : " -overwrite_original -progress"; await _exifOperationSemaphore.WaitAsync(token).ConfigureAwait(false); // By default exif tool receives ??? instead of valid cyrillic paths - need to reencode var encodedPaths = paths.Select(path => $"\"{EncodeToUtf8(path)}\""); var command = $"-charset filename=utf8 {operation}{backupArg} -n {string.Join(" ", encodedPaths)}"; try { var processResult = await _processUtility.ExecuteCommandAsync(_exifToolPath, command, token).ConfigureAwait(false); if (processResult.IsError) { throw new InvalidOperationException(processResult.Error); } } finally { _exifOperationSemaphore.Release(); } }
public async Task ExecuteCommandAsync(string executable, string command, string directoryPath, CancellationToken cancellationToken) { _ = executable ?? throw new ArgumentNullException(nameof(executable)); _ = command ?? throw new ArgumentNullException(nameof(command)); _messageHub.Publish($"Executing '{executable}' '{command}'...".ToMessage()); var result = await _processUtility.ExecuteCommandAsync(executable, command, cancellationToken, workingDirectory : directoryPath).ConfigureAwait(false); if (result.IsError) { throw new InvalidOperationException($"Cannot execute '{command}'"); } _messageHub.Publish($"'{command}' has been executed successfully".ToSuccess()); }
static async Task ExtractPackageAsync(string packageFilePath, IProcessUtility processUtility, string versionDirectoryPath, string fileName) { await processUtility.ExecuteCommandAsync(Path.Combine(AssemblyDirectory, "7za.exe"), $"e \"{packageFilePath}\" -o\"{versionDirectoryPath}\" {fileName} -r -y", CancellationToken.None) .ConfigureAwait(false); }
static async Task PushNugetAsync(ILogger logger, IProcessUtility processUtility, string lastPackagePath) { await processUtility.ExecuteCommandAsync("dotnet", $"nuget push \"{lastPackagePath}\" -s {NugetServerUrl} -k {NugetServerApiKey}", CancellationToken.None).ConfigureAwait(false); logger.LogInformation("Nuget file {PackageName} was pushed to {NugetServerUrl}", NugetUtilities.ParseNugetPackageInfoForPath(lastPackagePath)?.ToString(), NugetServerUrl); }