예제 #1
0
 public StoreController(SmartDbContext db, ICatalogSearchService catalogSearchService)
 {
     _db = db;
     _catalogSearchService = catalogSearchService;
 }
예제 #2
0
 public SettingService(ICacheManager cache, SmartDbContext db)
 {
     _cache       = cache;
     _db          = db;
     _setSettings = _db.Settings;
 }
예제 #3
0
 public QueuedMessagesSendTask(SmartDbContext db, IQueuedEmailService queuedEmailService)
 {
     _db = db;
     _queuedEmailService = queuedEmailService;
 }
예제 #4
0
 public ProductReviewCountRule(SmartDbContext db)
 {
     _db = db;
 }
예제 #5
0
 public ProductService(SmartDbContext db)
 {
     _db = db;
 }
예제 #6
0
 public CategoryHook(SmartDbContext db, IRequestCache requestCache)
 {
     _db           = db;
     _requestCache = requestCache;
 }
예제 #7
0
 public EmailFilePublisher(SmartDbContext db, DatabaseMediaStorageProvider dbMediaStorageProvider)
 {
     _db = db;
     _dbMediaStorageProvider = dbMediaStorageProvider;
 }
 public ProductMediaFileHook(SmartDbContext db)
 {
     _db = db;
 }
예제 #9
0
 public OrderItemHook(SmartDbContext db, IEventPublisher eventPublisher)
 {
     _db             = db;
     _eventPublisher = eventPublisher;
 }
예제 #10
0
        public GiftCardService(SmartDbContext db, IStoreContext storeContext)
        {
            _db = db;

            _primaryCurrency = storeContext.CurrentStore.PrimaryStoreCurrency;
        }
 public ProductTagRuleOptionsProvider(SmartDbContext db)
 {
     _db = db;
 }
 public CommonRuleOptionsProvider(SmartDbContext db)
 {
     _db = db;
 }
예제 #13
0
 public SpentAmountRule(SmartDbContext db)
 {
     _db = db;
 }
예제 #14
0
 public ActivityLogger(SmartDbContext db, IWorkContext workContext, IRequestCache requestCache)
 {
     _db           = db;
     _workContext  = workContext;
     _requestCache = requestCache;
 }
 public MessageTemplateConverter(SmartDbContext db, IApplicationContext appContext)
 {
     _db                  = Guard.NotNull(db, nameof(db));
     _appContext          = Guard.NotNull(appContext, nameof(appContext));
     _defaultEmailAccount = _db.Set <EmailAccount>().FirstOrDefault(x => x.Email != null);
 }
 public InstallPermissionsInitializer(SmartDbContext db, IPermissionService permissionService, ITypeScanner typeScanner)
 {
     _db = db;
     _permissionService = permissionService;
     _typeScanner       = typeScanner;
 }
예제 #17
0
 public ProductFromCategoryInCartRule(SmartDbContext db, IShoppingCartService shoppingCartService)
 {
     _db = db;
     _shoppingCartService = shoppingCartService;
 }
예제 #18
0
 public TransientMediaClearTask(SmartDbContext db, IMediaService mediaService)
 {
     _db           = db;
     _mediaService = mediaService;
 }
예제 #19
0
 public MemberRepository(SmartDbContext context)
 {
     _context = context;
 }
예제 #20
0
 public DiscountController(SmartDbContext db)
 {
     _db = db;
 }
예제 #21
0
 public ProductTagService(SmartDbContext db, IWorkContext workContext, ICacheManager cache)
 {
     _db          = db;
     _workContext = workContext;
     _cache       = cache;
 }
예제 #22
0
 public DeliveryTimeHook(SmartDbContext db)
 {
     _db = db;
 }
예제 #23
0
        public virtual async Task <InstallationResult> InstallAsync(InstallationModel model, ILifetimeScope scope)
        {
            // TODO: (core) CancellationToken
            Guard.NotNull(model, nameof(model));

            UpdateResult(x =>
            {
                x.ProgressMessage = GetResource("Progress.CheckingRequirements");
                x.Completed       = false;
                Logger.Info(x.ProgressMessage);
            });

            if (DataSettings.DatabaseIsInstalled())
            {
                return(UpdateResult(x =>
                {
                    x.Success = true;
                    x.RedirectUrl = _urlHelper.Action("Index", "Home");
                    Logger.Info("Application already installed");
                }));
            }

            //// set page timeout to 5 minutes
            //this.Server.ScriptTimeout = 300;

            DbFactory dbFactory = null;

            try
            {
                dbFactory = DbFactory.Load(model.DataProvider, _appContext.TypeScanner);
            }
            catch
            {
                return(UpdateResult(x =>
                {
                    x.Errors.Add(GetResource("ConnectionStringRequired")); // TODO: (core) ErrMessage
                    Logger.Error(x.Errors.Last());
                }));
            }

            model.DatabaseConnectionString = model.DatabaseConnectionString?.Trim();

            DbConnectionStringBuilder conStringBuilder = null;

            if (model.SqlConnectionInfo.EqualsNoCase("sqlconnectioninfo_raw"))
            {
                // Raw connection string
                if (string.IsNullOrEmpty(model.DatabaseConnectionString))
                {
                    return(UpdateResult(x =>
                    {
                        x.Errors.Add(GetResource("ConnectionStringRequired"));
                        Logger.Error(x.Errors.Last());
                    }));
                }

                try
                {
                    // Try to create connection string
                    conStringBuilder = dbFactory.CreateConnectionStringBuilder(model.DatabaseConnectionString);
                }
                catch (Exception ex)
                {
                    return(UpdateResult(x =>
                    {
                        x.Errors.Add(GetResource("ConnectionStringWrongFormat"));
                        Logger.Error(ex, x.Errors.Last());
                    }));
                }
            }
            else
            {
                // Structural connection string
                // TODO: (core) ...
            }

            // TODO: (core) Access rights check ...

            if (GetInstallResult().HasErrors)
            {
                return(UpdateResult(x =>
                {
                    x.Completed = true;
                    x.Success = false;
                    x.RedirectUrl = null;
                    Logger.Error("Aborting installation.");
                }));
            }

            SmartDbContext dbContext = null;
            var            shouldDeleteDbOnFailure = false;

            try
            {
                var conString = conStringBuilder.ConnectionString;
                var settings  = DataSettings.Instance;

                settings.AppVersion       = SmartstoreVersion.Version;
                settings.DbFactory        = dbFactory;
                settings.ConnectionString = conString;

                // So that DataSettings.DatabaseIsInstalled() returns false during installation.
                DataSettings.SetTestMode(true);

                // resolve SeedData instance from primary language
                var lazyLanguage = GetAppLanguage(model.PrimaryLanguage);
                if (lazyLanguage == null)
                {
                    return(UpdateResult(x =>
                    {
                        x.Errors.Add(GetResource("Install.LanguageNotRegistered").FormatInvariant(model.PrimaryLanguage));
                        x.Completed = true;
                        x.Success = false;
                        x.RedirectUrl = null;
                        Logger.Error(x.Errors.Last());
                    }));
                }

                // Create the DataContext
                dbContext = (SmartDbContext)dbFactory.CreateApplicationDbContext(
                    conString,
                    _appContext.AppConfiguration.DbMigrationCommandTimeout,
                    HistoryRepository.DefaultTableName + "_Core"); // TODO: (core) Make const for core migration table name

                // Delete only on failure if WE created the database.
                shouldDeleteDbOnFailure = !await dbContext.Database.CanConnectAsync();

                // Create Language domain object from lazyLanguage
                var languages       = dbContext.Languages;
                var primaryLanguage = new Language
                {
                    Name              = lazyLanguage.Metadata.Name,
                    LanguageCulture   = lazyLanguage.Metadata.Culture,
                    UniqueSeoCode     = lazyLanguage.Metadata.UniqueSeoCode,
                    FlagImageFileName = lazyLanguage.Metadata.FlagImageFileName
                };

                // Build the seed configuration model
                var seedConfiguration = new SeedDataConfiguration
                {
                    DefaultUserName     = model.AdminEmail,
                    DefaultUserPassword = model.AdminPassword,
                    SeedSampleData      = model.InstallSampleData,
                    Data                    = lazyLanguage.Value,
                    Language                = primaryLanguage,
                    StoreMediaInDB          = model.MediaStorage == "db",
                    ProgressMessageCallback = msg => UpdateResult(x => x.ProgressMessage = GetResource(msg))
                };

                var seeder = new InstallationDataSeeder(seedConfiguration, Logger, _httpContextAccessor);

                UpdateResult(x =>
                {
                    x.ProgressMessage = GetResource("Progress.BuildingDatabase");
                    Logger.Info(x.ProgressMessage);
                });

                // ===>>> Actually performs database creation.
                await dbContext.Database.MigrateAsync();

                // ===>>> Seeds data.
                await seeder.SeedAsync(dbContext);

                // ...

                // Detect media file tracks (must come after plugins installation)
                UpdateResult(x =>
                {
                    x.ProgressMessage = GetResource("Progress.ProcessingMedia");
                    Logger.Info(x.ProgressMessage);
                });

                using (var scope2 = scope.BeginLifetimeScope(c =>
                {
                    c.RegisterInstance(dbContext);
                    c.Register <IStoreContext>(cc => new StoreContext(cc.Resolve <ICacheFactory>(), null, _httpContextAccessor, cc.Resolve <IActionContextAccessor>()));
                    c.Register <ISettingFactory>(cc => new SettingFactory(cc.Resolve <ICacheManager>(), null, _httpContextAccessor));
                }))
                {
                    var mediaTracker = scope2.Resolve <IMediaTracker>();
                    foreach (var album in scope2.Resolve <IAlbumRegistry>().GetAlbumNames(true))
                    {
                        await mediaTracker.DetectAllTracksAsync(album);
                    }
                }

                UpdateResult(x =>
                {
                    x.ProgressMessage = GetResource("Progress.Finalizing");
                    Logger.Info(x.ProgressMessage);
                });

                // Now persist settings
                settings.Save();

                // SUCCESS: Redirect to home page
                return(UpdateResult(x =>
                {
                    x.Completed = true;
                    x.Success = true;
                    x.RedirectUrl = _urlHelper.Action("Index", "Home");
                    Logger.Info("Installation completed successfully");
                }));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                // Delete Db if it was auto generated
                if (dbContext != null && shouldDeleteDbOnFailure)
                {
                    try
                    {
                        Logger.Debug("Deleting database");
                        await dbContext.Database.EnsureDeletedAsync();
                    }
                    catch { }
                }

                // Clear provider settings if something got wrong
                DataSettings.Delete();

                var msg           = ex.Message;
                var realException = ex;
                while (realException.InnerException != null)
                {
                    realException = realException.InnerException;
                }

                if (!object.Equals(ex, realException))
                {
                    msg += " (" + realException.Message + ")";
                }

                return(UpdateResult(x =>
                {
                    x.Errors.Add(string.Format(GetResource("SetupFailed"), msg));
                    x.Success = false;
                    x.Completed = true;
                    x.RedirectUrl = null;
                }));
            }
            finally
            {
                if (dbContext != null)
                {
                    dbContext.Dispose();
                }
            }
        }
예제 #24
0
 public virtual IUrlServiceBatchScope CreateBatchScope(SmartDbContext db = null)
 {
     return(new UrlServiceBatchScope(this, db));
 }
예제 #25
0
 public RecurringPaymentHook(SmartDbContext db, IEventPublisher eventPublisher)
 {
     _db             = db;
     _eventPublisher = eventPublisher;
 }
예제 #26
0
 public SystemAlbumProvider(SmartDbContext db)
 {
     _db = db;
 }
 public ActivityLogTypeMigrator(SmartDbContext db)
 {
     _db = Guard.NotNull(db, nameof(db));
 }
예제 #28
0
 public QueuedMessagesClearTask(SmartDbContext db, CommonSettings commonSettings)
 {
     _db             = db;
     _commonSettings = commonSettings;
 }
예제 #29
0
 public DashboardBestsellersViewComponent(SmartDbContext db, MediaSettings mediaSettings)
 {
     _db            = db;
     _mediaSettings = mediaSettings;
 }
예제 #30
0
 public ProductVariantAttributeValueHook(SmartDbContext db)
 {
     _db = db;
 }
예제 #31
0
 public ManufacturerRuleOptionsProvider(SmartDbContext db)
 {
     _db = db;
 }