Beispiel #1
0
 public ProjectsController(ProjectList projectList)
 {
     _projectList = projectList;
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider provider, IHubContext <ProjectsHub> projectsHub, ProjectList projectList, AppDBContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Identity setup
            // Add routing to make SignalR hubs work
            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(config =>
            {
                config.MapHub <ProjectsHub>("/ProjectsHub");
            });


            app.UseMvc();


            // Ensure database was created
            if (dbContext.Database.EnsureCreated())
            {
                // Add roles
                provider.GetService <RoleManager <IdentityRole> >().CreateAsync(new IdentityRole("User")).Wait();
                provider.GetService <RoleManager <IdentityRole> >().CreateAsync(new IdentityRole("Admin")).Wait();
            }
            ;


            // Not using async await because it will probably cause a race condition.
            // In addition there is no point in async call here because here is where the server is being set-up
            provider.GetService <ProjectList>().UpdateListAsync().Wait();

            // Add notifications
            provider.GetService <Notifier>().Notifications.Add(new NotificationItem((int)TimeSpan.FromMinutes(15).TotalMilliseconds,
                                                                                    async() =>
            {
                await projectList.UpdateListAsync();

                await projectsHub.Clients.All.SendAsync("ProjectListUpdated", projectList.Projects);
            }, "ProjectLoader"));
        }