示例#1
0
        private static void ExportXmlTradersToMongo(ICollection <Trader> traders)
        {
            var mongoProvider = new MongoProvider(
                System.Configuration.ConfigurationManager.ConnectionStrings["MolybdenumDb"].ConnectionString,
                System.Configuration.ConfigurationManager.ConnectionStrings["MolybdenumDb"].Name);

            var mongoDatabase = mongoProvider.GetDatabase();

            var mongoExporter = new MongoExporter();

            mongoExporter.ExportTraders(mongoDatabase, traders);
        }
示例#2
0
        private static void ImportDataFromMongo()
        {
            var dbContext = new ChemicalsDbContext();

            var mongoProvider = new MongoProvider(
                System.Configuration.ConfigurationManager.ConnectionStrings["MolybdenumDb"].ConnectionString,
                System.Configuration.ConfigurationManager.ConnectionStrings["MolybdenumDb"].Name);

            var mongoDatabase = mongoProvider.GetDatabase();

            var mongoImporter = new MongoImporter();
            var products      = mongoImporter.GetAllProducts(mongoDatabase, "Products");

            foreach (var product in products)
            {
                dbContext.Products.Add(product);
            }

            dbContext.SaveChanges();

            Console.WriteLine("The data was successfully imported to the SQL Server.");
        }
示例#3
0
 public IMongoDatabase GetDatabase()
 {
     return(_mongoProvider.GetDatabase());
 }
示例#4
0
        private static void ImportDataFromMongo()
        {
            var dbContext = new ChemicalsDbContext();

            var mongoProvider = new MongoProvider(
                System.Configuration.ConfigurationManager.ConnectionStrings["MolybdenumDb"].ConnectionString,
                System.Configuration.ConfigurationManager.ConnectionStrings["MolybdenumDb"].Name);

            var mongoDatabase = mongoProvider.GetDatabase();

            var mongoImporter = new MongoImporter();
            var products = mongoImporter.GetAllProducts(mongoDatabase, "Products");

            foreach (var product in products)
            {
                dbContext.Products.Add(product);
            }

            dbContext.SaveChanges();

            Console.WriteLine("The data was successfully imported to the SQL Server.");
        }
示例#5
0
        private static void ExportXmlTradersToMongo(ICollection<Trader> traders)
        {
            var mongoProvider = new MongoProvider(
               System.Configuration.ConfigurationManager.ConnectionStrings["MolybdenumDb"].ConnectionString,
               System.Configuration.ConfigurationManager.ConnectionStrings["MolybdenumDb"].Name);

            var mongoDatabase = mongoProvider.GetDatabase();

            var mongoExporter = new MongoExporter();
            mongoExporter.ExportTraders(mongoDatabase, traders);
        }
示例#6
0
            PreInitAsync(IConfigProvider configProvider, IDbProvider dbProvider, string baseDbPath,
                IBlockTree blockTree, ITxPool txPool, ISpecProvider specProvider,
                IReceiptStorage receiptStorage, IWallet wallet, IFilterStore filterStore, IFilterManager filterManager,
                ITimestamper timestamper, IEthereumEcdsa ecdsa, IRpcModuleProvider rpcModuleProvider,
                IKeyStore keyStore, IJsonSerializer jsonSerializer, ICryptoRandom cryptoRandom, IEnode enode,
                INdmConsumerChannelManager consumerChannelManager, INdmDataPublisher dataPublisher,
                IGrpcServer grpcServer, bool enableUnsecuredDevWallet, IWebSocketsManager webSocketsManager,
                ILogManager logManager, IBlockProcessor blockProcessor)
        {
            if (!(configProvider.GetConfig<INdmConfig>() is NdmConfig defaultConfig))
            {
                return default;
            }

            if (!defaultConfig.Enabled)
            {
                return default;
            }

            if (defaultConfig.StoreConfigInDatabase && string.IsNullOrWhiteSpace(defaultConfig.Id))
            {
                throw new ArgumentException("NDM config stored in database requires an id.", nameof(defaultConfig.Id));
            }

            IMongoProvider mongoProvider = null;
            IConfigRepository configRepository = null;
            IEthRequestRepository ethRequestRepository = null;
            switch (defaultConfig.Persistence?.ToLowerInvariant())
            {
                case "mongo":
                    mongoProvider = new MongoProvider(configProvider.GetConfig<INdmMongoConfig>(), logManager);
                    var database = mongoProvider.GetDatabase();
                    configRepository = new ConfigMongoRepository(database);
                    ethRequestRepository = new EthRequestMongoRepository(database);
                    break;
                default:
                    configRepository = new ConfigRocksRepository(dbProvider.ConfigsDb, new NdmConfigDecoder());
                    ethRequestRepository = new EthRequestRocksRepository(dbProvider.EthRequestsDb,
                        new EthRequestDecoder());
                    break;
            }

            var configManager = new ConfigManager(defaultConfig, configRepository);
            var ndmConfig = await configManager.GetAsync(defaultConfig.Id);
            if (ndmConfig is null)
            {
                ndmConfig = defaultConfig;
                if (defaultConfig.StoreConfigInDatabase)
                {
                    await configManager.UpdateAsync(ndmConfig);
                }
            }

            var webSocketsModule = webSocketsManager.GetModule("ndm");
            var notifier = new NdmNotifier(webSocketsModule);
            var ethRequestService = new EthRequestService(ndmConfig.FaucetHost, logManager);
            var services = _ndmModule.Init(new NdmRequiredServices(configProvider, configManager, ndmConfig,
                baseDbPath, dbProvider, mongoProvider, logManager, blockTree, txPool, specProvider, receiptStorage,
                filterStore, filterManager, wallet, timestamper, ecdsa, keyStore, rpcModuleProvider, jsonSerializer,
                cryptoRandom, enode, consumerChannelManager, dataPublisher, grpcServer, ethRequestService, notifier,
                enableUnsecuredDevWallet, blockProcessor));

            var faucetAddress = string.IsNullOrWhiteSpace(ndmConfig.FaucetAddress)
                ? null
                : new Address(ndmConfig.FaucetAddress);
            var faucet = new NdmFaucet(services.CreatedServices.BlockchainBridge, ethRequestRepository, faucetAddress,
                ndmConfig.FaucetWeiRequestMaxValue, ndmConfig.FaucetEthDailyRequestsTotalValue, ndmConfig.FaucetEnabled,
                timestamper, wallet, logManager);

            var consumerAddress = string.IsNullOrWhiteSpace(ndmConfig.ConsumerAddress)
                ? Address.Zero
                : new Address(ndmConfig.ConsumerAddress);
            var providerAddress = string.IsNullOrWhiteSpace(ndmConfig.ProviderAddress)
                ? Address.Zero
                : new Address(ndmConfig.ProviderAddress);
            var consumers = _ndmConsumersModule.Init(services);

            return (ndmConfig, services, faucet, consumers.AccountService, consumers.ConsumerService, consumerAddress,
                providerAddress);
        }