Пример #1
0
        public static void Main(string[] args)
        {
            try
            {
                var appSettings = AppSettingsReader.ReadSettings();

                IServiceCollection services = new ServiceCollection();

                var log = new LogToTable(new AzureTableStorage <LogEntity>(appSettings.ConnectionString, "Log", null));

                services.AddInstance <ILog>(log);
                services.BindAzureRepositories(appSettings.ConnectionString, log);
                services.AddInstance(new BitcoinRpcClient(appSettings.BitcoinRpcSettings));

                var serviceProvider = services.BuildServiceProvider();
                var start           = ActivatorUtilities.CreateInstance <JobsBlockTransfer>(serviceProvider);
                //var start = ioc.CreateInstance<JobsBlockTransfer>();
                start.Start(appSettings.FirstHashBlock);
                //Console.WriteLine("Started...");
                //Console.ReadLine();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                //Console.ReadLine();
            }
        }
Пример #2
0
        public static IDependencyResolver Create()
        {
            var result = new MyDependencyResolver();

#if DEBUG
            var log = new LogToConsole();
            result.IoC.BindAzureReposInMem();
            result.IoC.BinMockAzureDebug();
#else
            var log = new LogToTable(new AzureTableStorage <LogEntity>(Settings.ConnectionString, "LogApi", null));

            result.IoC.BindAzureRepositories(Settings.ConnectionString, Settings.ConnectionString, log);
            result.IoC.BindMockAzureRepositories(Settings.ConnectionString, log);
#endif

            result.IoC.BindLykkeWalletServices();
            result.IoC.BindMockServices();


            log.WriteInfo("ApiDependencies", "Create", "Create", "Create");

            GetIdentity = ctr =>
            {
                var ctx = ctr as ApiController;
                return(ctx?.User.Identity.Name);
            };

            return(result);
        }
Пример #3
0
        public static IUnityContainer RegisterLogs(IUnityContainer container, IBaseSettings settings, string logsConnString)
        {
            var logToTable = new LogToTable(new AzureTableStorage <LogEntity>(logsConnString, "EmailsQueueReader", null));

            container.RegisterInstance(logToTable);
            container.RegisterType <LogToConsole>();

            container.RegisterType <ILog, LogToTableAndConsole>();

            return(container);
        }
Пример #4
0
        public ContainerBuilder Bind(BaseSettings settings)
        {
            var logToTable = new LogToTable(new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, "LogChronobankJobError", null),
                                            new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, "LogChronobankJobWarning", null),
                                            new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, "LogChronobankJobInfo", null));
            var log = new LogToTableAndConsole(logToTable, new LogToConsole());
            var ioc = new ContainerBuilder();

            InitContainer(ioc, settings, log);
            return(ioc);
        }
Пример #5
0
        public static void RegisterAzureLogs(this IServiceCollection services, IBaseSettings settings, string logPrefix)
        {
            var logToTable = new LogToTable(
                new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, Constants.StoragePrefix + logPrefix + "Error", null),
                new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, Constants.StoragePrefix + logPrefix + "Warning", null),
                new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, Constants.StoragePrefix + logPrefix + "Info", null));

            services.AddSingleton(logToTable);
            services.AddTransient <LogToConsole>();

            services.AddTransient <ILog, LogToTableAndConsole>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            ILog log = new LogToConsole();

            try
            {
                // Add framework services.
                services.AddMvc();

                // Add swagger generator
                services.AddSwaggerGen(x => { x.SwaggerDoc(ApiVersion, new Info {
                        Title = ApiTitle, Version = ApiVersion
                    }); });

                // Load settings
                var settingsUrl    = Configuration["SettingsUrl"];
                var httpClient     = new HttpClient();
                var response       = httpClient.GetAsync(settingsUrl).Result;
                var settingsString = response.Content.ReadAsStringAsync().Result;
                var settings       = Newtonsoft.Json.JsonConvert.DeserializeObject <AppSettings>(settingsString);

                if (null != settings.EmailSenderSettings.Log)
                {
                    var logToTable = new LogToTable(settings.EmailSenderSettings.Log.ConnectionString,
                                                    settings.EmailSenderSettings.Log.TableName, log);
                    log = new LogToAll(log, logToTable);
                }

                // Register dependencies, populate the services from
                // the collection, and build the container. If you want
                // to dispose of the container at the end of the app,
                // be sure to keep a reference to it as a property or field.
                var builder = new ContainerBuilder();

                builder.RegisterInstance(
                    new AzureTableStorage <PartnerSmtpSettings>(settings.EmailSenderSettings.Partners.ConnectionString,
                                                                settings.EmailSenderSettings.Partners.TableName, log))
                .As <INoSQLTableStorage <PartnerSmtpSettings> >()
                .SingleInstance();
                builder.Populate(services);
                ApplicationContainer = builder.Build();

                // Create the IServiceProvider based on the container.
                return(new AutofacServiceProvider(ApplicationContainer));
            }
            catch (Exception ex)
            {
                log.WriteFatalErrorAsync(nameof(EmailSender), nameof(Startup), nameof(ConfigureServices), ex, DateTime.UtcNow).Wait();
                throw;
            }
        }
Пример #7
0
        public static IUnityContainer RegisterLogs(IUnityContainer container, IBaseSettings settings, string logPrefix)
        {
            var logToTable = new LogToTable(
                new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, logPrefix + "Error", null),
                new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, logPrefix + "Warning", null),
                new AzureTableStorage <LogEntity>(settings.Db.LogsConnString, logPrefix + "Info", null));

            container.RegisterInstance(logToTable);
            container.RegisterType <LogToConsole>();

            container.RegisterType <ILog, LogToTableAndConsole>();

            return(container);
        }
Пример #8
0
        public static void RegisterTypes(IUnityContainer container)
        {
            var file     = File.ReadAllText(@"..\..\..\..\settings\generalsettings.json");
            var settings = GeneralSettingsReader.ReadSettingsFromData <BaseSettings>(file);

            container.RegisterInstance <IBaseSettings>(settings);

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

            container.RegisterInstance <ILog>(log);

            container.RegisterType <IContractService, ContractService>();
            container.RegisterType <IPaymentService, PaymentService>();
            container.RegisterType <IEthereumQueueOutService, EthereumQueueOutService>();
        }
Пример #9
0
        public ContainerBuilder Bind(WithdrawalRequestSchedulerSettings settings)
        {
            var logToTable = new LogToTable(new AzureTableStorage <LogEntity>(settings.LogsConnString, "LogWithdrawalRequestSchedulerError", null),
                                            new AzureTableStorage <LogEntity>(settings.LogsConnString, "LogWithdrawalRequestSchedulerWarning", null),
                                            new AzureTableStorage <LogEntity>(settings.LogsConnString, "LogWithdrawalRequestSchedulerInfo", null));

#if DEBUG
            var log = new LogToTableAndConsole(logToTable, new LogToConsole());
#else
            var log = logToTable;
#endif
            var ioc = new ContainerBuilder();
            InitContainer(ioc, settings, log);
            return(ioc);
        }
Пример #10
0
        public static IUnityContainer RegisterComponents(IBaseSettings settings)
        {
            var container = new UnityContainer();

            container.RegisterInstance(settings);

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

            container.RegisterInstance(logToTable);
            container.RegisterType <LogToConsole>();

            container.RegisterType <ILog, LogToTableAndConsole>();

            container.RegisterType <IContractService, ContractService>();
            container.RegisterType <IPaymentService, PaymentService>();
            container.RegisterType <IContractQueueService, ContractQueueService>();
            container.RegisterType <IEmailNotifierService, EmailNotifierService>();

            container.RegisterType <Func <string, IQueueExt> >(new InjectionFactory(c =>
                                                                                    new Func <string, IQueueExt>(x =>
            {
                switch (x)
                {
                case Constants.EthereumContractQueue:
                case Constants.EthereumOutQueue:
                    return(new AzureQueueExt(settings.Db.EthereumOutQueueConnString, x));

                case Constants.EmailNotifierQueue:
                    return(new AzureQueueExt(settings.Db.ClientPersonalInfoConnString, x));

                default:
                    throw new Exception("Queue is not registered");
                }
            })));

            return(container);
        }
Пример #11
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>();
        }