/// <summary>
 /// Add localization module
 /// </summary>
 /// <typeparam name="TContext"></typeparam>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IServiceCollection AddLocalizationModuleStorage <TContext>(this IServiceCollection services, Action <DbContextOptionsBuilder> options)
     where TContext : DbContext, ILocalizationContext
 {
     services.AddScopedContextFactory <ILocalizationContext, TContext>();
     services.RegisterAuditFor <TContext>("Localization module");
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TContext>();
     };
     return(services);
 }
Пример #2
0
 /// <summary>
 /// Register commerce storage
 /// </summary>
 /// <typeparam name="TContext"></typeparam>
 /// <param name="services"></param>
 /// <param name="storageOptions"></param>
 /// <returns></returns>
 public static IServiceCollection RegisterCommerceStorage <TContext>(this IServiceCollection services,
                                                                     Action <DbContextOptionsBuilder> storageOptions)
     where TContext : DbContext, ICommerceContext
 {
     services.AddDbContext <TContext>(storageOptions);
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TContext>();
     };
     return(services);
 }
 /// <summary>
 /// Register storage
 /// </summary>
 /// <typeparam name="TTaskManagerContext"></typeparam>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IServiceCollection AddTaskModuleStorage <TTaskManagerContext>(this IServiceCollection services, Action <DbContextOptionsBuilder> options)
     where TTaskManagerContext : DbContext, ITaskManagerContext
 {
     services.AddScopedContextFactory <ITaskManagerContext, TTaskManagerContext>();
     services.AddDbContext <TTaskManagerContext>(options, ServiceLifetime.Transient);
     services.RegisterAuditFor <ITaskManagerContext>($"{nameof(TaskManager)} module");
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TTaskManagerContext>();
     };
     return(services);
 }
Пример #4
0
 /// <summary>
 /// Add module storage
 /// </summary>
 /// <typeparam name="TContext"></typeparam>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IServiceCollection AddProcessesModuleStorage <TContext>(this IServiceCollection services, Action <DbContextOptionsBuilder> options)
     where TContext : DbContext, IProcessesDbContext
 {
     Arg.NotNull(options, nameof(AddProcessesModuleStorage));
     services.AddDbContext <TContext>(options);
     services.RegisterAuditFor <IProcessesDbContext>("Processes module");
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TContext>();
     };
     return(services);
 }
 /// <summary>
 /// Add country module storage
 /// </summary>
 /// <typeparam name="TContext"></typeparam>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IServiceCollection AddCountryModuleStorage <TContext>(this IServiceCollection services, Action <DbContextOptionsBuilder> options)
     where TContext : DbContext, ICountryContext
 {
     services.AddTransient <ICountryContext, TContext>();
     services.AddDbContext <TContext>(options);
     services.RegisterAuditFor <TContext>("Countries module");
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TContext>();
     };
     return(services);
 }
        /// <summary>
        /// Add identity server
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IServiceCollection AddIdentityClientsModule <TUser, TConfiguration, TPersisted, TClientsConfiguration>(this IServiceCollection services, IConfiguration configuration)
            where TClientsConfiguration : DefaultClientsConfigurator
            where TUser : GearUser
            where TConfiguration : ConfigurationDbContext <TConfiguration>, IClientsContext
            where TPersisted : PersistedGrantDbContext <TPersisted>, IClientsPersistedGrantContext
        {
            var configurator       = Activator.CreateInstance <TClientsConfiguration>();
            var migrationsAssembly = typeof(TConfiguration).Assembly.GetName().Name;

            void DbOptions(DbContextOptionsBuilder builder) => builder.RegisterIdentityStorage(configuration, migrationsAssembly);

            services.AddIdentityServer(options =>
            {
                options.Authentication.CookieLifetime = TimeSpan.FromHours(2);
                options.Events.RaiseSuccessEvents     = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseErrorEvents       = true;
            })
            .AddCertificate()
            .AddAspNetIdentity <TUser>()
            .AddConfigurationStore <TConfiguration>(options =>
            {
                options.DefaultSchema      = IdentityConfig.DEFAULT_SCHEMA;
                options.ConfigureDbContext = DbOptions;
            })
            .AddOperationalStore <TPersisted>(options =>
            {
                options.DefaultSchema        = IdentityConfig.DEFAULT_SCHEMA;
                options.ConfigureDbContext   = DbOptions;
                options.EnableTokenCleanup   = true;
                options.TokenCleanupInterval = 30;
            })
            .AddResourceStore <CustomResourceStore>()
            .AddClientStore <CustomClientStore>();
            //.AddResourceOwnerValidator<CustomResourceOwnerPasswordValidator>();

            services.AddTransient <ICorsPolicyService, CustomCorsPolicyService>();
            services.AddGearSingleton <IClientsContext, TConfiguration>();
            services.AddGearSingleton <IClientsPersistedGrantContext, TPersisted>();

            SystemEvents.Database.OnAllMigrate += (sender, args) =>
            {
                GearApplication.GetHost <IWebHost>()
                .MigrateDbContext <TPersisted>()
                .MigrateDbContext <TConfiguration>((context, servicesProvider) =>
                {
                    ClientsSeeder.SeedAsync(servicesProvider, configurator)
                    .Wait();
                });
            };

            return(services);
        }
Пример #7
0
 /// <summary>
 /// Register module storage
 /// </summary>
 /// <typeparam name="TContext"></typeparam>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static INotificationServiceCollection AddNotificationSubscriptionModuleStorage <TContext>(this INotificationServiceCollection services, Action <DbContextOptionsBuilder> options)
     where TContext : DbContext, INotificationSubscriptionsDbContext
 {
     Arg.NotNull(services, nameof(AddNotificationSubscriptionModuleStorage));
     services.Services.AddDbContext <TContext>(options);
     services.Services.AddScopedContextFactory <INotificationSubscriptionsDbContext, TContext>();
     services.Services.RegisterAuditFor <INotificationSubscriptionsDbContext>($"{nameof(Notification)} module");
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TContext>();
     };
     return(services);
 }
Пример #8
0
 public static IServiceCollection AddFileBoxModuleStorage <TFileBoxContext>(this IServiceCollection services, Action <DbContextOptionsBuilder> options, IConfiguration configuration)
     where TFileBoxContext : DbContext, IFileBoxContext
 {
     services.AddScopedContextFactory <IFileBoxContext, TFileBoxContext>();
     services.AddDbContext <TFileBoxContext>(options, ServiceLifetime.Transient);
     services.RegisterAuditFor <IFileBoxContext>("File box module");
     services.ConfigureWritable <List <FileBoxSettingsViewModel> >(configuration.GetSection("FileBoxSettings"));
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TFileBoxContext>();
     };
     return(services);
 }
Пример #9
0
 /// <summary>
 /// Add dashboard module storage
 /// </summary>
 /// <typeparam name="TDbContext"></typeparam>
 /// <param name="configuration"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IDashboardServiceCollection AddDashboardModuleStorage <TDbContext>(
     this IDashboardServiceCollection configuration, Action <DbContextOptionsBuilder> options)
     where TDbContext : DbContext, IDashboardDbContext
 {
     Arg.NotNull(configuration.Services, nameof(AddDashboardModuleStorage));
     configuration.Services.AddDbContext <TDbContext>(options, ServiceLifetime.Transient);
     configuration.Services.AddScopedContextFactory <IDashboardDbContext, TDbContext>();
     SystemEvents.Database.OnMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TDbContext>();
     };
     return(configuration);
 }
 /// <summary>
 /// Add Crm storage
 /// </summary>
 /// <typeparam name="TDbContext"></typeparam>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IServiceCollection AddCrmModuleStorage <TDbContext>(
     this IServiceCollection services, Action <DbContextOptionsBuilder> options)
     where TDbContext : DbContext, ICrmContext
 {
     Arg.NotNull(services, nameof(AddCrmModuleStorage));
     services.AddDbContext <TDbContext>(options, ServiceLifetime.Transient);
     services.AddGearTransient <ICrmContext, TDbContext>();
     SystemEvents.Database.OnMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TDbContext>();
     };
     return(services);
 }
 /// <summary>
 /// Register module storage
 /// </summary>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IServiceCollection AddDynamicReportModuleStorage <TReportContext>(this IServiceCollection services,
                                                                                 Action <DbContextOptionsBuilder> options)
     where TReportContext : DbContext, IReportContext
 {
     services.AddDbContext <TReportContext>(options);
     services.AddScopedContextFactory <IReportContext, TReportContext>();
     services.RegisterAuditFor <IReportContext>($"{nameof(Report)} module");
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TReportContext>();
     };
     return(services);
 }
        /// <summary>
        /// Add user activity module storage
        /// </summary>
        /// <typeparam name="TContext"></typeparam>
        /// <param name="services"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IServiceCollection AddUserActivityModuleStorage <TContext>(this IServiceCollection services,
                                                                                 Action <DbContextOptionsBuilder> options)
            where TContext : DbContext, IActivityContext
        {
            services.AddDbContext <TContext>(options);
            services.AddScopedContextFactory <IActivityContext, TContext>();

            SystemEvents.Database.OnAllMigrate += (sender, args) =>
            {
                GearApplication.GetHost <IWebHost>().MigrateDbContext <TContext>();
            };

            return(services);
        }
Пример #13
0
        /// <summary>
        /// Add module storage
        /// </summary>
        /// <typeparam name="TPageContext"></typeparam>
        /// <param name="services"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IServiceCollection AddPageModuleStorage <TPageContext>(this IServiceCollection services,
                                                                             Action <DbContextOptionsBuilder> options)
            where TPageContext : DbContext, IDynamicPagesContext
        {
            services.AddScopedContextFactory <IDynamicPagesContext, TPageContext>();
            services.AddDbContext <TPageContext>(options);
            services.RegisterAuditFor <IDynamicPagesContext>("Page module");

            SystemEvents.Database.OnMigrate += (sender, args) =>
            {
                GearApplication.GetHost <IWebHost>().MigrateDbContext <TPageContext>();
            };
            return(services);
        }
 /// <summary>
 /// Add calendar module storage
 /// </summary>
 /// <typeparam name="TDbContext"></typeparam>
 /// <param name="configuration"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static CalendarServiceCollection AddCalendarModuleStorage <TDbContext>(
     this CalendarServiceCollection configuration, Action <DbContextOptionsBuilder> options)
     where TDbContext : DbContext, ICalendarDbContext
 {
     Arg.NotNull(configuration.Services, nameof(AddCalendarModuleStorage));
     configuration.Services.AddDbContext <TDbContext>(options, ServiceLifetime.Transient);
     configuration.Services.AddScopedContextFactory <ICalendarDbContext, TDbContext>();
     configuration.Services.RegisterAuditFor <ICalendarDbContext>($"{nameof(Calendar)} module");
     SystemEvents.Database.OnAllMigrate += (sender, args) =>
     {
         GearApplication.GetHost <IWebHost>().MigrateDbContext <TDbContext>();
     };
     return(configuration);
 }
        /// <summary>
        /// Use gear app
        /// </summary>
        /// <param name="app"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static IGearAppBuilder UseGearWebApp(this IApplicationBuilder app, Action <GearAppBuilderConfig> config)
        {
            var configuration = new GearAppBuilderConfig();

            config(configuration);

            using (var serviceScope = app.ApplicationServices
                                      .GetRequiredService <IServiceScopeFactory>()
                                      .CreateScope())
            {
                var sp          = serviceScope.ServiceProvider;
                var environment = sp.GetService <IHostingEnvironment>();
                GearWebApplication.IsConfigured(environment);

                var lifeTimeService = serviceScope.ServiceProvider.GetService <IApplicationLifetime>();
                lifeTimeService.RegisterAppEvents(app, configuration.AppName);

                //----------------------------------Localization Usage-------------------------------------

                var languages = serviceScope.ServiceProvider.GetService <IOptionsSnapshot <LocalizationConfig> >();
                app.UseLocalizationModule(languages);
            }

            if (GearApplication.IsHostedOnLinux())
            {
                app.UseForwardedHeaders(new ForwardedHeadersOptions
                {
                    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
                });
            }

            if (configuration.HostingEnvironment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            //-----------------------Custom url redirection Usage-------------------------------------
            if (configuration.UseCustomUrlRewrite)
            {
                app.UseUrlRewriteModule();
            }

            //----------------------------------Origin Cors Usage-------------------------------------
            if (configuration.UseDefaultCorsConfiguration)
            {
                app.UseConfiguredCors();
            }

            app.UseAuthentication()
            .UseIdentityServer();

            //custom rules
            app.UseAppMvc(configuration.Configuration, configuration.CustomMapRules);

            //--------------------------------------Swagger Usage-------------------------------------
            if (configuration.SwaggerConfiguration.UseSwaggerUI &&
                (configuration.SwaggerConfiguration.UseOnlyInDevelopment && configuration.HostingEnvironment.IsDevelopment() || !configuration.SwaggerConfiguration.UseOnlyInDevelopment))
            {
                app.UseSwagger()
                .UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "GEAR API v1.0");
                });
            }

            //----------------------------------Static files Usage-------------------------------------
            if (configuration.AppFileConfiguration.UseDefaultFiles)
            {
                app.UseDefaultFiles();
            }

            if (configuration.AppFileConfiguration.UseStaticFile)
            {
                app.UseStaticFiles();
            }

            //--------------------------------------Use compression-------------------------------------
            if (configuration.UseResponseCompression && configuration.HostingEnvironment.IsProduction())
            {
                app.UseResponseCompression();
            }


            //---------------------------------------SignalR Usage-------------------------------------
            if (configuration.SignlarAppConfiguration.UseDefaultSignlarConfiguration)
            {
                app.UseSignalRModule(configuration.SignlarAppConfiguration.Path);
            }

            return(new GearAppBuilder(app.ApplicationServices));
        }