Пример #1
0
        public async Task Send(string message, Uri link, IReadOnlyCollection <string> tags)
        {
            var sb = new StringBuilder();

            sb.Append(message);
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(link);
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(string.Join(" ", tags));

            try
            {
                var bot = new TelegramBotClient(_token);

                await bot.SendTextMessageAsync(_name, sb.ToString());

                _logger.Write(LogEventLevel.Information, $"Message was sent to Telegram channel `{_name}`: `{sb}`");
            }
            catch (Exception ex)
            {
                _logger.Write(LogEventLevel.Error, $"Error during send message to Telegram: `{sb}`", ex);
            }
        }
Пример #2
0
        public IServiceCollection Register(IServiceCollection services)
        {
            services.AddMemoryCache();

            services.AddSingleton <Core.Settings>(_ => _settings);
            services.AddSingleton <Core.Logging.ILogger>(_ => _logger);

            services.AddScoped <DatabaseContext>(_ => new DatabaseContext(_settings.ConnectionString));

            services.AddScoped(typeof(TelegramCrosspostManager));
            services.AddScoped(typeof(FacebookCrosspostManager));

            services.AddScoped(typeof(ILocalizationManager), typeof(LocalizationManager));
            services.AddScoped(typeof(IPublicationManager), typeof(PublicationManager));
            services.AddScoped(typeof(IUserManager), typeof(UserManager));
            services.AddScoped(typeof(IVacancyManager), typeof(VacancyManager));

            services.Configure <WebEncoderOptions>(options =>
            {
                options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
            });

            _logger.Write(LogLevel.Info, "DI container initialized");

            return(services);
        }
Пример #3
0
        public IServiceCollection Register(IServiceCollection services)
        {
            services.AddMemoryCache();

            services.AddEntityFrameworkMySql();

            services.AddDbContext <DatabaseContext>(options => options.UseMySql(_settings.ConnectionString));

            services.AddSingleton(_ => _settings);
            services.AddSingleton(_ => _logger);

            services.AddTransient <TelegramCrosspostManager>();
            services.AddTransient <FacebookCrosspostManager>();
            services.AddTransient <TwitterCrosspostManager>();

            services.AddScoped <ILocalizationManager, LocalizationManager>();
            services.AddScoped <IPublicationManager, PublicationManager>();
            services.AddScoped <IUserManager, UserManager>();
            services.AddScoped <IVacancyManager, VacancyManager>();

            services.AddScoped <IPublicationRepository, PublicationRepository>();
            services.AddScoped <ISettingsRepository, SettingsRepository>();
            services.AddScoped <ISocialRepository, SocialRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IVacancyRepository, VacancyRepository>();

            services.Configure <WebEncoderOptions>(options =>
            {
                options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
            });

            _logger.Write(LogLevel.Info, "DI container initialized");

            return(services);
        }