Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            SqlServer sqlServer = new SqlServer(Configuration);

            services.AddSingleton(sqlServer);

            EmployeeProvider userCache = new EmployeeProvider(sqlServer);

            services.AddSingleton(userCache);

            JsonSettings = new JsonSerializerSettings();
            JsonSettings.MissingMemberHandling = MissingMemberHandling.Error;
            JsonSettings.FloatFormatHandling   = FloatFormatHandling.Symbol;
            JsonSettings.FloatParseHandling    = FloatParseHandling.Decimal;
            JsonConvert.DefaultSettings        = new Func <JsonSerializerSettings>(() => JsonSettings);

            services.AddHostedService <TelegramHostedService>();
            services.AddHostedService <NotificationsHostedService>();
            services.AddHostedService <DiagHostedService>();

            services.AddHttpsRedirection(options =>
            {
                options.RedirectStatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status307TemporaryRedirect;
                options.HttpsPort          = 5101;
            });
        }
Пример #2
0
        public TelegramHostedService(EmployeeProvider employeeProvider, ILogger <TelegramHostedService> logger, SqlServer sqlServer, IConfiguration config)
        {
            this._config = Startup.Config.UserBot;

            this._employeeProvider = employeeProvider;
            this._logger           = logger;
            this._sqlServer        = sqlServer;

            if (this._config.ApiUrl != null)
            {
                _httpClient = new HttpClient(new ProxyMessageHandler(this._config.ApiUrl));
            }
            else
            {
                _httpClient = new HttpClient();
            }

            this._cts       = new CancellationTokenSource();
            _telegramClient = new Telegram.Bot.TelegramBotClient(this._config.Token, _httpClient);

            if (!TimeSpan.TryParse(this._config.TimeToCancelTurns, out this._timeToCancelTurns))
            {
                this._timeToCancelTurns = TimeSpan.FromHours(6);
            }
        }
Пример #3
0
        public NotificationsHostedService(EmployeeProvider employeeProvider, ILogger <NotificationsHostedService> logger, SqlServer sqlServer, IConfiguration config)
        {
            this._config = Startup.Config.UserBot;

            this._employeeProvider = employeeProvider;
            this._logger           = logger;
            this._sqlServer        = sqlServer;

            this._cts       = new CancellationTokenSource();
            _httpClient     = new HttpClient();
            _telegramClient = new Telegram.Bot.TelegramBotClient(this._config.Token, _httpClient);
        }