static async Task RunAsync()
        {
            SchedulerStartup scheduler = null;

            try {
                scheduler = _container.Resolve <SchedulerStartup>();

                await scheduler.ConfigScheduler();

                _logger.LogInformation("Scheduler started");
                _manualReset.Wait();
            }
            catch (Exception e) {
                _logger.LogError(e, "Scheduler error");
            }
            finally {
                scheduler?.Dispose();
            }
        }
Beispiel #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime,
                              IConfiguration configuration, IOptionsBinder optionsBinder)
        {
            app.UseCors(builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyHeader()
                .AllowAnyMethod();
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            var quartz = new SchedulerStartup();

            lifetime.ApplicationStarted.Register(quartz.Start);
            lifetime.ApplicationStopping.Register(quartz.Stop);


            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            app.UseMiddleware <LanguageMiddleware>(optionsBinder);

            app.UseAuthentication();
            app.UseStaticFiles();
            app.UseWebSockets();

            app.Use(async(context, next) =>
            {
                var rM         = context.RequestServices.GetService <IRoleManager>();
                var aL         = context.RequestServices.GetService <IActivityLogger>();
                var iP         = context.RequestServices.GetService <ILocateByIpAddress>();
                var userName   = context.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
                var verifiedBy = context.User.Claims.Where(c => c.Type == "verifiedBy").Select(c => c.Value).FirstOrDefault();
                if (string.IsNullOrEmpty(userName))
                {
                    await next.Invoke();
                }
                else
                {
                    await aL.Log(userName);
                    var ipAddress = context.Request.HttpContext.Connection.RemoteIpAddress.ToString();
                    await iP.Locate(userName, ipAddress, verifiedBy);
                    var success = await rM.CheckValidity(userName, verifiedBy);
                    if (!success)
                    {
                        context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                        await next.Invoke();
                    }
                    else
                    {
                        await next.Invoke();
                    }
                }
            });
            app.Use(async(context, next) =>
            {
                if (!context.WebSockets.IsWebSocketRequest)
                {
                    await next.Invoke();
                }
                else
                {
                    var repo = context.RequestServices.GetService <IEntityRepository>();
                    await context.Map(repo);
                }
            });
            app.UseMvcWithDefaultRoute();
        }