protected override async Task ExecuteAsync(CancellationToken cancellationToken) { bool started = false; while (!started) { logger.LogInformation("Quitting Hauptwerk (if running)"); int numberOfTriesWithMidi = options.NumberOfSoftTries; while (processHelper.IsRunning()) { cancellationToken.ThrowIfCancellationRequested(); if (numberOfTriesWithMidi > 0) { numberOfTriesWithMidi--; hauptwerk.Quit(); await Task.Delay(options.DelayAfterSoftQuitMs, cancellationToken); } else { processHelper.KillAll(); await Task.Delay(options.DelayAfterKillMs, cancellationToken); } } try { hauptwerk.ClearStatus(); cancellationToken.ThrowIfCancellationRequested(); await Task.Delay(options.WaitBeforeRestartMs, cancellationToken); while (!await audioCard.IsActiveAsync()) { await Task.Delay(options.AudioCardPingInterval, cancellationToken); } cancellationToken.ThrowIfCancellationRequested(); var completionTask = hauptwerk.HauptwerkStatuses .Timeout(TimeSpan.FromMilliseconds(options.OrganLoadingTimeoutMs)) .TakeUntil(status => status.IsHauptwerkAudioActive && status.IsHauptwerkMidiActive) .ToTask(cancellationToken); logger.LogInformation("Starting Hauptwerk"); processHelper.Start(); await completionTask; started = true; logger.LogInformation("Hauptwerk started"); } catch (OperationCanceledException) { logger.LogDebug("Start Hauptwerk cancelled"); throw; } catch (Exception e) { logger.LogError(e, "Error starting Hauptwerk"); } } }
public Task <byte[]> ConvertFileFromat(byte[] content, string inputFormat, string outputFormat) { return(Task.Run(() => { if (inputFormat == outputFormat) { return content; } var inputTempfileName = Path.GetTempFileName(); // file names are created to overcome utf-8 issues in file name. var outputTempfileName = Path.GetTempFileName(); File.WriteAllBytes(inputTempfileName, content); var workingDirectory = Path.Combine(_options.BinariesFolder, GPSBABEL_DIRECTORY); var arguments = "-N -i " + inputFormat + " -f \"" + inputTempfileName + "\" -o " + outputFormat + " -F \"" + outputTempfileName + "\""; _processHelper.Start(GPS_BABEL_EXE, arguments, workingDirectory); File.Delete(inputTempfileName); var outputContent = File.ReadAllBytes(outputTempfileName); File.Delete(outputTempfileName); _logger.LogDebug("Finished converting data from: " + inputFormat + " to: " + outputFormat); return outputContent; })); }
private void UpdateFileToLatestVersion(string workingDirectory) { _processHelper.Start(OSM_UPDATE_EXE, $"{Sources.OSM_FILE_NAME} {UPDATES_FILE_NAME} --base-url={MINUTES_FILES_BASE_ADDRESS} --minute", workingDirectory); RunOsmConvert($"{Sources.OSM_FILE_NAME} {UPDATES_FILE_NAME}", workingDirectory); }
private void UpdateFileToLatestVersion(string workingDirectory) { _processHelper.Start(OSM_UPDATE_EXE, $"{Sources.OSM_FILE_NAME} {UPDATES_FILE_NAME} --base-url={_options.OsmMinutsFileBaseAddress} --minute", workingDirectory); RunOsmConvert($"{Sources.OSM_FILE_NAME} {UPDATES_FILE_NAME}", workingDirectory); }