コード例 #1
0
        public static async Task Main(string[] args)
        {
            var builder = new HostBuilder()
                          .ConfigureAppConfiguration((hostContext, configApp) =>
            {
                configApp.AddJsonFile("appsettings.json", optional: true);
                configApp.AddJsonFile(
                    $"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json",
                    optional: true);
                configApp.AddEnvironmentVariables(prefix: "PREFIX_");
                configApp.AddCommandLine(args);
            })
                          .ConfigureServices((hostContext, services) => { services.AddHostedService <ArticleService>(); })
                          .ConfigureServices((hostContext, services) => { services.Configure <HostOptions>(option => { option.ShutdownTimeout = System.TimeSpan.FromSeconds(20); }); })
                          .ConfigureServices((hostContext, services) =>
            {
                var schedulerOptions = new ArticleSchedulerProperties();
                hostContext.Configuration.Bind("Properties", schedulerOptions);
                services.AddSingleton(schedulerOptions);
            })
                          .ConfigureLogging((hostingContext, logging) =>
            {
                logging.ClearProviders();
                logging.SetMinimumLevel(LogLevel.Trace);
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                if (hostingContext.HostingEnvironment.IsDevelopment())
                {
                    logging.AddConsole();
                    logging.AddDebug();
                }
            })
                          .UseNLog()
                          .UseConsoleLifetime();


            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (!(Debugger.IsAttached || ((IList)args).Contains("--console")))
                {
                    await builder.RunAsServiceAsync();
                }
                else
                {
                    await builder.RunConsoleAsync();
                }
            }
            else
            {
                await builder.RunConsoleAsync();
            }
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: QuantumArt/QP
        public void ConfigureServices(IServiceCollection services)
        {
            var qpOptions = new QPublishingOptions();

            Configuration.Bind("Properties", qpOptions);
            services.AddSingleton(qpOptions);
            QPConfiguration.Options = qpOptions;

            var formOptions = new FormOptions();

            Configuration.Bind("Form", formOptions);
            services.AddSingleton(formOptions);

            if (qpOptions.EnableArticleScheduler)
            {
                var schedulerOptions = new ArticleSchedulerProperties(qpOptions);
                Configuration.Bind("ArticleScheduler", schedulerOptions);
                services.AddSingleton(schedulerOptions);

                services.AddHostedService <S.ArticleService>();
            }

            var commonSchedulerProperties = new CommonSchedulerProperties();

            if (qpOptions.EnableCommonScheduler)
            {
                Configuration.Bind("CommonScheduler", commonSchedulerProperties);
                services.AddTransient <IUserSynchronizationService, UserSynchronizationService>();
            }
            services.AddSingleton(commonSchedulerProperties);
            services.AddQuartzService(commonSchedulerProperties.Name, Configuration.GetSection("CommonScheduler"));

            // used by Session middleware
            services.AddDistributedMemoryCache();
            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedProtoHeaderName = "X-FORWARDED-PROTO";
                options.ForwardedHeaders         =
                    ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
                // Only loopback proxies are allowed by default.
                // Clear that restriction because forwarders are enabled by explicit
                // configuration.
                options.KnownNetworks.Clear();
                options.KnownProxies.Clear();
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.Cookie.HttpOnly   = true;
                options.ExpireTimeSpan    = TimeSpan.FromMinutes(qpOptions.CookieTimeout);
                options.LoginPath         = new PathString("/Logon");
                options.LogoutPath        = new PathString("/Logon/Logout");
                options.AccessDeniedPath  = new PathString("/Logon");
                options.SlidingExpiration = true;
            });

            services.AddOptions();
            services.AddHttpContextAccessor();
            services.AddHttpClient();

            services.AddSingleton <IActionContextAccessor, ActionContextAccessor>();
            services.AddScoped <IUrlHelper>(x => {
                var actionContext = x.GetRequiredService <IActionContextAccessor>().ActionContext;
                var factory       = x.GetRequiredService <IUrlHelperFactory>();
                return(factory.GetUrlHelper(actionContext));
            });

            services.AddSession(options =>
            {
                options.IdleTimeout        = TimeSpan.FromSeconds(qpOptions.SessionTimeout);
                options.Cookie.HttpOnly    = true;
                options.Cookie.IsEssential = true;
            });

            services
            .AddMvc(options =>
            {
                options.ModelBinderProviders.Insert(0, new QpModelBinderProvider());
                options.EnableEndpointRouting = false;
            })
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                options.SerializerSettings.ContractResolver      = new DefaultContractResolver();
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("CustomerCodeSelected", policy => policy.RequireClaim("CustomerCode"));
            });

            // servicesn
            services
            .AddTransient <AuthenticationHelper>()
            .AddTransient <JsLanguageHelper>()
            .AddTransient <JsConstantsHelper>()
            .AddSingleton <ISearchGrammarParser, IronySearchGrammarParser>()
            .AddTransient <IStopWordList, StopWordList>()
            .AddTransient <IArticleSearchRepository, ArticleSearchRepository>()
            .AddTransient <ISearchInArticlesRepository, SearchInArticlesRepository>()
            .AddTransient <ISearchInArticlesService, SearchInArticlesService>()
            .AddTransient <IBackendActionLogRepository, AuditRepository>()
            .AddTransient <IBackendActionLogPagesRepository, AuditRepository>()
            .AddTransient <IButtonTracePagesRepository, AuditRepository>()
            .AddTransient <IRemovedEntitiesPagesRepository, AuditRepository>()
            .AddTransient <ISessionLogRepository, AuditRepository>()
            .AddTransient <IApplicationInfoRepository, ApplicationInfoRepository>()
            .AddTransient <IArticleRepository, ArticleRepository>()
            .AddTransient <IContentRepository, ContentRepository>()
            .AddTransient <IArticleSearchService, ArticleSearchService>()
            .AddTransient <IBackendActionLogService, BackendActionLogService>()
            .AddTransient <IButtonTraceService, ButtonTraceService>()
            .AddTransient <IRemovedEntitiesService, RemovedEntitiesService>()
            .AddTransient <ISessionLogService, SessionLogService>()
            .AddTransient <ICustomActionService, CustomActionService>()
            .AddTransient <IFieldDefaultValueService, FieldDefaultValueService>()
            .AddTransient <IRecreateDynamicImagesService, RecreateDynamicImagesService>()
            .AddTransient <IUserService, UserService>()
            .AddTransient <IUserGroupService, UserGroupService>()
            .AddTransient <IXmlDbUpdateLogRepository, XmlDbUpdateLogRepository>()
            .AddTransient <IXmlDbUpdateActionsLogRepository, XmlDbUpdateActionsLogRepository>()
            .AddTransient <IXmlDbUpdateLogService, XmlDbUpdateLogService>()
            .AddTransient <IArticleService, A.ArticleService>()
            .AddTransient <IContentService, ContentService>()
            .AddTransient <IXmlDbUpdateHttpContextProcessor, XmlDbUpdateHttpContextProcessor>()
            .AddTransient <IXmlDbUpdateActionCorrecterService, XmlDbUpdateActionCorrecterService>()
            .AddTransient <INotificationService, NotificationService>()
            .AddTransient <IActionPermissionTreeService, ActionPermissionTreeService>()
            .AddTransient <ISecurityService, SecurityService>()
            .AddTransient <IVisualEditorService, VisualEditorService>()
            .AddTransient <IQpPluginService, QpPluginService>()
            .AddTransient <IWorkflowService, WorkflowService>()
            .AddTransient <IStatusTypeService, StatusTypeService>()
            .AddTransient <IPageTemplateService, PageTemplateService>()
            .AddTransient <IPageService, PageService>()
            .AddTransient <IObjectService, ObjectService>()
            .AddTransient <IFormatService, FormatService>()
            .AddTransient <ProcessRemoteValidationIf>() //preload XAML validation
            .AddTransient <ResourceDictionary>()        // preload QA.Configuration
            .AddTransient <QuartzService>()
            ;

            services
            .AddTransient <WorkflowPermissionService>()
            .AddTransient <SitePermissionService>()
            .AddTransient <SiteFolderPermissionService>()
            .AddTransient <ContentPermissionService>()
            .AddTransient <ChildContentPermissionService>()
            .AddTransient <ArticlePermissionService>()
            .AddTransient <ChildArticlePermissionService>()
            .AddTransient <EntityTypePermissionService>()
            .AddTransient <EntityTypePermissionChangeService>()
            .AddTransient <ActionPermissionService>()
            .AddTransient <ActionPermissionChangeService>()
            ;

            services
            .AddTransient <ISearchGrammarParser, IronySearchGrammarParser>()
            .AddTransient <ArticleFullTextSearchQueryParser>()
            ;

            services
            .AddTransient <IInterfaceNotificationProvider, InterfaceNotificationProvider>()
            .AddTransient <IExternalInterfaceNotificationService, ExternalInterfaceNotificationService>()
            .AddTransient <IExternalSystemNotificationService, ExternalSystemNotificationService>()
            .AddTransient <ISchedulerCustomerCollection, SchedulerCustomerCollection>()
            .AddTransient <ICommonUserService, CommonUserService>()
            .AddTransient <ElasticCdcImportService>()
            .AddTransient <TarantoolCdcImportService>()
            .AddTransient <IDbService, DbService>()
            ;

            RegisterMultistepActionServices(services);
        }