Example #1
0
        protected override void Load(ContainerBuilder builder)
        {
            var connectionString = _dbSettings.Nested(x => x.DataConnString);

            builder
            .Register(c => WalletRepository.Create(connectionString, c.Resolve <ILogFactory>()))
            .As <IWalletRepository>()
            .SingleInstance();

            builder
            .Register(c => BlockchainWalletsRepository.Create(connectionString, c.Resolve <ILogFactory>()))
            .As <IBlockchainWalletsRepository>()
            .SingleInstance();

            builder
            .Register(c => FirstGenerationBlockchainWalletRepository.Create(_dbSettings.Nested(x => x.ClientPersonalInfoConnString), c.Resolve <ILogFactory>()))
            .As <IFirstGenerationBlockchainWalletRepository>()
            .SingleInstance();

            builder
            .Register(c => MonitoringSubscriptionRepository.Create(connectionString, c.Resolve <ILogFactory>()))
            .As <IMonitoringSubscriptionRepository>()
            .SingleInstance();

            builder
            .Register(c => WalletCredentialsHistoryRepository.Create(_dbSettings.Nested(x => x.ClientPersonalInfoConnString), c.Resolve <ILogFactory>()))
            .As <IWalletCredentialsHistoryRepository>()
            .SingleInstance();
        }
        private static async Task CreateIndexesAsync(string settingsUrl)
        {
            if (!Uri.TryCreate(settingsUrl, UriKind.Absolute, out _))
            {
                Console.WriteLine($"{SettingsUrl} should be a valid uri");

                return;
            }

            var logFactory = LogFactory.Create()
                             .AddConsole();

            var settings = new SettingsServiceReloadingManager <AppSettings>(settingsUrl, p => { }).Nested(x => x.BlockchainWalletsService.Db.DataConnString);

            var defaultWalletsRepository = (WalletRepository)WalletRepository.Create(settings, logFactory);

            string continuationToken = null;

            Console.WriteLine("Creating Indexes...");

            var progressCounter = 0;

            do
            {
                try
                {
                    IEnumerable <WalletDto> wallets;

                    (wallets, continuationToken) = await defaultWalletsRepository.GetAllAsync(100, continuationToken);

                    foreach (var defaultWallet in wallets)
                    {
                        await defaultWalletsRepository.AddAsync
                        (
                            defaultWallet.BlockchainType,
                            defaultWallet.AssetId,
                            defaultWallet.ClientId,
                            defaultWallet.Address
                        );

                        Console.SetCursorPosition(0, Console.CursorTop);
                        Console.Write($"{++progressCounter} indexes created");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace + " " + e.Message);
                }
            } while (continuationToken != null);

            if (progressCounter == 0)
            {
                Console.WriteLine("Nothing to create");
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine($"Added indexes to {progressCounter} wallets");
            }
        }
Example #3
0
        private static async Task ConvertAddressesAsync(string settingsUrl, string integrationId, string assetId)
        {
            if (!Uri.TryCreate(settingsUrl, UriKind.Absolute, out _))
            {
                Console.WriteLine($"{SettingsUrl} should be a valid uri");

                return;
            }

            var logFactory = LogFactory.Create()
                             .AddConsole();

            var settings = new SettingsServiceReloadingManager <AppSettings>(settingsUrl, p => { }).Nested(x => x.BlockchainWalletsService.Db.DataConnString);

            var defaultWalletsRepository = (WalletRepository)WalletRepository.Create(settings, logFactory);

            string continuationToken = null;

            Console.WriteLine("Converting wallets...");

            var progressCounter = 0;

            do
            {
                IEnumerable <WalletDto> defaultWallets;

                (defaultWallets, continuationToken) = await defaultWalletsRepository.GetAsync(integrationId, assetId, 100, continuationToken);

                foreach (var defaultWallet in defaultWallets)
                {
                    await defaultWalletsRepository.DeleteIfExistsAsync
                    (
                        defaultWallet.BlockchainType,
                        defaultWallet.AssetId,
                        defaultWallet.ClientId
                    );

                    Console.SetCursorPosition(0, Console.CursorTop);
                    Console.Write($"{++progressCounter} wallets converted");
                }
            } while (continuationToken != null);

            if (progressCounter == 0)
            {
                Console.WriteLine("Nothing to convert");
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("Conversion completed");
            }
        }
Example #4
0
        private static async Task Migrate(string settingsUrl)
        {
            if (!Uri.TryCreate(settingsUrl, UriKind.Absolute, out _))
            {
                Console.WriteLine($"{SettingsUrl} should be a valid uri");

                return;
            }

            var logFactory = LogFactory.Create().AddConsole();

            var settings     = new SettingsServiceReloadingManager <AppSettings>(settingsUrl, p => { });
            var settingsRepo = settings.Nested(x => x.BlockchainWalletsService.Db.DataConnString);

            var builder     = new ContainerBuilder();
            var appSettings = settings;

            builder.RegisterInstance(logFactory).As <ILogFactory>();

            builder
            .RegisterModule(new CqrsModule(appSettings.CurrentValue.BlockchainWalletsService.Cqrs))
            .RegisterModule(new RepositoriesModule(appSettings.Nested(x => x.BlockchainWalletsService.Db)))
            .RegisterModule(new ServiceModule(
                                appSettings.CurrentValue.BlockchainsIntegration,
                                appSettings.CurrentValue.BlockchainSignFacadeClient,
                                appSettings.CurrentValue,
                                appSettings.CurrentValue.AssetsServiceClient,
                                appSettings.CurrentValue.BlockchainWalletsService));

            var container = builder.Build();

            var cqrsEngine = container.Resolve <ICqrsEngine>();

            var archiveWalletsTable = AzureTableStorage <BlockchainWalletEntity> .Create
                                      (
                settingsRepo,
                "BlockchainWalletsArchive",
                logFactory
                                      );

            var defaultWalletsRepository    = (WalletRepository)WalletRepository.Create(settingsRepo, logFactory);
            var blockchainWalletsRepository = (BlockchainWalletsRepository)AzureRepositories.BlockchainWalletsRepository.Create(settingsRepo, logFactory);

            string continuationToken = null;

            Console.WriteLine("Creating indexes for default wallets...");

            var       progressCounter = 0;
            const int batchSize       = 10;

            //Commented code recreates all wallets with indicies
            //do
            //{
            //    try
            //    {
            //        IEnumerable<WalletDto> wallets;
            //        (wallets, continuationToken) = await blockchainWalletsRepository.GetAllAsync(100, continuationToken);

            //        foreach (var batch in wallets.Batch(batchSize))
            //        {
            //            await Task.WhenAll(batch.Select(o =>
            //                blockchainWalletsRepository.DeleteIfExistsAsync(o.BlockchainType, o.ClientId, o.Address)));
            //            progressCounter += batchSize;
            //            Console.SetCursorPosition(0, Console.CursorTop);
            //            Console.Write($"{progressCounter} indexes created");
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e.StackTrace + " " + e.Message);
            //    }

            //} while (continuationToken != null);

            //do
            //{
            //    try
            //    {
            //        IEnumerable<BlockchainWalletEntity> wallets;
            //        (wallets, continuationToken) = await archiveWalletsTable.GetDataWithContinuationTokenAsync(100, continuationToken);

            //        foreach (var batch in wallets.Batch(batchSize))
            //        {
            //            await Task.WhenAll(batch.Select(async o =>
            //            {
            //                await blockchainWalletsRepository.AddAsync(o.IntegrationLayerId, o.ClientId, o.Address,
            //                    o.CreatedBy);

            //                var @event = new WalletCreatedEvent
            //                {
            //                    Address = o.Address,
            //                    BlockchainType = o.IntegrationLayerId,
            //                    IntegrationLayerId = o.IntegrationLayerId,
            //                    CreatedBy = CreatorType.LykkeWallet,
            //                    ClientId = o.ClientId
            //                };

            //                cqrsEngine.PublishEvent
            //                (
            //                    @event,
            //                    BlockchainWalletsBoundedContext.Name
            //                );
            //            }));
            //            progressCounter += batchSize;
            //            Console.SetCursorPosition(0, Console.CursorTop);
            //            Console.Write($"{progressCounter} indexes created");
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e.StackTrace + " " + e.Message);
            //    }

            //} while (continuationToken != null);

            do
            {
                try
                {
                    IEnumerable <WalletDto> wallets;
                    (wallets, continuationToken) = await defaultWalletsRepository.GetAllAsync(100, continuationToken);

                    foreach (var batch in wallets.Batch(batchSize))
                    {
                        await Task.WhenAll(batch.Select(async o =>
                        {
                            await blockchainWalletsRepository.AddAsync(o.BlockchainType, o.ClientId, o.Address,
                                                                       CreatorType.LykkeWallet);

                            var @event = new WalletCreatedEvent
                            {
                                Address            = o.Address,
                                BlockchainType     = o.BlockchainType,
                                IntegrationLayerId = o.BlockchainType,
                                CreatedBy          = CreatorType.LykkeWallet,
                                ClientId           = o.ClientId
                            };

                            cqrsEngine.PublishEvent
                            (
                                @event,
                                BlockchainWalletsBoundedContext.Name
                            );
                        }));

                        progressCounter += batchSize;
                        Console.SetCursorPosition(0, Console.CursorTop);
                        Console.Write($"{progressCounter} indexes created");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace + " " + e.Message);
                }
            } while (continuationToken != null);
            Console.WriteLine();
            Console.WriteLine("Conversion completed");
        }