Beispiel #1
0
        static AppSettings GetCurrentSettings()
        {
            FileInfo fi       = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location);
            var      location = Path.Combine(fi.DirectoryName);
            var      builder  = new ConfigurationBuilder()
                                .SetBasePath(location)
                                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                .AddEnvironmentVariables();
            var configuration = builder.Build();
            var path          = GetSettingsPath();
            var settings      = GeneralSettingsReader.ReadGeneralSettingsLocal <AppSettings>(path);

            return(settings);
        }
Beispiel #2
0
        public void Initialize()
        {
            var generalSettings = GeneralSettingsReader.ReadGeneralSettingsLocal <BaseSettings>("../../../../../settings/chronobanksettings.json");

            var log = new LogToConsole();

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(generalSettings);
            builder.RegisterInstance(log).As <ILog>();
            builder.BindAzure(generalSettings, log);

            builder.BindCommonServices();

            var testSettings = ReadSettings();

            if (testSettings != null)
            {
                builder.RegisterInstance(testSettings);
            }

            Services = new AutofacServiceProvider(builder.Build());
        }
Beispiel #3
0
        public void ConfigureServices(IServiceCollection services)
        {
#if DEBUG
            var settings = GeneralSettingsReader.ReadGeneralSettingsLocal <Settings>(Configuration["ConnectionString"]).PublicApi;
#else
            var settings = GeneralSettingsReader.ReadGeneralSettings <Settings>(Configuration["ConnectionString"]).PublicApi;
#endif

            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddMemoryCache();

            services.AddSingleton(settings);
            services.AddSingleton(settings.CompanyInfo);

            services.AddSingleton <IAssetsRepository>(
                new AssetsRepository(new AzureTableStorage <AssetEntity>(settings.Db.DictsConnString, "Dictionaries",
                                                                         null)));

            services.AddSingleton <IAssetPairsRepository>(
                new AssetPairsRepository(new AzureTableStorage <AssetPairEntity>(settings.Db.DictsConnString, "Dictionaries",
                                                                                 null)));

            services.AddSingleton <IAssetPairBestPriceRepository>(
                new AssetPairBestPriceRepository(new AzureTableStorage <FeedDataEntity>(settings.Db.HLiquidityConnString,
                                                                                        "MarketProfile", null)));

            services.AddSingleton <IMarketDataRepository>(
                new MarketDataRepository(new AzureTableStorage <MarketDataEntity>(settings.Db.HTradesConnString,
                                                                                  "MarketsData", null)));

            services.AddSingleton <ICandleHistoryRepository>(
                new CandleHistoryRepository(new AzureTableStorage <CandleTableEntity>(settings.Db.HLiquidityConnString,
                                                                                      "CandlesHistory", null)));

            services.AddSingleton <IFeedHistoryRepository>(
                new FeedHistoryRepository(new AzureTableStorage <FeedHistoryEntity>(settings.Db.HLiquidityConnString,
                                                                                    "FeedHistory", null)));

            services.AddSingleton <IWalletsRepository>(
                new WalletsRepository(new AzureTableStorage <WalletEntity>(settings.Db.BalancesInfoConnString,
                                                                           "Accounts", null)));

            services.AddSingleton(x =>
            {
                var assetPairsRepository = (IAssetPairsRepository)x.GetService(typeof(IAssetPairsRepository));
                return(new CachedDataDictionary <string, IAssetPair>(
                           async() => (await assetPairsRepository.GetAllAsync()).ToDictionary(itm => itm.Id)));
            });

            services.AddSingleton(x =>
            {
                var assetRepository = (IAssetsRepository)x.GetService(typeof(IAssetsRepository));
                return(new CachedDataDictionary <string, IAsset>(
                           async() => (await assetRepository.GetAssetsAsync()).ToDictionary(itm => itm.Id)));
            });

            services.AddSingleton(x =>
            {
                var assetsRepo = (IAssetsRepository)x.GetService(typeof(IAssetsRepository));
                return(new CachedDataDictionary <string, IAsset>(
                           async() => (await assetsRepo.GetAssetsAsync()).ToDictionary(itm => itm.Id)));
            });

            services.AddDistributedRedisCache(options =>
            {
                options.Configuration = settings.CacheSettings.RedisConfiguration;
                options.InstanceName  = settings.CacheSettings.FinanceDataCacheInstance;
            });

            services.AddTransient <IOrderBooksService, OrderBookService>();
            services.AddTransient <IMarketCapitalizationService, MarketCapitalizationService>();
            services.AddTransient <IMarketProfileService, MarketProfileService>();
            services.AddTransient <ISrvRatesHelper, SrvRateHelper>();

            services.AddMvc();

            services.AddSwaggerGen();

            services.ConfigureSwaggerGen(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version        = "v1",
                    Title          = "",
                    TermsOfService = "https://lykke.com/city/terms_of_use"
                });

                options.DescribeAllEnumsAsStrings();

                //Determine base path for the application.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;

                //Set the comments path for the swagger json and ui.
                var xmlPath = Path.Combine(basePath, "LykkePublicAPI.xml");
                options.IncludeXmlComments(xmlPath);
            });

            services.AddCors(options =>
            {
                options.AddPolicy("Lykke", builder =>
                {
                    builder
                    .WithOrigins(settings.CrossdomainOrigins)
                    .AllowAnyMethod()
                    .AllowAnyHeader();
                });
            });
        }
Beispiel #4
0
        public void ConfigureServices(string connectionString, IServiceCollection services)
        {
#if DEBUG
            var settings = GeneralSettingsReader.ReadGeneralSettingsLocal <AppStaticSettings>(connectionString).TelegramBot;
#else
            var settings = GeneralSettingsReader.ReadGeneralSettings <AppStaticSettings>(connectionString).TelegramBot;
#endif
            services.AddMemoryCache();
            services.AddSingleton(settings);

            var telegramBot = new TelegramBotClient(settings.Token);
            telegramBot.SetWebhookAsync(string.Empty).Wait();
            services.AddSingleton(telegramBot);

            var sp       = services.BuildServiceProvider();
            var memCache = sp.GetService <IMemoryCache>();

            services.AddSingleton <IMessagesTemplatesRepository>(
                new MessagesTemplatesRepository(new AzureBlobStorage(settings.Db.TemplatesConnString), memCache));

            var log = new LogToTable(new AzureTableStorage <LogEntity>(settings.Db.LogsConnString,
                                                                       "TgLogTelegramBot", null));

            services.AddSingleton <ILog>(log);

            services.AddSingleton <IHandledMessagesRepository>(
                new HandledMessagesRepository(new AzureTableStorageWithCache <HandledMessageRecord>(settings.Db.DataConnString,
                                                                                                    "TgHandledMessages", log)));


            services.AddSingleton <IUsersOnChannelRepository>(
                new UsersOnChannelRepository(new AzureTableStorage <UserOnChannelRecord>(settings.Db.DataConnString,
                                                                                         "TgUsersOnChannel", log)));

            services.AddSingleton <IOffsetRepository>(
                new OffsetRepository(new AzureTableStorage <OffsetRecord>(settings.Db.DataConnString,
                                                                          "TgUpdatesOffset", log)));

            services.AddSingleton <IServiceMonitoringRepository>(
                new ServiceMonitoringRepository(new AzureTableStorage <MonitoringRecordEntity>(settings.Db.SharedConnString,
                                                                                               "Monitoring", log)));

            services.AddTransient <IMessagesService, MessagesService>();
            services.AddTransient <IUpdatesHandlerService, UpdateHandlerService>();
            services.AddTransient <ILykkeApiClient, LykkeApiClient>();

            services.AddTransient <BotCommandsFactory>();
            services.AddTransient <IBotCommand, AndroidAppCommand>();
            services.AddTransient <IBotCommand, IosAppCommand>();
            services.AddTransient <IBotCommand, StartCommand>();
            services.AddTransient <IBotCommand, SupportMailCommand>();
            services.AddTransient <IBotCommand, UserJoinedCommand>();
            services.AddTransient <IBotCommand, UserLeftCommand>();
            services.AddTransient <IBotCommand, FaqCommand>();
            services.AddTransient <IBotCommand, GetAppCommand>();
            services.AddTransient <IBotCommand, ExchangeRatesCommand>();
            services.AddTransient <IBotCommand, BtcUsdRatesCommand>();
            services.AddTransient <IBotCommand, EthUsdRatesCommand>();
            services.AddTransient <IBotCommand, EthBtcRatesCommand>();
            services.AddTransient <IBotCommand, Lkk1YBtcRatesCommand>();
            services.AddTransient <IBotCommand, LkkBtcRatesCommand>();
            services.AddTransient <IBotCommand, LkkUsdRatesCommand>();
            services.AddTransient <IBotCommand, SlrBtcRatesCommand>();
            services.AddTransient <IBotCommand, TimeBtcRatesCommand>();

            services.AddTransient <IUpdatesHandlerService, UpdateHandlerService>();
        }