示例#1
0
        /// <summary>
        /// Constructor used to instantiate the core services
        /// </summary>
        /// <param name="dbUnitOfWorkProvider"></param>
        /// <param name="fileUnitOfWorkProvider"></param>
        /// <param name="publishingStrategy"></param>
        /// <param name="cache"></param>
        internal ServiceContext(IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider, IUnitOfWorkProvider fileUnitOfWorkProvider, BasePublishingStrategy publishingStrategy, CacheHelper cache)
        {
			BuildServiceCache(dbUnitOfWorkProvider, fileUnitOfWorkProvider, publishingStrategy, cache,
                              //this needs to be lazy because when we create the service context it's generally before the
                              //resolvers have been initialized!
                              new Lazy<RepositoryFactory>(() => RepositoryResolver.Current.Factory));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GleanerContext"/> class.
        /// </summary>
        /// <param name="serviceContext">
        /// The service context.
        /// </param>
        /// <param name="cache">
        /// The cache.
        /// </param>
        internal GleanerContext(ServiceContext serviceContext, CacheHelper cache)
        {
            Mandate.ParameterNotNull(serviceContext, "serviceContext");
            Mandate.ParameterNotNull(cache, "cache");

            _services = serviceContext;
            Cache = cache;
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="serviceContext"></param>
 /// <param name="cache"></param>
 public ApplicationContext(DatabaseContext dbContext, ServiceContext serviceContext, CacheHelper cache)
 {
     if (dbContext == null) throw new ArgumentNullException("dbContext");
     if (serviceContext == null) throw new ArgumentNullException("serviceContext");
     if (cache == null) throw new ArgumentNullException("cache");
     _databaseContext = dbContext;
     _services = serviceContext;
     ApplicationCache = cache;
 }
		public DisplayTemplateEvaluator(IAppConfigRepository repository, IEvaluationPolicy[] policies, ICacheRepository cache)
			:base(cache)
		{
			_repository = repository;
			_policies = policies;

			IsEnabled = AppConfigConfiguration.Instance != null && AppConfigConfiguration.Instance.Cache.IsEnabled;
			Cache = new CacheHelper(cache);
		}
		public DefaultPromotionEvaluator(IMarketingRepository repository, IPromotionUsageProvider usageProvider, IEvaluationPolicy[] policies, ICacheRepository cache)
			:base(cache)
		{
			_repository = repository;
			_usageProvider = usageProvider;
			_policies = policies;

            _isEnabled = MarketingConfiguration.Instance.Cache.IsEnabled;
            Cache = new CacheHelper(cache);
		}
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MerchelloContext"/> class.
        /// </summary>
        /// <param name="serviceContext">
        /// The service context.
        /// </param>
        /// <param name="gatewayContext">
        /// The gateway context.
        /// </param>
        /// <param name="cache">
        /// The cache.
        /// </param>
        internal MerchelloContext(IServiceContext serviceContext, IGatewayContext gatewayContext, CacheHelper cache)
        {
            Mandate.ParameterNotNull(serviceContext, "serviceContext");
            Mandate.ParameterNotNull(gatewayContext, "gatewayContext");
            Mandate.ParameterNotNull(cache, "cache");

            _services = serviceContext;
            _gateways = gatewayContext;
            Cache = cache;
        }
示例#7
0
        internal MerchelloContext(IServiceContext serviceContext, CacheHelper cache, bool isUnitTest)
        {
            Mandate.ParameterNotNull(serviceContext, "serviceContext");
            Mandate.ParameterNotNull(cache, "cache");

            _services = serviceContext;
            Cache = cache;

            BuildMerchelloContext(isUnitTest);
        }
	    /// <summary>
	    /// A method used to create and ensure that a global ApplicationContext singleton is created.
	    /// </summary>
	    /// <param name="cache"></param>
	    /// <param name="replaceContext">
	    /// If set to true will replace the current singleton instance - This should only be used for unit tests or on app 
	    /// startup if for some reason the boot manager is not the umbraco boot manager.
	    /// </param>
	    /// <param name="dbContext"></param>
	    /// <param name="serviceContext"></param>
	    /// <returns></returns>
	    /// <remarks>
	    /// This is NOT thread safe 
	    /// </remarks>
	    public static ApplicationContext EnsureContext(DatabaseContext dbContext, ServiceContext serviceContext, CacheHelper cache, bool replaceContext)
        {
            if (ApplicationContext.Current != null)
            {
                if (!replaceContext)
                    return ApplicationContext.Current;
            }
            var ctx = new ApplicationContext(dbContext, serviceContext, cache);
            ApplicationContext.Current = ctx;
            return ApplicationContext.Current;
        }
示例#9
0
        internal CustomerContext(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
        {
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
            Mandate.ParameterNotNull(umbracoContext, "umbracoContext");

            _umbracoContext = umbracoContext;
            _customerService = merchelloContext.Services.CustomerService;
            _cache = merchelloContext.Cache;

            Initialize();
        }
示例#10
0
        public SectionService(
            IUserService userService,
            IApplicationTreeService applicationTreeService, 
            CacheHelper cache)
        {
            if (applicationTreeService == null) throw new ArgumentNullException("applicationTreeService");
            if (cache == null) throw new ArgumentNullException("cache");

            _userService = userService;
            _applicationTreeService = applicationTreeService;
            _cache = cache;
        }
示例#11
0
 public void Setup()
 {
     //we DO want cache enabled for these tests
     var cacheHelper = new CacheHelper(
         new ObjectCacheRuntimeCacheProvider(),
         new StaticCacheProvider(),
         new NullCacheProvider());
     ApplicationContext.Current = new ApplicationContext(cacheHelper);
     ProfilerResolver.Current = new ProfilerResolver(new LogProfiler())
                                    {
                                        CanResolveBeforeFrozen = true
                                    };
 }
        public virtual void FixtureSetup()
        {
            var syntax = (DbSyntax)Enum.Parse(typeof(DbSyntax), ConfigurationManager.AppSettings["syntax"]);

            // sets up the Umbraco SqlSyntaxProvider Singleton OBSOLETE
            SqlSyntaxProviderTestHelper.EstablishSqlSyntax(syntax);

            var sqlSyntax = SqlSyntaxProviderTestHelper.SqlSyntaxProvider(syntax);

            //AutoMapperMappings.CreateMappings();
            var logger = Logger.CreateWithDefaultLog4NetConfiguration();

            var cache = new CacheHelper(
                new ObjectCacheRuntimeCacheProvider(),
                new StaticCacheProvider(),
                new NullCacheProvider());

            var serviceContext = new ServiceContext(new RepositoryFactory(cache, logger, sqlSyntax), new PetaPocoUnitOfWorkProvider(logger), logger, new TransientMessageFactory());

            _dbPreTestDataWorker = new DbPreTestDataWorker(serviceContext);

            // Umbraco Application
            var applicationMock = new Mock<UmbracoApplication>();

            // Merchello CoreBootStrap
            var bootManager = new Web.WebBootManager(logger, _dbPreTestDataWorker.SqlSyntaxProvider);
            bootManager.Initialize();

            if (MerchelloContext.Current == null) Assert.Ignore("MerchelloContext.Current is null");

            //if (!GatewayProviderResolver.HasCurrent)
            //    GatewayProviderResolver.Current = new GatewayProviderResolver(
            //    PluginManager.Current.ResolveGatewayProviders(),
            //    serviceContext.GatewayProviderService,
            //    new NullCacheProvider());

            //MerchelloContext = new MerchelloContext(serviceContext,
            //    new GatewayContext(serviceContext, GatewayProviderResolver.Current),
            //    new CacheHelper(new NullCacheProvider(),
            //                        new NullCacheProvider(),
            //                        new NullCacheProvider()));

            //if (!TriggerResolver.HasCurrent)
            //    TriggerResolver.Current = new TriggerResolver(PluginManager.Current.ResolveObservableTriggers());

            //if (!MonitorResolver.HasCurrent)
            //    MonitorResolver.Current = new MonitorResolver(MerchelloContext.Gateways.Notification, PluginManager.Current.ResolveObserverMonitors());

            ExamineManager.Instance.IndexProviderCollection["MerchelloProductIndexer"].RebuildIndex();
            ExamineManager.Instance.IndexProviderCollection["MerchelloCustomerIndexer"].RebuildIndex();
        }
示例#13
0
        public static ServiceContext GetServiceContext()
        {
            var syntax = (DbSyntax)Enum.Parse(typeof(DbSyntax), ConfigurationManager.AppSettings["syntax"]);

            // sets up the Umbraco SqlSyntaxProvider Singleton OBSOLETE
            SqlSyntaxProviderTestHelper.EstablishSqlSyntax(syntax);

            var sqlSyntaxProvider = SqlSyntaxProviderTestHelper.SqlSyntaxProvider(syntax);
            var cache = new CacheHelper(
                new ObjectCacheRuntimeCacheProvider(),
                new StaticCacheProvider(),
                new NullCacheProvider());

            var repositoryFactory = new RepositoryFactory(cache, TestLogger, sqlSyntaxProvider);

            return  new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(TestLogger), TestLogger, new TransientMessageFactory());
        }
示例#14
0
        public static IMerchelloContext GetMerchelloContext()
        {
            var syntax = (DbSyntax)Enum.Parse(typeof(DbSyntax), ConfigurationManager.AppSettings["syntax"]);
            // sets up the Umbraco SqlSyntaxProvider Singleton
            SqlSyntaxProviderTestHelper.EstablishSqlSyntax(syntax);

            var sqlSyntax = SqlSyntaxProviderTestHelper.SqlSyntaxProvider(syntax);

            //AutoMapperMappings.CreateMappings();
            var logger = Logger.CreateWithDefaultLog4NetConfiguration();
            var cache = new CacheHelper(
                new ObjectCacheRuntimeCacheProvider(),
                new StaticCacheProvider(),
                new NullCacheProvider());

            var serviceContext = new ServiceContext(new RepositoryFactory(cache, logger, sqlSyntax), new PetaPocoUnitOfWorkProvider(new Mock<ILogger>().Object), new Mock<ILogger>().Object, new TransientMessageFactory());
            return  new MerchelloContext(serviceContext,
                new GatewayContext(serviceContext, GatewayProviderResolver.Current),
                new CacheHelper(new NullCacheProvider(),
                                    new NullCacheProvider(),
                                    new NullCacheProvider()));
        }
示例#15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomerContext"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="memberService">
        /// The member Service.
        /// </param>
        /// <param name="umbracoContext">
        /// The umbraco context.
        /// </param>
        internal CustomerContext(IMerchelloContext merchelloContext, IMemberService memberService, UmbracoContext umbracoContext)
        {
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
            Mandate.ParameterNotNull(umbracoContext, "umbracoContext");
            Mandate.ParameterNotNull(memberService, "memberService");

            _merchelloContext = merchelloContext;
            _umbracoContext = umbracoContext;
            _customerService = merchelloContext.Services.CustomerService;
            _memberService = memberService;
            _cache = merchelloContext.Cache;

            _membershipHelper = new MembershipHelper(_umbracoContext);

            Initialize();
        }
 public ApplicationTreeService(CacheHelper cache)
 {
     _cache = cache;
 }
示例#17
0
 /// <summary>
 /// Creates a basic basic context
 /// </summary>
 /// <param name="cache"></param>
 /// <remarks>
 /// Used for testing
 /// </remarks>
 internal MerchelloContext(CacheHelper cache)
 {
     Cache = cache;
 }
 /// <summary>
 /// Creates a basic app context
 /// </summary>
 /// <param name="cache"></param>
 public ApplicationContext(CacheHelper cache)
 {
     ApplicationCache = cache;
 }
示例#19
0
 internal MerchelloContext(IServiceContext serviceContext, CacheHelper cache)
     : this(serviceContext, cache, false)
 {
 }
示例#20
0
 /// <summary>
 /// Creates the application cache based on the HttpRuntime cache
 /// </summary>
 protected override void CreateApplicationCache()
 {
     //create a web-based cache helper
     ApplicationCache = new CacheHelper();
 }
示例#21
0
 /// <summary>
 /// Creates the MerchelloPluginContext (singleton)
 /// </summary>
 /// <param name="serviceContext">The service context</param>
 /// <param name="cache">The cache helper</param>
 /// <remarks>
 /// Since we load fire our boot manager after Umbraco fires its "started" even, Merchello gets the benefit
 /// of allowing Umbraco to manage the various caching providers via the Umbraco CoreBootManager or WebBootManager
 /// depending on the context.
 /// </remarks>
 protected void CreateMerchelloContext(ServiceContext serviceContext, CacheHelper cache)
 {
     var gateways = new GatewayContext(serviceContext, GatewayProviderResolver.Current);
     _merchelloContext = MerchelloContext.Current = new MerchelloContext(serviceContext, gateways, cache);
 }
示例#22
0
 public void Setup()
 {
     _helper = new CacheHelper(HttpRuntime.Cache);
 }
 private void RemoveUserFromCache(Guid userId)
 {
     var key = "User:" + userId;
     var cacheHelper = new CacheHelper();
     cacheHelper.Clear(key);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomerContextBase"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>.
        /// </param>
        /// <param name="umbracoContext">
        /// The <see cref="UmbracoContext"/>.
        /// </param>
        protected CustomerContextBase(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
        {
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
            Mandate.ParameterNotNull(umbracoContext, "umbracoContext");

            this._merchelloContext = merchelloContext;
            this._umbracoContext = umbracoContext;
            this._anonCookieExpireDays = MerchelloConfiguration.Current.AnonymousCustomerCookieExpiresDays;
            this._customerService = merchelloContext.Services.CustomerService;
            this._cache = merchelloContext.Cache;
            this.Initialize();
        }
示例#25
0
 private void InitializeGatewayResolver(IServiceContext serviceContext, CacheHelper cache)
 {
     if(!GatewayProviderResolver.HasCurrent)
     GatewayProviderResolver.Current = new GatewayProviderResolver(
     PluginManager.Current.ResolveGatewayProviders(),
     serviceContext.GatewayProviderService,
     cache.RuntimeCache);
 }
示例#26
0
        /// <summary>
        /// Builds the various services
        /// </summary>
        private void BuildServiceCache(
            IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider,
            IUnitOfWorkProvider fileUnitOfWorkProvider,
            BasePublishingStrategy publishingStrategy,
            CacheHelper cache,
            Lazy<RepositoryFactory> repositoryFactory)
        {
            var provider = dbUnitOfWorkProvider;
            var fileProvider = fileUnitOfWorkProvider;

            if (_serverRegistrationService == null)
                _serverRegistrationService = new Lazy<ServerRegistrationService>(() => new ServerRegistrationService(provider, repositoryFactory.Value));

            if (_userService == null)
                _userService = new Lazy<IUserService>(() => new UserService(provider, repositoryFactory.Value));

            if (_memberService == null)
                _memberService = new Lazy<IMemberService>(() => new MemberService(provider, repositoryFactory.Value));

            if (_contentService == null)
                _contentService = new Lazy<IContentService>(() => new ContentService(provider, repositoryFactory.Value, publishingStrategy));

            if (_mediaService == null)
                _mediaService = new Lazy<IMediaService>(() => new MediaService(provider, repositoryFactory.Value));

            if (_contentTypeService == null)
                _contentTypeService = new Lazy<IContentTypeService>(() => new ContentTypeService(provider, repositoryFactory.Value, _contentService.Value, _mediaService.Value));

            if (_dataTypeService == null)
                _dataTypeService = new Lazy<IDataTypeService>(() => new DataTypeService(provider, repositoryFactory.Value));

            if (_fileService == null)
                _fileService = new Lazy<IFileService>(() => new FileService(fileProvider, provider, repositoryFactory.Value));

            if (_localizationService == null)
                _localizationService = new Lazy<ILocalizationService>(() => new LocalizationService(provider, repositoryFactory.Value));

            if (_packagingService == null)
                _packagingService = new Lazy<PackagingService>(() => new PackagingService(_contentService.Value, _contentTypeService.Value, _mediaService.Value, _dataTypeService.Value, _fileService.Value, _localizationService.Value, repositoryFactory.Value, provider));

            if (_entityService == null)
                _entityService = new Lazy<IEntityService>(() => new EntityService(provider, repositoryFactory.Value, _contentService.Value, _contentTypeService.Value, _mediaService.Value, _dataTypeService.Value));

            if (_relationService == null)
                _relationService = new Lazy<IRelationService>(() => new RelationService(provider, repositoryFactory.Value, _entityService.Value));

            if (_treeService == null)
                _treeService = new Lazy<IApplicationTreeService>(() => new ApplicationTreeService(cache));

            if (_sectionService == null)
                _sectionService = new Lazy<ISectionService>(() => new SectionService(_userService.Value, _treeService.Value, cache));

            if (_macroService == null)
                _macroService = new Lazy<IMacroService>(() => new MacroService(provider, repositoryFactory.Value));

            if (_memberTypeService == null)
                _memberTypeService = new Lazy<IMemberTypeService>(() => new MemberTypeService(provider, repositoryFactory.Value));

            if (_tagService == null)
                _tagService = new Lazy<ITagService>(() => new TagService(provider, repositoryFactory.Value));
        }
示例#27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomerContextBase"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>.
        /// </param>
        /// <param name="umbracoContext">
        /// The <see cref="UmbracoContext"/>.
        /// </param>
        protected CustomerContextBase(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
        {
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
            Mandate.ParameterNotNull(umbracoContext, "umbracoContext");

            this._merchelloContext = merchelloContext;
            this._umbracoContext = umbracoContext;
            this._customerService = merchelloContext.Services.CustomerService;
            this._cache = merchelloContext.Cache;
            this.Initialize();
        }
示例#28
0
        /// <summary>
        /// Creates and assigns the ApplicationCache based on a new instance of System.Web.Caching.Cache
        /// </summary>
        protected virtual void CreateApplicationCache()
        {
            var cacheHelper = new CacheHelper(
                        new ObjectCacheRuntimeCacheProvider(),
                        new StaticCacheProvider(),
                        //we have no request based cache when not running in web-based context
                        new NullCacheProvider());

            ApplicationCache = cacheHelper;
        }
示例#29
0
        /// <summary>
        /// Responsible for the special case initialization of the gateway resolver.
        /// </summary>
        /// <param name="serviceContext">
        /// The service context.
        /// </param>
        /// <param name="cache">
        /// The cache.
        /// </param>
        /// <remarks>
        /// This is a special case due to the fact we need this singleton instantiated prior to 
        /// building the <see cref="MerchelloContext"/>
        /// </remarks>
        private void InitializeGatewayResolver(IServiceContext serviceContext, CacheHelper cache)
        {
            _logger.Info<CoreBootManager>("Initializing Merchello GatewayResolver");

            if (!GatewayProviderResolver.HasCurrent)
                GatewayProviderResolver.Current = new GatewayProviderResolver(
                PluginManager.Current.ResolveGatewayProviders(),
                serviceContext.GatewayProviderService,
                cache.RuntimeCache);
        }
 /// <summary>
 /// Creates the GleanerPluginContext (singleton)
 /// </summary>
 /// <param name="serviceContext">The sevice context</param>
 /// <param name="cache">The cache helper</param>
 /// <remarks>
 /// Since we load fire our boot manager after Umbraco fires its "started" even, Gleaner gets the benefit
 /// of allowing Umbraco to manage the various caching providers via the Umbraco CoreBootManager or WebBootManager
 /// depending on the context.
 /// </remarks>
 protected void CreateGleanerContext(ServiceContext serviceContext, CacheHelper cache)
 {
     _gleanerContext = GleanerContext.Current = new GleanerContext(serviceContext, cache);
 }