Beispiel #1
0
        public DataImporter(
            ICommonServices services,
            IImportProfileService importProfileService,
            ILanguageService languageService,
            Func <ImportEntityType, IEntityImporter> importerFactory,
            Lazy <IEmailAccountService> emailAccountService,
            Lazy <IEmailSender> emailSender,
            Lazy <ContactDataSettings> contactDataSettings,
            Lazy <DataExchangeSettings> dataExchangeSettings,
            IDbCache dbCache,
            IUrlRecordService urlRecordService,
            ILocalizedEntityService localizedEntityService)
        {
            _services             = services;
            _importProfileService = importProfileService;
            _languageService      = languageService;
            _importerFactory      = importerFactory;
            _emailAccountService  = emailAccountService;
            _emailSender          = emailSender;
            _contactDataSettings  = contactDataSettings;
            _dataExchangeSettings = dataExchangeSettings;
            _dbCache                = dbCache;
            _urlRecordService       = urlRecordService;
            _localizedEntityService = localizedEntityService;

            T = NullLocalizer.Instance;
        }
 public DbRepository(
     IDbResourceManager dbResources,
     IDbCache cache,
     Func <string, IDbConnection> generateConnection)
 {
     _dbResources        = dbResources;
     _cache              = cache;
     _generateConnection = generateConnection;
 }
 public DbRepository(
     IDbResourceManager dbResources,
     IDbCache cache,
     Func <string, IDbConnection> generateConnection)
 {
     _dbResources        = dbResources;
     _cache              = cache;
     _generateConnection = generateConnection;
     DefaultTimeoutSec   = 5;
     DefaultMaxAttempts  = 3;
 }
Beispiel #4
0
        public static T GetOrCreate <T>(
            this IDbCache cache,
            string key,
            TimeSpan?expirationRelativeToNow,
            Func <T> factory)
        {
            if (!cache.TryGetValue(key, out object result))
            {
                result = factory();
                cache.CreateEntry(key, result, expirationRelativeToNow);
            }

            return((T)result);
        }
Beispiel #5
0
 public CachingQueryProvider(
     IDbCache cache,
     IQueryKeyGenerator queryKeyGenerator,
     IQueryCompiler queryCompiler,
     ICurrentDbContext currentContext,
     IDbContextOptions options,
     IDiagnosticsLogger <DbLoggerCategory.Query> logger)
     : base(queryCompiler)
 {
     _cache             = cache;
     _queryKeyGenerator = queryKeyGenerator;
     _currentContext    = currentContext;
     _extension         = options.FindExtension <CachingOptionsExtension>();
     _logger            = logger.Logger;
 }
Beispiel #6
0
        public SmartDbConfiguration()
        {
            // DB model caching
            if (HostingEnvironment.IsHosted)
            {
                var cacheLocation = CommonHelper.MapPath("~/App_Data/EfCache");
                System.IO.Directory.CreateDirectory(cacheLocation);
                var modelStore = new EfDbModelStore(cacheLocation);
                AddDependencyResolver(new SingletonDependencyResolver <DbModelStore>(modelStore));
            }

            IEfDataProvider provider = null;

            try
            {
                provider = (new EfDataProviderFactory(DataSettings.Current).LoadDataProvider()) as IEfDataProvider;
            }
            catch
            {
                /* SmartStore is not installed yet! */
            }

            if (provider != null)
            {
                base.SetDefaultConnectionFactory(provider.GetConnectionFactory());

                if (HostingEnvironment.IsHosted && DataSettings.DatabaseIsInstalled())
                {
                    Loaded += (sender, args) =>
                    {
                        // prepare EntityFramework 2nd level cache
                        IDbCache cache = null;
                        try
                        {
                            cache = EngineContext.Current.Resolve <IDbCache>();
                        }
                        catch
                        {
                            cache = new NullDbCache();
                        }

                        var cacheInterceptor = new CacheTransactionInterceptor(cache);
                        AddInterceptor(cacheInterceptor);
                        args.ReplaceService <DbProviderServices>((s, o) => new CachingProviderServices(s, cacheInterceptor));
                    };
                }
            }
        }
Beispiel #7
0
        public static async Task <T> GetOrCreateAsync <T>(
            this IDbCache cache,
            string key,
            TimeSpan?expirationRelativeToNow,
            Func <Task <T> > factory)
        {
            if (!cache.TryGetValue(key, out object result))
            {
                // Async version of GetOrCreate is necessary, because
                // we want to store the result of Task<T> which is T.
                result = await factory();

                cache.CreateEntry(key, result, expirationRelativeToNow);
            }

            return((T)result);
        }
 public CommonController(
     Lazy <IPaymentService> paymentService,
     Lazy <IShippingService> shippingService,
     Lazy <ICurrencyService> currencyService,
     Lazy <IMeasureService> measureService,
     ICustomerService customerService,
     Lazy <CommonSettings> commonSettings,
     Lazy <CurrencySettings> currencySettings,
     Lazy <MeasureSettings> measureSettings,
     Lazy <IDateTimeHelper> dateTimeHelper,
     ILanguageService languageService,
     ILocalizationService localizationService,
     Lazy <IImageCache> imageCache,
     Lazy <IImportProfileService> importProfileService,
     Lazy <IIconExplorer> iconExplorer,
     IGenericAttributeService genericAttributeService,
     IDbCache dbCache,
     ITaskScheduler taskScheduler,
     ICommonServices services)
 {
     _paymentService          = paymentService;
     _shippingService         = shippingService;
     _currencyService         = currencyService;
     _measureService          = measureService;
     _customerService         = customerService;
     _commonSettings          = commonSettings;
     _currencySettings        = currencySettings;
     _measureSettings         = measureSettings;
     _dateTimeHelper          = dateTimeHelper;
     _languageService         = languageService;
     _localizationService     = localizationService;
     _imageCache              = imageCache;
     _importProfileService    = importProfileService;
     _iconExplorer            = iconExplorer;
     _genericAttributeService = genericAttributeService;
     _dbCache       = dbCache;
     _taskScheduler = taskScheduler;
     _services      = services;
 }
Beispiel #9
0
        public SmartDbConfiguration()
        {
            IEfDataProvider provider = null;

            try
            {
                provider = (new EfDataProviderFactory(DataSettings.Current).LoadDataProvider()) as IEfDataProvider;
            }
            catch
            {
                /* SmartStore is not installed yet! */
            }

            if (provider != null)
            {
                base.SetDefaultConnectionFactory(provider.GetConnectionFactory());

                if (HostingEnvironment.IsHosted && DataSettings.DatabaseIsInstalled())
                {
                    Loaded += (sender, args) =>
                    {
                        // prepare EntityFramework 2nd level cache
                        IDbCache cache = null;
                        try
                        {
                            cache = EngineContext.Current.Resolve <IDbCache>();
                        }
                        catch
                        {
                            cache = new NullDbCache();
                        }

                        var cacheInterceptor = new CacheTransactionInterceptor(cache);
                        AddInterceptor(cacheInterceptor);
                        args.ReplaceService <DbProviderServices>((s, o) => new CachingProviderServices(s, cacheInterceptor));
                    };
                }
            }
        }
        public CacheTransactionInterceptor(IDbCache cache)
        {
            Guard.NotNull(cache, nameof(cache));

            _cache = cache;
        }
 public DbRepository(
     IDbResourceManager dbResources,
     IDbCache cache)
     : this(dbResources, cache, connStr => new SqlConnection(connStr))
 {
 }