コード例 #1
0
        /// <summary>
        /// Initialize engine
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        public static void Initialize(IServiceCollection services, IConfiguration configuration)
        {
            //set base application path
            var provider           = services.BuildServiceProvider();
            var hostingEnvironment = provider.GetRequiredService <IWebHostEnvironment>();
            var config             = new GrandConfig();

            configuration.GetSection("Grand").Bind(config);

            CommonHelper.WebRootPath         = hostingEnvironment.WebRootPath;
            CommonHelper.BaseDirectory       = hostingEnvironment.ContentRootPath;
            CommonHelper.CacheTimeMinutes    = config.DefaultCacheTimeMinutes;
            CommonHelper.CookieAuthExpires   = config.CookieAuthExpires > 0 ? config.CookieAuthExpires : 24 * 365;
            CommonHelper.AllowToJsonResponse = config.AllowToJsonResponse;

            //register mongo mappings
            MongoDBMapperConfiguration.RegisterMongoDBMappings();

            //initialize plugins
            var mvcCoreBuilder = services.AddMvcCore();
            //PluginManager.Initialize(mvcCoreBuilder, config);

            //initialize CTX sctipts
            //RoslynCompiler.Initialize(mvcCoreBuilder.PartManager, config);
        }
コード例 #2
0
 public RedisMessageBus(ISubscriber subscriber, IServiceProvider serviceProvider, GrandConfig grandConfig)
 {
     _subscriber      = subscriber;
     _serviceProvider = serviceProvider;
     _grandConfig     = grandConfig;
     SubscribeAsync();
 }
コード例 #3
0
        /// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration root of the application</param>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            var config = new GrandConfig();

            configuration.GetSection("Grand").Bind(config);

            //add settings
            services.AddSettings();

            //compression
            services.AddResponseCompression();

            //add options feature
            services.AddOptions();

            //add HTTP sesion state feature
            services.AddHttpSession(config);

            //add anti-forgery
            services.AddAntiForgery(config);

            //add localization
            services.AddLocalization();

            //add theme support
            services.AddThemes();

            //add WebEncoderOptions
            services.AddWebEncoder();
        }
コード例 #4
0
        private void RegisterMediaService(IServiceCollection serviceCollection, GrandConfig config)
        {
            serviceCollection.AddScoped <IMimeMappingService, MimeMappingService>(x =>
            {
                var provider = new FileExtensionContentTypeProvider();
                return(new MimeMappingService(provider));
            });

            //picture service
            var useAzureBlobStorage  = !String.IsNullOrEmpty(config.AzureBlobStorageConnectionString);
            var useAmazonBlobStorage = (!String.IsNullOrEmpty(config.AmazonAwsAccessKeyId) && !String.IsNullOrEmpty(config.AmazonAwsSecretAccessKey) && !String.IsNullOrEmpty(config.AmazonBucketName) && !String.IsNullOrEmpty(config.AmazonRegion));

            if (useAzureBlobStorage)
            {
                //Windows Azure BLOB
                serviceCollection.AddScoped <IPictureService, AzurePictureService>();
            }
            else if (useAmazonBlobStorage)
            {
                //Amazon S3 Simple Storage Service
                serviceCollection.AddScoped <IPictureService, AmazonPictureService>();
            }
            else
            {
                //standard file system
                serviceCollection.AddScoped <IPictureService, PictureService>();
            }

            serviceCollection.AddScoped <IDownloadService, DownloadService>();
        }
コード例 #5
0
        /// <summary>
        /// Register mapping
        /// </summary>
        /// <param name="config">Config</param>
        protected virtual void RegisterMapperConfiguration(GrandConfig config)
        {
            //dependencies
            var typeFinder = new WebAppTypeFinder();

            //register mapper configurations provided by other assemblies
            var mcTypes     = typeFinder.FindClassesOfType <IMapperConfiguration>();
            var mcInstances = new List <IMapperConfiguration>();

            foreach (var mcType in mcTypes)
            {
                mcInstances.Add((IMapperConfiguration)Activator.CreateInstance(mcType));
            }
            //sort
            mcInstances = mcInstances.AsQueryable().OrderBy(t => t.Order).ToList();
            //get configurations
            var configurationActions = new List <Action <IMapperConfigurationExpression> >();

            foreach (var mc in mcInstances)
            {
                configurationActions.Add(mc.GetConfiguration());
            }
            //register
            AutoMapperConfiguration.Init(configurationActions);
        }
コード例 #6
0
        /// <summary>
        /// Register MongoDB mappings
        /// </summary>
        /// <param name="config">Config</param>
        public static void RegisterMongoDBMappings(GrandConfig config)
        {
            BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128));
            BsonSerializer.RegisterSerializer(typeof(decimal?), new NullableSerializer <decimal>(new DecimalSerializer(BsonType.Decimal128)));
            BsonSerializer.RegisterSerializer(typeof(DateTime), new BsonUtcDateTimeSerializer());

            //global set an equivalent of [BsonIgnoreExtraElements] for every Domain Model
            var cp = new ConventionPack();

            cp.Add(new IgnoreExtraElementsConvention(true));
            ConventionRegistry.Register("ApplicationConventions", cp, t => true);

            //BsonClassMap.RegisterClassMap<ProductCategory>(cm =>
            //{
            //    cm.AutoMap();
            //    cm.UnmapMember(c => c.ProductId);
            //});

            //BsonClassMap.RegisterClassMap<ProductManufacturer>(cm =>
            //{
            //    cm.AutoMap();
            //    cm.UnmapMember(c => c.ProductId);
            //});

            //BsonClassMap.RegisterClassMap<CustomerReminderHistory>(cm =>
            //{
            //    cm.AutoMap();
            //    cm.UnmapMember(c => c.ReminderRule);
            //    cm.UnmapMember(c => c.HistoryStatus);
            //});
        }
コード例 #7
0
 public InstallController(GrandConfig config, ICacheManager cacheManager,
                          IServiceProvider serviceProvider)
 {
     _config          = config;
     _cacheManager    = cacheManager;
     _serviceProvider = serviceProvider;
 }
コード例 #8
0
 public void Register(ContainerBuilder builder, ITypeFinder typeFinder, GrandConfig config)
 {
     builder.RegisterType <VPAPlugin>().InstancePerLifetimeScope();
     builder.RegisterType <ProductService>().As <IProductService>().InstancePerLifetimeScope();
     builder.RegisterType <ProductServiceOver>().As <Grand.Services.Catalog.IProductService>().InstancePerLifetimeScope();
     builder.RegisterType <GetSearchProductsQueryHandlerOver>().As <IRequestHandler <GetSearchProductsQuery, (IPagedList <Core.Domain.Catalog.Product>, IList <string>)> >().InstancePerLifetimeScope();
 }
コード例 #9
0
        /// <summary>
        /// Configure static file serving
        /// </summary>
        /// <param name="application">Builder for configuring an application's request pipeline</param>
        public static void UseGrandStaticFiles(this IApplicationBuilder application, GrandConfig grandConfig)
        {
            //static files
            application.UseStaticFiles(new StaticFileOptions {

                OnPrepareResponse = ctx =>
                {
                    if (!String.IsNullOrEmpty(grandConfig.StaticFilesCacheControl))
                        ctx.Context.Response.Headers.Append(HeaderNames.CacheControl, grandConfig.StaticFilesCacheControl);
                }

            });

            //themes
            application.UseStaticFiles(new StaticFileOptions {
                FileProvider = new PhysicalFileProvider(CommonHelper.MapPath("Themes")),
                RequestPath = new PathString("/Themes"),
                OnPrepareResponse = ctx =>
                {
                    if (!String.IsNullOrEmpty(grandConfig.StaticFilesCacheControl))
                        ctx.Context.Response.Headers.Append(HeaderNames.CacheControl, grandConfig.StaticFilesCacheControl);
                }
            });
            //plugins
            application.UseStaticFiles(new StaticFileOptions {
                FileProvider = new PhysicalFileProvider(CommonHelper.MapPath("Plugins")),
                RequestPath = new PathString("/Plugins"),
                OnPrepareResponse = ctx =>
                {
                    if (!String.IsNullOrEmpty(grandConfig.StaticFilesCacheControl))
                        ctx.Context.Response.Headers.Append(HeaderNames.CacheControl, grandConfig.StaticFilesCacheControl);
                }
            });

        }
コード例 #10
0
        /// <summary>
        /// Register dependencies using Autofac
        /// </summary>
        /// <param name="grandConfiguration">Startup Grand configuration parameters</param>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="typeFinder">Type finder</param>
        protected virtual IServiceProvider RegisterDependencies(GrandConfig grandConfiguration, IServiceCollection services, ITypeFinder typeFinder)
        {
            var containerBuilder = new ContainerBuilder();

            //register engine
            containerBuilder.RegisterInstance(this).As <IEngine>().SingleInstance();

            //register type finder
            containerBuilder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();

            //find dependency registrars provided by other assemblies
            var dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>();

            //create and sort instances of dependency registrars
            var instances = dependencyRegistrars
                            //.Where(startup => PluginManager.FindPlugin(startup).Return(plugin => plugin.Installed, true)) //ignore not installed plugins
                            .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar))
                            .OrderBy(dependencyRegistrar => dependencyRegistrar.Order);

            //register all provided dependencies
            foreach (var dependencyRegistrar in instances)
            {
                dependencyRegistrar.Register(containerBuilder, typeFinder, grandConfiguration);
            }

            //populate Autofac container builder with the set of registered service descriptors
            containerBuilder.Populate(services);

            //create service provider
            _serviceProvider = new AutofacServiceProvider(containerBuilder.Build());
            return(_serviceProvider);
        }
コード例 #11
0
        /// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration root of the application</param>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            var config = new GrandConfig();

            configuration.GetSection("Grand").Bind(config);

            //add settings
            // services.AddSettings();

            //compression
            //services.AddResponseCompression();

            //add options feature
            //services.AddOptions();

            //add HTTP sesion state feature
            services.AddHttpSession(config);

            //add anti-forgery
            services.AddAntiForgery(config);

            //add localization
            //services.AddLocalization();

            //add theme support
            //services.AddThemes();

            //add WebEncoderOptions
            services.AddWebEncoder();

            services.AddRouting(options =>
            {
                // options.ConstraintMap["lang"] = typeof(LanguageParameterTransformer);
            });
        }
コード例 #12
0
        private void RegisterMediaService(ContainerBuilder builder, GrandConfig config)
        {
            var provider = new FileExtensionContentTypeProvider();

            builder.RegisterType <MimeMappingService>().As <IMimeMappingService>()
            .WithParameter(new TypedParameter(typeof(FileExtensionContentTypeProvider), provider))
            .InstancePerLifetimeScope();

            //picture service
            var useAzureBlobStorage  = !String.IsNullOrEmpty(config.AzureBlobStorageConnectionString);
            var useAmazonBlobStorage = (!String.IsNullOrEmpty(config.AmazonAwsAccessKeyId) && !String.IsNullOrEmpty(config.AmazonAwsSecretAccessKey) && !String.IsNullOrEmpty(config.AmazonBucketName) && !String.IsNullOrEmpty(config.AmazonRegion));

            if (useAzureBlobStorage)
            {
                //Windows Azure BLOB
                builder.RegisterType <AzurePictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }
            else if (useAmazonBlobStorage)
            {
                //Amazon S3 Simple Storage Service
                builder.RegisterType <AmazonPictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }
            else
            {
                //standard file system
                builder.RegisterType <PictureService>().As <IPictureService>().InstancePerLifetimeScope();
            }

            builder.RegisterType <DownloadService>().As <IDownloadService>().InstancePerLifetimeScope();
        }
コード例 #13
0
 public WebWorkContext(IHttpContextAccessor httpContextAccessor,
                       IGrandAuthenticationService authenticationService,
                       IApiAuthenticationService apiauthenticationService,
                       ICurrencyService currencyService,
                       ICustomerService customerService,
                       IGenericAttributeService genericAttributeService,
                       ILanguageService languageService,
                       IStoreContext storeContext,
                       IStoreMappingService storeMappingService,
                       IVendorService vendorService,
                       LocalizationSettings localizationSettings,
                       TaxSettings taxSettings,
                       GrandConfig config)
 {
     _httpContextAccessor      = httpContextAccessor;
     _authenticationService    = authenticationService;
     _apiauthenticationService = apiauthenticationService;
     _currencyService          = currencyService;
     _customerService          = customerService;
     _genericAttributeService  = genericAttributeService;
     _languageService          = languageService;
     _storeContext             = storeContext;
     _storeMappingService      = storeMappingService;
     _vendorService            = vendorService;
     _localizationSettings     = localizationSettings;
     _taxSettings = taxSettings;
     _config      = config;
 }
コード例 #14
0
        public AzurePictureService(IRepository <Picture> pictureRepository,
                                   ISettingService settingService,
                                   ILogger logger,
                                   IMediator mediator,
                                   IWebHostEnvironment hostingEnvironment,
                                   IStoreContext storeContext,
                                   ICacheManager cacheManager,
                                   MediaSettings mediaSettings,
                                   GrandConfig config)
            : base(pictureRepository,
                   settingService,
                   logger,
                   mediator,
                   hostingEnvironment,
                   storeContext,
                   cacheManager,
                   mediaSettings)
        {
            _config = config;

            if (string.IsNullOrEmpty(_config.AzureBlobStorageConnectionString))
            {
                throw new Exception("Azure connection string for BLOB is not specified");
            }
            if (string.IsNullOrEmpty(_config.AzureBlobStorageContainerName))
            {
                throw new Exception("Azure container name for BLOB is not specified");
            }
            if (string.IsNullOrEmpty(_config.AzureBlobStorageEndPoint))
            {
                throw new Exception("Azure end point for BLOB is not specified");
            }

            container = new BlobContainerClient(_config.AzureBlobStorageConnectionString, _config.AzureBlobStorageContainerName);
        }
コード例 #15
0
        /// <summary>
        /// ConfigureContainer is where you can register things directly
        /// with Autofac. This runs after ConfigureServices so the things
        /// here will override registrations made in ConfigureServices.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configuration"></param>
        public void ConfigureContainer(ContainerBuilder builder, IConfiguration configuration)
        {
            var typeFinder = new WebAppTypeFinder();

            //register type finder
            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();

            //find dependency registrars provided by other assemblies
            var dependencyRegistrars = typeFinder.FindClassesOfType <IDependencyRegistrar>();

            //create and sort instances of dependency registrars
            var instances = dependencyRegistrars
                            //.Where(startup => PluginManager.FindPlugin(startup).Return(plugin => plugin.Installed, true)) //ignore not installed plugins
                            .Select(dependencyRegistrar => (IDependencyRegistrar)Activator.CreateInstance(dependencyRegistrar))
                            .OrderBy(dependencyRegistrar => dependencyRegistrar.Order);

            var config = new GrandConfig();

            configuration.GetSection("Grand").Bind(config);

            //register all provided dependencies
            foreach (var dependencyRegistrar in instances)
            {
                dependencyRegistrar.Register(builder, typeFinder, config);
            }
        }
コード例 #16
0
        /// <summary>
        /// Add and configure services
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration root of the application</param>
        /// <returns>Service provider</returns>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            //find startup configurations provided by other assemblies
            var typeFinder            = new WebAppTypeFinder();
            var startupConfigurations = typeFinder.FindClassesOfType <IGrandStartup>();

            //create and sort instances of startup configurations
            var instances = startupConfigurations
                            .Where(startup => PluginManager.FindPlugin(startup).Return(plugin => plugin.Installed, true)) //ignore not installed plugins
                            .Select(startup => (IGrandStartup)Activator.CreateInstance(startup))
                            .OrderBy(startup => startup.Order);

            //configure services
            foreach (var instance in instances)
            {
                instance.ConfigureServices(services, configuration);
            }

            //register mapper configurations
            AddAutoMapper(services, typeFinder);

            //Add attributes to register custom type converters
            RegisterTypeConverter();

            var config = new GrandConfig();

            configuration.GetSection("Grand").Bind(config);

            //run startup tasks
            if (!config.IgnoreStartupTasks)
            {
                RunStartupTasks(typeFinder);
            }
        }
コード例 #17
0
 public void Register(ContainerBuilder builder, ITypeFinder typeFinder, GrandConfig config)
 {
     builder.RegisterType <ExamplePlugin>().InstancePerLifetimeScope();
     builder.RegisterType <ExampleService>().As <IExampleService>().InstancePerLifetimeScope();
     builder.RegisterType <OverrideProductService>().As <IProductService>().InstancePerLifetimeScope();
     builder.RegisterType <ExampleTask>().As <IScheduleTask>().InstancePerLifetimeScope();
     builder.RegisterType <TestActionFilter2>().InstancePerLifetimeScope();
 }
コード例 #18
0
ファイル: UrlRecordService.cs プロジェクト: xgame92/grandnode
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="cacheManager">Cache manager</param>
 /// <param name="urlRecordRepository">URL record repository</param>
 /// <param name="localizationSettings">Localization settings</param>
 public UrlRecordService(ICacheManager cacheManager,
                         IRepository <UrlRecord> urlRecordRepository,
                         GrandConfig config)
 {
     _cacheManager        = cacheManager;
     _urlRecordRepository = urlRecordRepository;
     _config = config;
 }
コード例 #19
0
 public InstallController(IInstallationLocalizationService locService, GrandConfig config, ICacheManager cacheManager,
                          IServiceProvider serviceProvider)
 {
     _locService      = locService;
     _config          = config;
     _cacheManager    = cacheManager;
     _serviceProvider = serviceProvider;
 }
コード例 #20
0
 public InstallController(GrandConfig config, ICacheBase cacheManager,
                          IServiceProvider serviceProvider, IMediator mediator)
 {
     _config          = config;
     _cacheBase       = cacheManager;
     _serviceProvider = serviceProvider;
     _mediator        = mediator;
 }
コード例 #21
0
 public SlugRouteTransformer(
     IUrlRecordService urlRecordService,
     ILanguageService languageService,
     GrandConfig config)
 {
     _urlRecordService = urlRecordService;
     _languageService  = languageService;
     _config           = config;
 }
コード例 #22
0
 public CheckLanguageSeoCodeFilter(IWebHelper webHelper,
                                   IWorkContext workContext, ILanguageService languageService,
                                   GrandConfig config)
 {
     _webHelper       = webHelper;
     _workContext     = workContext;
     _languageService = languageService;
     _config          = config;
 }
コード例 #23
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="customerSettings">Customer settings</param>
 /// <param name="customerService">Customer service</param>
 /// <param name="httpContextAccessor">HTTP context accessor</param>
 public CookieAuthenticationService(CustomerSettings customerSettings,
                                    ICustomerService customerService,
                                    IHttpContextAccessor httpContextAccessor,
                                    GrandConfig grandConfig)
 {
     _customerSettings    = customerSettings;
     _customerService     = customerService;
     _httpContextAccessor = httpContextAccessor;
     _grandConfig         = grandConfig;
 }
コード例 #24
0
 public GetRobotsTextFileHandler(IStoreContext storeContext,
                                 ILanguageService languageService,
                                 IWebHelper webHelper,
                                 GrandConfig config)
 {
     _storeContext    = storeContext;
     _languageService = languageService;
     _webHelper       = webHelper;
     _config          = config;
 }
コード例 #25
0
 private void RegisterCache(IServiceCollection serviceCollection, GrandConfig config)
 {
     serviceCollection.AddSingleton <ICacheBase, MemoryCacheBase>();
     if (config.RedisPubSubEnabled)
     {
         var redis = ConnectionMultiplexer.Connect(config.RedisPubSubConnectionString);
         serviceCollection.AddSingleton <ISubscriber>(c => redis.GetSubscriber());
         serviceCollection.AddSingleton <IMessageBus, RedisMessageBus>();
         serviceCollection.AddSingleton <ICacheBase, RedisMessageCacheManager>();
     }
 }
コード例 #26
0
        public RedisCacheManager(/*ICacheManager perRequestCacheManager,*/
            IRedisConnectionWrapper connectionWrapper,
            GrandConfig config)
        {
            if (string.IsNullOrEmpty(config.RedisCachingConnectionString))
                throw new Exception("Redis connection string is empty");

            this._connectionWrapper = connectionWrapper;
            
            this._db = _connectionWrapper.GetDatabase();
        }
コード例 #27
0
        public RedisCacheManager(GrandConfig config, IRedisConnectionWrapper connectionWrapper)
        {
            if (String.IsNullOrEmpty(config.RedisCachingConnectionString))
            {
                throw new Exception("Redis connection string is empty");
            }

            // ConnectionMultiplexer.Connect should only be called once and shared between callers
            this._connectionWrapper = connectionWrapper;
            this._db = _connectionWrapper.Database();
        }
コード例 #28
0
 private void RegisterCache(ContainerBuilder builder, GrandConfig config)
 {
     builder.RegisterType <MemoryCacheManager>().As <ICacheManager>().SingleInstance();
     if (config.RedisPubSubEnabled)
     {
         var redis = ConnectionMultiplexer.Connect(config.RedisPubSubConnectionString);
         builder.Register(c => redis.GetSubscriber()).As <ISubscriber>().SingleInstance();
         builder.RegisterType <RedisMessageBus>().As <IMessageBus>().SingleInstance();
         builder.RegisterType <RedisMessageCacheManager>().As <ICacheManager>().SingleInstance();
     }
 }
コード例 #29
0
 private void RegisterMachineNameProvider(ContainerBuilder builder, GrandConfig config)
 {
     if (config.RunOnAzureWebApps)
     {
         builder.RegisterType <AzureWebAppsMachineNameProvider>().As <IMachineNameProvider>().SingleInstance();
     }
     else
     {
         builder.RegisterType <DefaultMachineNameProvider>().As <IMachineNameProvider>().SingleInstance();
     }
 }
コード例 #30
0
        /// <summary>
        /// Add and configure any of the middleware
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration root of the application</param>
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            var config = new GrandConfig();

            configuration.GetSection("Grand").Bind(config);

            //add data protection
            services.AddGrandDataProtection(config);
            //add authentication
            services.AddGrandAuthentication(configuration);
        }