Exemple #1
0
        private async Task <bool> StepAsync(CancellationToken cancellation)
        {
            var          oldState = State;
            StatusResult status   = null;

            try
            {
                switch (State)
                {
                case NBXplorerState.NotConnected:
                    status = await _Client.GetStatusAsync(cancellation);

                    if (status != null)
                    {
                        if (status.IsFullySynched)
                        {
                            State = NBXplorerState.Ready;
                        }
                        else
                        {
                            State = NBXplorerState.Synching;
                        }
                    }
                    break;

                case NBXplorerState.Synching:
                    status = await _Client.GetStatusAsync(cancellation);

                    if (status == null)
                    {
                        State = NBXplorerState.NotConnected;
                    }
                    else if (status.IsFullySynched)
                    {
                        State = NBXplorerState.Ready;
                    }
                    break;

                case NBXplorerState.Ready:
                    status = await _Client.GetStatusAsync(cancellation);

                    if (status == null)
                    {
                        State = NBXplorerState.NotConnected;
                    }
                    else if (!status.IsFullySynched)
                    {
                        State = NBXplorerState.Synching;
                    }
                    break;
                }
            }
            catch when(cancellation.IsCancellationRequested)
            {
            }
Exemple #2
0
        public async Task UpdateClientState(ExplorerClient client, CancellationToken cancellation)
        {
            _logger.LogInformation($"Updating summary for {client.CryptoCode}");
            var          state  = (NBXplorerState?)null;
            string       error  = null;
            StatusResult status = null;

            try
            {
                status = await client.GetStatusAsync(cancellation);

                if (status == null)
                {
                    state = NBXplorerState.NotConnected;
                }
                else if (status.IsFullySynched)
                {
                    state = NBXplorerState.Ready;
                }
                else if (!status.IsFullySynched)
                {
                    state = NBXplorerState.Synching;
                }
            }
            catch (Exception ex) when(!cancellation.IsCancellationRequested)
            {
                _logger.LogWarning($"Could not update summary for {client.CryptoCode} because {ex.Message}");
                error = ex.Message;
            }

            if (status != null && error == null && status.NetworkType != _options.NetworkType)
            {
                error =
                    $"{client.CryptoCode}: NBXplorer is on a different ChainType (actual: {status.NetworkType}, expected: {_options.NetworkType})";
            }

            if (error != null)
            {
                state = NBXplorerState.NotConnected;
            }

            var summary = new NBXplorerSummary()
            {
                Status = status,
                State  = state.GetValueOrDefault(NBXplorerState.NotConnected),
                Error  = error
            };

            _logger.LogInformation($"summary updated {client.CryptoCode}");
            _summaries.AddOrReplace(client.CryptoCode.ToUpperInvariant(), summary);
        }
Exemple #3
0
        private async Task <StatusResult> GetStatusWithTimeout()
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            using (cts)
            {
                var cancellation = cts.Token;
                while (!cancellation.IsCancellationRequested)
                {
                    try
                    {
                        var status = await _Client.GetStatusAsync(cancellation).ConfigureAwait(false);

                        return(status);
                    }
                    catch (OperationCanceledException) { }
                    catch { }
                }
            }
            return(null);
        }
Exemple #4
0
        private async Task <bool> StepAsync(CancellationToken cancellation)
        {
            var          oldState = State;
            string       error    = null;
            StatusResult status   = null;

            try
            {
                switch (State)
                {
                case NBXplorerState.NotConnected:
                    status = await _Client.GetStatusAsync(cancellation);

                    if (status != null)
                    {
                        if (status.IsFullySynched)
                        {
                            State = NBXplorerState.Ready;
                        }
                        else
                        {
                            State = NBXplorerState.Synching;
                        }
                    }
                    break;

                case NBXplorerState.Synching:
                    status = await _Client.GetStatusAsync(cancellation);

                    if (status == null)
                    {
                        State = NBXplorerState.NotConnected;
                    }
                    else if (status.IsFullySynched)
                    {
                        State = NBXplorerState.Ready;
                    }
                    break;

                case NBXplorerState.Ready:
                    status = await _Client.GetStatusAsync(cancellation);

                    if (status == null)
                    {
                        State = NBXplorerState.NotConnected;
                    }
                    else if (!status.IsFullySynched)
                    {
                        State = NBXplorerState.Synching;
                    }
                    break;
                }
            }
            catch (Exception ex) when(!cancellation.IsCancellationRequested)
            {
                error = ex.Message;
            }


            if (status == null && error == null)
            {
                error = $"{_Network.CryptoCode}: NBXplorer does not support this cryptocurrency";
            }

            if (status != null && error == null)
            {
                if (status.ChainType != _Network.NBXplorerNetwork.DefaultSettings.ChainType)
                {
                    error = $"{_Network.CryptoCode}: NBXplorer is on a different ChainType (actual: {status.ChainType}, expected: {_Network.NBXplorerNetwork.DefaultSettings.ChainType})";
                }
            }

            if (error != null)
            {
                State  = NBXplorerState.NotConnected;
                status = null;
                _Aggregator.Publish(new NBXplorerErrorEvent(_Network, error));
            }

            if (oldState != State)
            {
                if (State == NBXplorerState.Synching)
                {
                    PollInterval = TimeSpan.FromSeconds(10);
                }
                else
                {
                    PollInterval = TimeSpan.FromMinutes(1);
                }
                _Aggregator.Publish(new NBXplorerStateChangedEvent(_Network, oldState, State));
            }
            _Dashboard.Publish(_Network, State, status, error);
            return(oldState != State);
        }