Exemplo n.º 1
0
        public static void Init(InitOptions options)
        {
            const long gb = 1_000_000_000;

            _log = new ConsoleLog();
            _log.Log(LogSeverity.Info, " ### Initialize CashDB using config file ### ");
            var config = CashDBConfigReader.Read(options.ConfigFullPath);

            CashDBInstance.InitializeFiles(config, options.Layer1SizeInGB * gb, options.Layer2SizeInGB * gb, _log);
            var instance = new CashDBInstance(_log);

            instance.SetupStores(config);
            _log.Log(LogSeverity.Info, " ### Initialization done. ### ");
        }
Exemplo n.º 2
0
        public static void Run(RunOptions options)
        {
            _log = new ConsoleLog();
            _log.Log(LogSeverity.Info, " ### Running the server ### ");
            _log.Log(LogSeverity.Info, $"   ProcessID: {Process.GetCurrentProcess().Id}");

            var config = CashDBConfigReader.Read(options.ConfigFullPath);

            var CashDB = new CashDBInstance(_log);

            CashDB.SetupNetwork(config);
            CashDB.SetupStores(config);
            CashDB.SetupControllers();

            _log.Log(LogSeverity.Info, $"Starting the server listening to {config.IpAddress} on port {config.Port}");
            CashDB.Start();

            _log.Log(LogSeverity.Info, $"Server started - press Ctrl-C to exit");

            AppDomain.CurrentDomain.ProcessExit += (sender, args) => _log.Log(LogSeverity.Info, "App domain exit");

            var readLoop = new CancellationTokenSource();

            Console.CancelKeyPress += (o, args) =>
            {
                CashDB.Stop();
                readLoop.Cancel();
            };
            try
            {
                while (!readLoop.IsCancellationRequested)
                {
                    Console.ReadKey();
                }
            }
            catch (Exception e)
            {
                _log.Log(LogSeverity.Error, "an error occurred");
                _log.Log(LogSeverity.Error, e.Message);
            }
            finally
            {
                _log.Log(LogSeverity.Info, "bye bye");
            }
        }