예제 #1
0
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            int numberOfTriesWithMidi = options.NumberOfSoftTries;

            logger.LogInformation("Quit Hauptwerk (if running)");
            while (processHelper.IsRunning())
            {
                cancellationToken.ThrowIfCancellationRequested();
                if (numberOfTriesWithMidi > 0)
                {
                    numberOfTriesWithMidi--;
                    logger.LogDebug("Quit Hauptwerk via interface");
                    hauptwerk.Quit();
                    await Task.Delay(options.DelayAfterSoftQuitMs, cancellationToken);
                }
                else
                {
                    logger.LogDebug("Quit Hauptwerk with Kill");
                    processHelper.KillAll();
                    await Task.Delay(options.DelayAfterKillMs, cancellationToken);
                }
            }
            cancellationToken.ThrowIfCancellationRequested();
            logger.LogInformation("Request computer shutdown");
            shutdownHelper.Shutdown();
        }
예제 #2
0
        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");
                }
            }
        }