Exemplo n.º 1
0
        private static object LoadKongoOptions(KongoOptions opts)
        {
            _opts = opts;
            _opts.ApplicationStartedOn = DateTimeOffset.UtcNow;

            // parse database path and create db connection string
            try
            {
                if (File.Exists(_opts.DatabasePath) && !Directory.Exists(_opts.DatabasePath))
                {
                    _dbConnectionString = $"Data Source={_opts.DatabasePath};";
                }
                else
                {
                    if (_opts.DatabasePath.EndsWith(".sqlite", StringComparison.InvariantCultureIgnoreCase))
                    {
                        _dbConnectionString = $"Data Source={_opts.DatabasePath};";
                    }
                    else
                    {
                        if (!Directory.Exists(_opts.DatabasePath))
                        {
                            Directory.CreateDirectory(_opts.DatabasePath);
                        }

                        _dbConnectionString = $"Data Source={Path.Combine(_opts.DatabasePath, "Kongo.SQlite")};";
                    }
                }
            }
            catch (Exception ex)
            {
                var currentForeground = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Exception occured parsing DatabasePath");
                Console.WriteLine($"Excaption: {ex}, {ex.Message}");
                Console.ForegroundColor = currentForeground;

                _dbConnectionString = "Data Source=Kongo.SQlite;";
            }

            // validate urls info
            if (!string.IsNullOrEmpty(_opts.ServerUrls))
            {
                if (string.IsNullOrEmpty(_opts.CertificateSubject))
                {
                    if (string.IsNullOrEmpty(_opts.CertificatePath) || string.IsNullOrEmpty(_opts.CertificatePassword))
                    {
                        var message = "Missing dependent property:  (--server.url --cert-subject) or (--server.url --cert-path --cert-password) are required";
                        Console.WriteLine(message);
                        throw new KongoOptionsException(message);
                    }
                }
            }

            // initialize Kongo Status model
            _kongoStatus = new KongoStatusModel()
            {
                CurrentBlockHeight    = 0,
                CurrentChartTimeframe = TimeRangeEnum.OneHour,
                LastBlockReceivedAt   = default,
Exemplo n.º 2
0
 public NodeStats(ILogger <NodeStats> logger, IProcessNodeStatistics processor, KongoOptions opts, KongoStatusModel kongoStatus)
 {
     _logger      = logger;
     _httpClient  = new HttpClient();
     _processor   = processor;
     _sb          = new StringBuilder();
     _opts        = opts;
     _kongoStatus = kongoStatus;
 }