// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public IServiceProvider ConfigureServices(IServiceCollection services) { var settings = GeneralSettingsReader.ReadGeneralSettings <GeneralSettings>(Configuration.GetConnectionString("Settings")); services.AddMvc(o => { o.Filters.Add(new HandleAllExceptionsFilterFactory()); }); services.AddSwaggerGen(options => { options.SingleApiVersion(new Info { Version = "v1", Title = "Chronobank_Api" }); 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, "ChronobankApi.xml"); options.IncludeXmlComments(xmlPath); }); var builder = new AzureBinder().Bind(settings.ChronobankApi); builder.Populate(services); return(new AutofacServiceProvider(builder.Build())); }
private static BaseSettings ReadSettings() { var connectionString = CloudConfigurationManager.GetSetting("ConnectionString"); var containerSettingsLocation = CloudConfigurationManager.GetSetting("ContainerSettingsLocation"); var containerSettingsKey = CloudConfigurationManager.GetSetting("ContainerSettingsKey"); var settingsLocations = new Tuple <string, string>(containerSettingsLocation, containerSettingsKey); return(GeneralSettingsReader.ReadGeneralSettings <BaseSettings>(connectionString, settingsLocations)); }
static SettingsWrapper GetSettings(IConfigurationRoot configuration) { var connectionString = configuration.GetConnectionString("ConnectionString"); if (string.IsNullOrEmpty(connectionString)) { throw new Exception("Please, provide connection string"); } var settings = GeneralSettingsReader.ReadGeneralSettings <SettingsWrapper>(connectionString); return(settings); }
static SettingsWrapper 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 settings = GeneralSettingsReader.ReadGeneralSettings <SettingsWrapper>(configuration.GetConnectionString("ConnectionString")); return(settings); }
static SettingsWrapper GetSettings(IConfigurationRoot configuration) { var connectionString = configuration.GetConnectionString("ConnectionString"); if (string.IsNullOrWhiteSpace(connectionString)) { connectionString = DefaultConnectionString; } var settings = GeneralSettingsReader.ReadGeneralSettings <SettingsWrapper>(connectionString); return(settings); }
private SettingsWrapper ReadSettings() { try { var url = File.ReadAllText(@"..\..\..\configurationUrl.url"); if (string.IsNullOrWhiteSpace(url)) { return(null); } SettingsWrapper settings = GeneralSettingsReader.ReadGeneralSettings <SettingsWrapper>(url); return(settings); } catch (Exception e) { return(null); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var settingsConnectionString = Configuration["SettingsConnString"]; var settingsContainer = Configuration["SettingsContainerName"]; var settingsFileName = Configuration["SettingsFileName"]; Settings = GeneralSettingsReader.ReadGeneralSettings <BaseSettings>(settingsConnectionString, settingsContainer, settingsFileName); var connectionString = Settings.Azure.StorageConnString; var connectionStringLogs = Settings.Azure.StorageLogConnString; Log = new LogToTable(new AzureTableStorage <LogEntity>(connectionStringLogs, "LogCompPlatform", null)); // Add framework services. services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddAuthentication( options => { options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; }); services.AddMvc(); services.RegisterLyykeServices(); var notificationEmailsQueueConnString = Settings.Notifications.EmailsQueueConnString; var notificationSlackQueueConnString = Settings.Notifications.SlackQueueConnString; if (HostingEnvironment.IsProduction()) { services.RegisterNotificationServices(notificationEmailsQueueConnString, notificationSlackQueueConnString); } else { services.RegisterInMemoryNotificationServices(); } services.RegisterRepositories(connectionString, Log); JobScheduler.Start(connectionString, Log); services.AddRecaptcha(new RecaptchaOptions { SiteKey = Settings.Recaptcha.SiteKey, SecretKey = Settings.Recaptcha.SecretKey }); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public IServiceProvider ConfigureServices(IServiceCollection services) //public void ConfigureServices(IServiceCollection services) { var settings = GeneralSettingsReader.ReadGeneralSettings <BaseSettings>(Configuration, "OffchainMonitorSettings"); services.AddMvc(o => { o.Filters.Add(new HandleAllExceptionsFilterFactory()); }); services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info { Title = "OffchainMonitor_Api", Version = "v1" }); 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, "OffchainMonitorApi.xml"); options.IncludeXmlComments(xmlPath); }); var builder = new SqlliteBinder().Bind(settings); builder.Populate(services); builder.RegisterType <TimerTriggerBinding>(); builder.RegisterType <QueueTriggerBinding>(); builder.RegisterType <CommitmentBroadcastCheck>(); var container = builder.Build(); var triggerHost = new TriggerHost(new AutofacServiceProvider(container)); triggerHost.ProvideAssembly(GetType().GetTypeInfo().Assembly); triggerHost.StartAndBlock(); return(new AutofacServiceProvider(container)); }
public void ConfigureServices(IServiceCollection services) { var settings = GeneralSettingsReader.ReadGeneralSettings <BaseSettings>(Configuration["ConnectionString"]); 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.AddMvc(); services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => { options.SingleApiVersion(new Info { Version = "v1", Title = "Lykke public API", TermsOfService = "https://lykke.com/city/terms_of_use", License = new License { Name = "Use under MIT", Url = "https://github.com/LykkeCity/LykkePublicAPI/blob/master/LICENSE" } }); }); }
public void Run() { var settings = GeneralSettingsReader.ReadGeneralSettings <GeneralSettings>(Configuration.GetConnectionString("Settings")); var containerBuilder = new AzureBinder().Bind(settings.ChronobankJobs); var ioc = containerBuilder.Build(); var triggerHost = new TriggerHost(new AutofacServiceProvider(ioc)); triggerHost.ProvideAssembly(GetType().GetTypeInfo().Assembly); var end = new ManualResetEvent(false); AssemblyLoadContext.Default.Unloading += ctx => { Console.WriteLine("SIGTERM recieved"); triggerHost.Cancel(); end.WaitOne(); }; triggerHost.Start().Wait(); end.Set(); }
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(); }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var settingsConnectionString = Configuration["SettingsConnString"]; var settingsContainer = Configuration["SettingsContainerName"]; var settingsFileName = Configuration["SettingsFileName"]; var connectionStringLogs = Configuration["LogsConnString"]; Log = new LogToTable(new AzureTableStorage <LogEntity>(connectionStringLogs, "LogCompPlatform", null)); try { Settings = GeneralSettingsReader.ReadGeneralSettings <BaseSettings>(settingsConnectionString, settingsContainer, settingsFileName); services.AddSingleton(Settings); } catch (Exception ex) { Log.WriteErrorAsync("Startup", "ReadSettingsFile", "Reading Settings File", ex).Wait(); } var connectionString = Settings.Azure.StorageConnString; CheckSettings(Settings, Log); try { // Add framework services. services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddAuthentication( options => { options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; }); var notificationEmailsQueueConnString = Settings.Notifications.EmailsQueueConnString; var notificationSlackQueueConnString = Settings.Notifications.SlackQueueConnString; services.AddApplicationInsightsTelemetry(Configuration); var builder = services.AddMvc(); builder.AddMvcOptions(o => { o.Filters.Add(new GlobalExceptionFilter(Log, notificationSlackQueueConnString)); }); services.RegisterLyykeServices(); //if (HostingEnvironment.IsProduction() && !string.IsNullOrEmpty(notificationEmailsQueueConnString) && // !string.IsNullOrEmpty(notificationSlackQueueConnString)) //{ // services.RegisterEmailNotificationServices(notificationEmailsQueueConnString); //} //else //{ services.RegisterInMemoryNotificationServices(); //} services.RegisterRepositories(connectionString, Log); JobScheduler.Start(connectionString, Log); } catch (Exception ex) { Log.WriteErrorAsync("Startup", "RegisterServices", "Registering Repositories and services", ex).Wait(); } }
static BaseSettings GetCurrentSettings() { return(GeneralSettingsReader.ReadGeneralSettings <BaseSettings>(ConfigurationManager.AppSettings["ConnectionString"])); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var settingsConnectionString = Configuration["SettingsConnString"]; var settingsContainer = Configuration["SettingsContainerName"]; var settingsFileName = Configuration["SettingsFileName"]; var connectionStringLogs = Configuration["LogsConnString"]; Log = new LogToTableRepository(new AzureTableStorage <LogEntity>(connectionStringLogs, "LogMarketMakersUI", null)); try { Settings = GeneralSettingsReader.ReadGeneralSettings <BaseSettings>(settingsConnectionString, settingsContainer, settingsFileName); } catch (Exception ex) { Log.WriteErrorAsync("Startup", "ReadSettingsFile", "Reading Settings File", ex).Wait(); } CheckSettings(Settings, Log); try { // Add framework services. services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddLocalization(options => options.ResourcesPath = "Translates"); services.AddMvc() .AddViewLocalization() .AddDataAnnotationsLocalization(); services.AddScoped <FilterFeaturesAccessAttribute>(); services.Configure <RequestLocalizationOptions>(options => { var supportedCultures = new List <CultureInfo> { new CultureInfo("en-US"), new CultureInfo("ru-RU") }; options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; } ); services.RegisterRepositories(Settings.Db.MarketMakerConnString, Log); services.RegisterLyykeServices(); } catch (Exception ex) { Log.WriteErrorAsync("Startup", "RegisterServices", "Registering Repositories and services", ex).Wait(); } }
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>(); }