Exemplo n.º 1
0
        private IEnumerable <FileBackupInfo> ComposeFiles(int tenant, string config)
        {
            var files = new List <FileBackupInfo>();

            foreach (var module in StorageFactoryConfig.GetModuleList(config))
            {
                if (allowedModules.Contains(module))
                {
                    var store      = StorageFactory.GetStorage(config, tenant.ToString(), module);
                    var domainList = StorageFactoryConfig.GetDomainList(config, module);
                    foreach (var domain in domainList)
                    {
                        files.AddRange(store
                                       .ListFilesRelative(domain, "\\", "*.*", true)
                                       .Select(x => new FileBackupInfo(domain, module, x)));
                    }

                    files.AddRange(store
                                   .ListFilesRelative(string.Empty, "\\", "*.*", true)
                                   .Where(x => domainList.All(domain => x.IndexOf(string.Format("{0}/", domain)) == -1))
                                   .Select(x => new FileBackupInfo(string.Empty, module, x)));
                }
            }
            return(files.Distinct());
        }
Exemplo n.º 2
0
        private void DoDeleteStorage(IEnumerable <string> storageModules, IEnumerable <Tenant> tenants)
        {
            Logger.Debug("begin delete storage");

            foreach (var tenant in tenants)
            {
                foreach (var module in storageModules)
                {
                    var storage = StorageFactory.GetStorage(ConfigPath, tenant.TenantId.ToString(), module);
                    var domains = StorageFactoryConfig.GetDomainList(ConfigPath, module).ToList();

                    domains.Add(string.Empty); //instead storage.DeleteFiles("\\", "*.*", true);

                    foreach (var domain in domains)
                    {
                        ActionInvoker.Try(
                            state =>
                        {
                            if (storage.IsDirectory((string)state))
                            {
                                storage.DeleteFiles((string)state, "\\", "*.*", true);
                            }
                        },
                            domain,
                            5,
                            onFailure: error => Logger.WarnFormat("Can't delete files for domain {0}: \r\n{1}", domain, error)
                            );
                    }

                    SetStepCompleted();
                }
            }

            Logger.Debug("end delete storage");
        }
Exemplo n.º 3
0
 protected PortalTaskBase(DbFactory dbFactory, IOptionsMonitor <ILog> options, StorageFactory storageFactory, StorageFactoryConfig storageFactoryConfig, ModuleProvider moduleProvider)
 {
     Logger               = options.CurrentValue;
     ProcessStorage       = true;
     StorageFactory       = storageFactory;
     StorageFactoryConfig = storageFactoryConfig;
     ModuleProvider       = moduleProvider;
     DbFactory            = dbFactory;
 }
Exemplo n.º 4
0
        private void RestoreFromDump(IDataReadOperator dataReader)
        {
            var keyBase  = KeyHelper.GetDatabaseSchema();
            var keys     = dataReader.GetEntries(keyBase).Select(r => Path.GetFileName(r)).ToList();
            var upgrades = new List <string>();

            if (!string.IsNullOrEmpty(UpgradesPath) && Directory.Exists(UpgradesPath))
            {
                upgrades = Directory.GetFiles(UpgradesPath).ToList();
            }

            var stepscount = keys.Count * 2 + upgrades.Count;

            SetStepsCount(ProcessStorage ? stepscount + 1 : stepscount);

            if (ProcessStorage)
            {
                var storageModules = StorageFactoryConfig.GetModuleList(ConfigPath).Where(IsStorageModuleAllowed);
                var tenants        = TenantManager.GetTenants(false);

                stepscount += storageModules.Count() * tenants.Count;

                SetStepsCount(stepscount + 1);

                DoDeleteStorage(storageModules, tenants);
            }
            else
            {
                SetStepsCount(stepscount);
            }

            for (var i = 0; i < keys.Count; i += TasksLimit)
            {
                var tasks = new List <Task>(TasksLimit * 2);

                for (var j = 0; j < TasksLimit && i + j < keys.Count; j++)
                {
                    var key1 = Path.Combine(KeyHelper.GetDatabaseSchema(), keys[i + j]);
                    tasks.Add(RestoreFromDumpFile(dataReader, key1).ContinueWith(r => RestoreFromDumpFile(dataReader, KeyHelper.GetDatabaseData(key1.Substring(keyBase.Length + 1)))));
                }

                Task.WaitAll(tasks.ToArray());
            }

            var comparer = new SqlComparer();

            foreach (var u in upgrades.OrderBy(Path.GetFileName, comparer))
            {
                RunMysqlFile(u, true);
                SetStepCompleted();
            }
        }
Exemplo n.º 5
0
        internal void ClearDataStoreCache()
        {
            var tenantId = TenantManager.GetCurrentTenant().TenantId.ToString();
            var path     = TennantPath.CreatePath(tenantId);

            foreach (var module in StorageFactoryConfig.GetModuleList("", true))
            {
                Cache.Publish(new DataStoreCacheItem()
                {
                    TenantId = path, Module = module
                }, CacheNotifyAction.Remove);
            }
        }
Exemplo n.º 6
0
 public MigrationService(
     StorageUploader storageUploader,
     StaticUploader staticUploader,
     StorageFactoryConfig storageFactoryConfig,
     IServiceProvider serviceProvider,
     IOptionsMonitor <ILog> options)
 {
     StorageUploader      = storageUploader;
     StaticUploader       = staticUploader;
     StorageFactoryConfig = storageFactoryConfig;
     ServiceProvider      = serviceProvider;
     Log = options.Get("ASC.Data.Storage.Migration");
 }
Exemplo n.º 7
0
 public StorageSettingsHelper(
     BaseStorageSettingsListener baseStorageSettingsListener,
     StorageFactoryConfig storageFactoryConfig,
     PathUtils pathUtils,
     ICacheNotify <DataStoreCacheItem> cache,
     IOptionsMonitor <ILog> options,
     TenantManager tenantManager,
     SettingsManager settingsManager,
     IHttpContextAccessor httpContextAccessor,
     ConsumerFactory consumerFactory)
     : this(baseStorageSettingsListener, storageFactoryConfig, pathUtils, cache, options, tenantManager, settingsManager, consumerFactory)
 {
     HttpContextAccessor = httpContextAccessor;
 }
Exemplo n.º 8
0
 public RestorePortalTask(
     DbFactory dbFactory,
     IOptionsMonitor <ILog> options,
     StorageFactory storageFactory,
     StorageFactoryConfig storageFactoryConfig,
     CoreBaseSettings coreBaseSettings,
     LicenseReader licenseReader,
     TenantManager tenantManager,
     AscCacheNotify ascCacheNotify,
     ModuleProvider moduleProvider)
     : base(dbFactory, options, storageFactory, storageFactoryConfig, moduleProvider)
 {
     CoreBaseSettings = coreBaseSettings;
     LicenseReader    = licenseReader;
     TenantManager    = tenantManager;
     AscCacheNotify   = ascCacheNotify;
     Options          = options;
 }
Exemplo n.º 9
0
 public EncryptionOperationScope(IOptionsMonitor <ILog> options,
                                 StorageFactoryConfig storageFactoryConfig,
                                 StorageFactory storageFactory,
                                 TenantManager tenantManager,
                                 CoreBaseSettings coreBaseSettings,
                                 NotifyHelper notifyHelper,
                                 EncryptionSettingsHelper encryptionSettingsHelper,
                                 IConfiguration configuration)
 {
     Log = options.CurrentValue;
     StorageFactoryConfig     = storageFactoryConfig;
     StorageFactory           = storageFactory;
     TenantManager            = tenantManager;
     CoreBaseSettings         = coreBaseSettings;
     NotifyHelper             = notifyHelper;
     EncryptionSettingsHelper = encryptionSettingsHelper;
     Configuration            = configuration;
 }
Exemplo n.º 10
0
 public TransferPortalTask(
     DbFactory dbFactory,
     IServiceProvider serviceProvider,
     IOptionsMonitor <ILog> options,
     StorageFactory storageFactory,
     StorageFactoryConfig storageFactoryConfig,
     ModuleProvider moduleProvider,
     TempStream tempStream,
     TempPath tempPath)
     : base(dbFactory, options, storageFactory, storageFactoryConfig, moduleProvider)
 {
     DeleteBackupFileAfterCompletion = true;
     BlockOldPortalAfterStart        = true;
     DeleteOldPortalAfterCompletion  = true;
     Options         = options;
     TempStream      = tempStream;
     TempPath        = tempPath;
     ServiceProvider = serviceProvider;
 }
Exemplo n.º 11
0
 public StorageSettingsHelper(
     BaseStorageSettingsListener baseStorageSettingsListener,
     StorageFactoryConfig storageFactoryConfig,
     PathUtils pathUtils,
     ICacheNotify <DataStoreCacheItem> cache,
     IOptionsMonitor <ILog> options,
     TenantManager tenantManager,
     SettingsManager settingsManager,
     ConsumerFactory consumerFactory)
 {
     baseStorageSettingsListener.Subscribe();
     StorageFactoryConfig = storageFactoryConfig;
     PathUtils            = pathUtils;
     Cache           = cache;
     Options         = options;
     TenantManager   = tenantManager;
     SettingsManager = settingsManager;
     ConsumerFactory = consumerFactory;
 }
Exemplo n.º 12
0
        private void DoDeleteStorage()
        {
            Logger.Debug("begin delete storage");
            var storageModules   = StorageFactoryConfig.GetModuleList(ConfigPath).Where(IsStorageModuleAllowed).ToList();
            var modulesProcessed = 0;

            foreach (var module in storageModules)
            {
                var storage = StorageFactory.GetStorage(ConfigPath, TenantId.ToString(), module);
                var domains = StorageFactoryConfig.GetDomainList(ConfigPath, module).ToList();
                foreach (var domain in domains)
                {
                    ActionInvoker.Try(state => storage.DeleteFiles((string)state, "\\", "*.*", true), domain, 5,
                                      onFailure: error => Logger.WarnFormat("Can't delete files for domain {0}: \r\n{1}", domain, error));
                }
                storage.DeleteFiles("\\", "*.*", true);
                SetCurrentStepProgress((int)((++modulesProcessed * 100) / (double)storageModules.Count));
            }
            Logger.Debug("end delete storage");
        }
Exemplo n.º 13
0
        private void EncryptStore(Tenant tenant, string module, DiscDataStore store, StorageFactoryConfig storageFactoryConfig, ILog log)
        {
            var domains = storageFactoryConfig.GetDomainList(ConfigPath, module).ToList();

            domains.Add(string.Empty);

            var progress = ReadProgress(store);

            foreach (var domain in domains)
            {
                var logParent = string.Format("Tenant: {0}, Module: {1}, Domain: {2}", tenant.TenantAlias, module, domain);

                var files = GetFiles(domains, progress, store, domain);

                EncryptFiles(store, domain, files, logParent, log);
            }

            StepDone();

            log.DebugFormat("Percentage: {0}", Percentage);
        }
Exemplo n.º 14
0
 public StorageSettingsHelper(
     BaseStorageSettingsListener baseStorageSettingsListener,
     StorageFactoryConfig storageFactoryConfig,
     PathUtils pathUtils,
     EmailValidationKeyProvider emailValidationKeyProvider,
     ICacheNotify <DataStoreCacheItem> cache,
     IOptionsMonitor <ILog> options,
     TenantManager tenantManager,
     SettingsManager settingsManager,
     IHttpContextAccessor httpContextAccessor)
 {
     BaseStorageSettingsListener = baseStorageSettingsListener;
     StorageFactoryConfig        = storageFactoryConfig;
     PathUtils = pathUtils;
     EmailValidationKeyProvider = emailValidationKeyProvider;
     Cache               = cache;
     Options             = options;
     TenantManager       = tenantManager;
     SettingsManager     = settingsManager;
     HttpContextAccessor = httpContextAccessor;
 }
Exemplo n.º 15
0
        protected IEnumerable <BackupFileInfo> GetFilesToProcess(int tenantId)
        {
            var files = new List <BackupFileInfo>();

            foreach (var module in StorageFactoryConfig.GetModuleList(ConfigPath).Where(IsStorageModuleAllowed))
            {
                var store   = StorageFactory.GetStorage(ConfigPath, tenantId.ToString(), module);
                var domains = StorageFactoryConfig.GetDomainList(ConfigPath, module).ToArray();

                foreach (var domain in domains)
                {
                    files.AddRange(
                        store.ListFilesRelative(domain, "\\", "*.*", true)
                        .Select(path => new BackupFileInfo(domain, module, path, tenantId)));
                }

                files.AddRange(
                    store.ListFilesRelative(string.Empty, "\\", "*.*", true)
                    .Where(path => domains.All(domain => !path.Contains(domain + "/")))
                    .Select(path => new BackupFileInfo(string.Empty, module, path, tenantId)));
            }

            return(files.Distinct());
        }
Exemplo n.º 16
0
 public QuotaSyncScope(TenantManager tenantManager, StorageFactoryConfig storageFactoryConfig, StorageFactory storageFactory)
 {
     TenantManager        = tenantManager;
     StorageFactoryConfig = storageFactoryConfig;
     StorageFactory       = storageFactory;
 }
Exemplo n.º 17
0
 public void Deconstruct(out TenantManager tenantManager, out StorageFactoryConfig storageFactoryConfig, out StorageFactory storageFactory)
 {
     tenantManager        = TenantManager;
     storageFactoryConfig = StorageFactoryConfig;
     storageFactory       = StorageFactory;
 }
Exemplo n.º 18
0
 public FileBackupProvider(IOptionsMonitor <ILog> options, StorageFactory storageFactory, StorageFactoryConfig storageFactoryConfig)
 {
     StorageFactory       = storageFactory;
     StorageFactoryConfig = storageFactoryConfig;
     log = options.CurrentValue;
 }
Exemplo n.º 19
0
 public RestoreDbModuleTask(IOptionsMonitor <ILog> options, IModuleSpecifics module, IDataReadOperator reader, ColumnMapper columnMapper, DbFactory factory, bool replaceDate, bool dump, StorageFactory storageFactory, StorageFactoryConfig storageFactoryConfig, ModuleProvider moduleProvider)
     : base(factory, options, storageFactory, storageFactoryConfig, moduleProvider)
 {
     Reader       = reader ?? throw new ArgumentNullException("reader");
     ColumnMapper = columnMapper ?? throw new ArgumentNullException("columnMapper");
     DbFactory    = factory ?? throw new ArgumentNullException("factory");
     Module       = module;
     ReplaceDate  = replaceDate;
     Dump         = dump;
     Init(-1, null);
 }
Exemplo n.º 20
0
 public BackupPortalTask(DbFactory dbFactory, DbContextManager <BackupsContext> dbContextManager, IOptionsMonitor <ILog> options, TenantManager tenantManager, CoreBaseSettings coreBaseSettings, StorageFactory storageFactory, StorageFactoryConfig storageFactoryConfig, ModuleProvider moduleProvider)
     : base(dbFactory, options, storageFactory, storageFactoryConfig, moduleProvider)
 {
     Dump                = coreBaseSettings.Standalone;
     TenantManager       = tenantManager;
     BackupRecordContext = dbContextManager.Get(DbFactory.ConnectionStringSettings.ConnectionString);
 }
Exemplo n.º 21
0
 public void Deconstruct(out ILog log, out EncryptionSettingsHelper encryptionSettingsHelper, out TenantManager tenantManager, out NotifyHelper notifyHelper, out CoreBaseSettings coreBaseSettings, out StorageFactoryConfig storageFactoryConfig, out StorageFactory storageFactory, out IConfiguration configuration)
 {
     log = Log;
     encryptionSettingsHelper = EncryptionSettingsHelper;
     tenantManager            = TenantManager;
     notifyHelper             = NotifyHelper;
     coreBaseSettings         = CoreBaseSettings;
     storageFactoryConfig     = StorageFactoryConfig;
     storageFactory           = StorageFactory;
     configuration            = Configuration;
 }
Exemplo n.º 22
0
 public DeletePortalTask(DbFactory dbFactory, IOptionsMonitor <ILog> options, int tenantId, string configPath, StorageFactory storageFactory, StorageFactoryConfig storageFactoryConfig, ModuleProvider moduleProvider)
     : base(dbFactory, options, storageFactory, storageFactoryConfig, moduleProvider)
 {
     Init(tenantId, configPath);
 }