示例#1
0
        private static IRichStore LoadStore(Options options)
        {
            bool readOnlyMode = options.Seeds is null;
            BaseBlockStatesStore innerStore;

            switch (options.StoreType)
            {
            case "rocksdb":
                innerStore = new RocksDBStore.RocksDBStore(options.StorePath);
                break;

            case "default":
                innerStore = new DefaultStore(
                    options.StorePath,
                    flush: false,
                    readOnly: readOnlyMode);
                break;

            default:
                // FIXME: give available store type as argument hint without code duplication.
                var    availableStoreTypes = new[] { "rocksdb", "default" };
                string longOptionName      = options.GetType().GetProperty(nameof(options.StoreType))
                                             .GetCustomAttribute <OptionAttribute>().LongName;
                throw new InvalidOptionValueException(
                          "--" + longOptionName,
                          options.StoreType,
                          availableStoreTypes);
            }

            bool useMySQL = !string.IsNullOrEmpty(options.MySQLDatabase) &&
                            !string.IsNullOrEmpty(options.MySQLPassword) &&
                            !string.IsNullOrEmpty(options.MySQLServer) &&
                            !string.IsNullOrEmpty(options.MySQLUsername) &&
                            !(options.MySQLPort is null);

            if (useMySQL)
            {
                var mySqlOptions = new MySQLRichStoreOptions(
                    options.MySQLDatabase,
                    options.MySQLServer,
                    options.MySQLPort.Value,
                    options.MySQLUsername,
                    options.MySQLPassword);
                return(new MySQLRichStore(
                           innerStore,
                           mySqlOptions
                           ));
            }
            else
            {
                return(new LiteDBRichStore(
                           innerStore,
                           path: options.StorePath,
                           flush: false,
                           readOnly: readOnlyMode
                           ));
            }
        }
示例#2
0
        private static IRichStore LoadStore(Options options)
        {
            // FIXME: This method basically does the same thing to Libplanet.Extensions.Cocona's
            // StoreCommand.LoadStoreFromUri() & StatsCommand.LoadStoreFromUri() methods.
            // The duplicate code should be extract to a shared common method.
            // https://github.com/planetarium/libplanet/issues/1573
            bool   readOnlyMode = options.Seeds is null;
            IStore innerStore;

            switch (options.StoreType)
            {
            case "rocksdb":
                innerStore = new RocksDBStore.RocksDBStore(
                    options.StorePath,
                    maxTotalWalSize: 16 * 1024 * 1024,
                    keepLogFileNum: 1);
                break;

            case "default":
                innerStore = new DefaultStore(
                    options.StorePath,
                    flush: false,
                    readOnly: readOnlyMode);
                break;

            default:
                // FIXME: give available store type as argument hint without code duplication.
                var          availableStoreTypes = new[] { "rocksdb", "default" };
                const string longOptionName      = "store-type";
                throw new InvalidOptionValueException(
                          "--" + longOptionName,
                          options.StoreType,
                          availableStoreTypes);
            }

            bool useMySQL = !string.IsNullOrEmpty(options.MySQLDatabase) &&
                            !string.IsNullOrEmpty(options.MySQLPassword) &&
                            !string.IsNullOrEmpty(options.MySQLServer) &&
                            !string.IsNullOrEmpty(options.MySQLUsername) &&
                            !(options.MySQLPort is null);

            if (useMySQL)
            {
                var mySqlOptions = new MySQLRichStoreOptions(
                    options.MySQLDatabase,
                    options.MySQLServer,
                    options.MySQLPort.Value,
                    options.MySQLUsername,
                    options.MySQLPassword);
                return(new MySQLRichStore(
                           innerStore,
                           mySqlOptions
                           ));
            }
            else
            {
                return(new LiteDBRichStore(
                           innerStore,
                           path: options.StorePath,
                           flush: false,
                           readOnly: readOnlyMode
                           ));
            }
        }
示例#3
0
        private static IRichStore LoadStore(Options options)
        {
            bool   readOnlyMode = options.Seeds is null;
            IStore innerStore;

            switch (options.StoreType)
            {
            case "rocksdb":
                innerStore = new RocksDBStore.RocksDBStore(
                    options.StorePath,
                    maxTotalWalSize: 16 * 1024 * 1024,
                    keepLogFileNum: 1);
                break;

            case "monorocksdb":
                innerStore = new RocksDBStore.MonoRocksDBStore(
                    options.StorePath,
                    maxTotalWalSize: 16 * 1024 * 1024,
                    keepLogFileNum: 1);
                break;

            case "default":
                innerStore = new DefaultStore(
                    options.StorePath,
                    flush: false,
                    readOnly: readOnlyMode);
                break;

            default:
                // FIXME: give available store type as argument hint without code duplication.
                var          availableStoreTypes = new[] { "rocksdb", "default" };
                const string longOptionName      = "store-type";
                throw new InvalidOptionValueException(
                          "--" + longOptionName,
                          options.StoreType,
                          availableStoreTypes);
            }

            bool useMySQL = !string.IsNullOrEmpty(options.MySQLDatabase) &&
                            !string.IsNullOrEmpty(options.MySQLPassword) &&
                            !string.IsNullOrEmpty(options.MySQLServer) &&
                            !string.IsNullOrEmpty(options.MySQLUsername) &&
                            !(options.MySQLPort is null);

            if (useMySQL)
            {
                var mySqlOptions = new MySQLRichStoreOptions(
                    options.MySQLDatabase,
                    options.MySQLServer,
                    options.MySQLPort.Value,
                    options.MySQLUsername,
                    options.MySQLPassword);
                return(new MySQLRichStore(
                           innerStore,
                           mySqlOptions
                           ));
            }
            else
            {
                return(new LiteDBRichStore(
                           innerStore,
                           path: options.StorePath,
                           flush: false,
                           readOnly: readOnlyMode
                           ));
            }
        }