public StorageFactory( StorageFactoryListener storageFactoryListener, StorageFactoryConfig storageFactoryConfig, SettingsManager settingsManager, StorageSettingsHelper storageSettingsHelper, TenantManager tenantManager, CoreBaseSettings coreBaseSettings, PathUtils pathUtils, EmailValidationKeyProvider emailValidationKeyProvider, IOptionsMonitor <ILog> options, IHttpContextAccessor httpContextAccessor, EncryptionSettingsHelper encryptionSettingsHelper, EncryptionFactory encryptionFactory) { StorageFactoryListener = storageFactoryListener; StorageFactoryConfig = storageFactoryConfig; SettingsManager = settingsManager; StorageSettingsHelper = storageSettingsHelper; TenantManager = tenantManager; CoreBaseSettings = coreBaseSettings; PathUtils = pathUtils; EmailValidationKeyProvider = emailValidationKeyProvider; Options = options; HttpContextAccessor = httpContextAccessor; EncryptionSettingsHelper = encryptionSettingsHelper; EncryptionFactory = encryptionFactory; }
public void Start(int tenantId, StorageSettings newStorageSettings, StorageFactoryConfig storageFactoryConfig) { if (TokenSource.Token.IsCancellationRequested) { return; } MigrateOperation migrateOperation; lock (Locker) { migrateOperation = Cache.Get <MigrateOperation>(GetCacheKey(tenantId)); if (migrateOperation != null) { return; } migrateOperation = new MigrateOperation(ServiceProvider, CacheMigrationNotify, tenantId, newStorageSettings, storageFactoryConfig); Cache.Insert(GetCacheKey(tenantId), migrateOperation, DateTime.MaxValue); } var task = new Task(migrateOperation.RunJob, TokenSource.Token, TaskCreationOptions.LongRunning); task.ConfigureAwait(false) .GetAwaiter() .OnCompleted(() => { lock (Locker) { Cache.Remove(GetCacheKey(tenantId)); } }); task.Start(Scheduler); }
public MigrateOperation(IServiceProvider serviceProvider, int tenantId, StorageSettings settings, StorageFactoryConfig storageFactoryConfig) { ServiceProvider = serviceProvider; this.tenantId = tenantId; this.settings = settings; StorageFactoryConfig = storageFactoryConfig; Modules = storageFactoryConfig.GetModuleList(ConfigPath, true); StepCount = Modules.Count(); Log = serviceProvider.GetService <IOptionsMonitor <ILog> >().CurrentValue; }
public StorageFactory( StorageFactoryListener storageFactoryListener, StorageFactoryConfig storageFactoryConfig, SettingsManager settingsManager, StorageSettingsHelper storageSettingsHelper, TenantManager tenantManager, CoreBaseSettings coreBaseSettings, PathUtils pathUtils, EmailValidationKeyProvider emailValidationKeyProvider, IOptionsMonitor <ILog> options) : this(storageFactoryListener, storageFactoryConfig, settingsManager, storageSettingsHelper, tenantManager, coreBaseSettings, pathUtils, emailValidationKeyProvider, options, null) { }
public void Start(int tenantId, StorageSettings newStorageSettings, StorageFactoryConfig storageFactoryConfig) { lock (Locker) { var id = GetCacheKey(tenantId); var migrateOperation = Queue.GetTask <MigrateOperation>(id); if (migrateOperation != null) { return; } migrateOperation = new MigrateOperation(ServiceProvider, CacheMigrationNotify, id, tenantId, newStorageSettings, storageFactoryConfig, TempStream); Queue.QueueTask(migrateOperation); } }
public StorageFactory( IServiceProvider serviceProvider, StorageFactoryConfig storageFactoryConfig, SettingsManager settingsManager, StorageSettingsHelper storageSettingsHelper, TenantManager tenantManager, CoreBaseSettings coreBaseSettings) { ServiceProvider = serviceProvider; StorageFactoryConfig = storageFactoryConfig; SettingsManager = settingsManager; StorageSettingsHelper = storageSettingsHelper; TenantManager = tenantManager; CoreBaseSettings = coreBaseSettings; }
public MigrateOperation( IServiceProvider serviceProvider, ICacheNotify <MigrationProgress> cacheMigrationNotify, string id, int tenantId, StorageSettings settings, StorageFactoryConfig storageFactoryConfig, TempStream tempStream) { Id = id; Status = DistributedTaskStatus.Created; ServiceProvider = serviceProvider; CacheMigrationNotify = cacheMigrationNotify; this.tenantId = tenantId; this.settings = settings; StorageFactoryConfig = storageFactoryConfig; TempStream = tempStream; Modules = storageFactoryConfig.GetModuleList(ConfigPath, true); StepCount = Modules.Count(); Log = serviceProvider.GetService <IOptionsMonitor <ILog> >().CurrentValue; }
protected override void DoJob() { try { Log.DebugFormat("Tenant: {0}", tenantId); Status = DistributedTaskStatus.Running; using var scope = ServiceProvider.CreateScope(); var tempPath = scope.ServiceProvider.GetService <TempPath>(); var scopeClass = scope.ServiceProvider.GetService <MigrateOperationScope>(); var(tenantManager, securityContext, storageFactory, options, storageSettingsHelper, settingsManager) = scopeClass; var tenant = tenantManager.GetTenant(tenantId); tenantManager.SetCurrentTenant(tenant); securityContext.AuthenticateMeWithoutCookie(tenant.OwnerId); foreach (var module in Modules) { var oldStore = storageFactory.GetStorage(ConfigPath, tenantId.ToString(), module); var store = storageFactory.GetStorageFromConsumer(ConfigPath, tenantId.ToString(), module, storageSettingsHelper.DataStoreConsumer(settings)); var domains = StorageFactoryConfig.GetDomainList(ConfigPath, module).ToList(); var crossModuleTransferUtility = new CrossModuleTransferUtility(options, TempStream, tempPath, oldStore, store); string[] files; foreach (var domain in domains) { //Status = module + domain; Log.DebugFormat("Domain: {0}", domain); files = oldStore.ListFilesRelative(domain, "\\", "*.*", true); foreach (var file in files) { Log.DebugFormat("File: {0}", file); crossModuleTransferUtility.CopyFile(domain, file, domain, file); } } Log.Debug("Domain:"); files = oldStore.ListFilesRelative(string.Empty, "\\", "*.*", true) .Where(path => domains.All(domain => !path.Contains(domain + "/"))) .ToArray(); foreach (var file in files) { Log.DebugFormat("File: {0}", file); crossModuleTransferUtility.CopyFile("", file, "", file); } StepDone(); MigrationPublish(); } settingsManager.Save(settings); tenant.SetStatus(TenantStatus.Active); tenantManager.SaveTenant(tenant); Status = DistributedTaskStatus.Completed; } catch (Exception e) { Status = DistributedTaskStatus.Failted; Exception = e; Log.Error(e); } MigrationPublish(); }