Exemplo n.º 1
0
        private void ModelOnModelShutdown(object sender, ShutdownEventArgs e)
        {
            _logger.Info($"Shutdown, Initiator: {e.Initiator}, Code: {e.ReplyCode}, Message: {e.ReplyText}");

            if (e.Initiator == ShutdownInitiator.Application)
            {
                return;
            }

            _modelActiveCts?.Cancel();
        }
Exemplo n.º 2
0
        private async Task <bool> ConnectAsync(bool reopen, CancellationTokenSource cts)
        {
            try
            {
                if (_disposeCancellation.IsCancellationRequested)
                {
                    return(false);
                }

                if (reopen)
                {
                    var timeout = _configuration.RecoveryInterval;
                    _logger.Info($"Reopening in {timeout.TotalSeconds:0.###}s");

                    try
                    {
                        await Task.Delay(timeout, _disposeCancellation)
                        .ConfigureAwait(false);
                    }
                    catch (OperationCanceledException)
                    {
                        return(false);
                    }
                }

                // start long-running task for syncronyous connect
                if (await AsyncHelper.RunAsync(Connect)
                    .ConfigureAwait(false))
                {
                    return(true);
                }

                return(false);
            }
            finally
            {
                cts.Cancel();
            }
        }