Ejemplo n.º 1
0
            public void RunJob()
            {
                //download demo data to temporary file
                var tempFilePath = Path.Combine(tmpfolder, _fromFilePath);

                try
                {
                    if (!File.Exists(tempFilePath))
                    {
                        using (var fs = new FileStream(tempFilePath, FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            var store = StorageFactory.GetStorage(currentWebConfigPath, "demodata", "demo", null, null);
                            store.GetReadStream(_fromFilePath).StreamCopyTo(fs);
                        }
                    }

                    var restoreTask = new RestorePortalTask(currentWebConfigPath, tempFilePath, ColumnMapper.ForRestoreDemoPortal(_tenantID));
                    restoreTask.IgnoreTable("tenants_tenants");
                    restoreTask.IgnoreTable("tenants_tariff");
                    restoreTask.IgnoreModule(ModuleName.Mail);
                    restoreTask.IgnoreModule(ModuleName.WebStudio);

                    restoreTask.ProgressChanged += (sender, args) => Percentage = args.Progress;
                    restoreTask.Message         += (sender, args) =>
                    {
                        if (args.Reason == MessageReason.Info)
                        {
                            log.Debug(args.Message);
                        }
                        else if (args.Reason == MessageReason.Warning)
                        {
                            log.Warn(args.Message);
                        }
                    };

                    restoreTask.Run();
                }
                catch (Exception error)
                {
                    log.Error(error);
                    Error = error;
                }
                finally
                {
                    IsCompleted = true;
                }
            }
Ejemplo n.º 2
0
        private static void Restore()
        {
            var files = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).GetFiles("*.zip");

            foreach (var file in files)
            {
                try
                {
                    var task = new RestorePortalTask(LogManager.GetLogger("ASC"), ToAbsolute("TeamLabSvc.exe.config"), file.FullName);
                    task.ProgressChanged            += (sender, args) => log.Info(args.Progress);
                    task.UnblockPortalAfterCompleted = true;
                    task.ReplaceDate = true;
                    task.RunJob();
                }
                catch (Exception error)
                {
                    log.Error(error);
                }
            }
        }
Ejemplo n.º 3
0
            public void RunJob()
            {
                Tenant tenant   = null;
                var    tempFile = PathHelper.GetTempFileName(tempFolder);

                try
                {
                    NotifyHelper.SendAboutRestoreStarted(TenantId, Notify);

                    var storage = BackupStorageFactory.GetBackupStorage(StorageType, TenantId);
                    storage.Download(StoragePath, tempFile);

                    Percentage = 10;

                    tenant = CoreContext.TenantManager.GetTenant(TenantId);
                    tenant.SetStatus(TenantStatus.Restoring);
                    CoreContext.TenantManager.SaveTenant(tenant);

                    var columnMapper = new ColumnMapper();
                    columnMapper.SetMapping("tenants_tenants", "alias", tenant.TenantAlias, ((Guid)Id).ToString("N"));
                    columnMapper.Commit();

                    var restoreTask = new RestorePortalTask(Log, TenantId, configPaths[currentRegion], tempFile, columnMapper);
                    restoreTask.IgnoreTable("tenants_tariff");
                    restoreTask.ProgressChanged += (sender, args) => Percentage = (10d + 0.65 * args.Progress);
                    restoreTask.RunJob();

                    CoreContext.TenantManager.RemoveTenant(tenant.TenantId);

                    var restoredTenant = CoreContext.TenantManager.GetTenant(columnMapper.GetTenantMapping());
                    restoredTenant.SetStatus(TenantStatus.Active);
                    restoredTenant.TenantAlias = tenant.TenantAlias;
                    restoredTenant.PaymentId   = string.Empty;
                    if (string.IsNullOrEmpty(restoredTenant.MappedDomain) && !string.IsNullOrEmpty(tenant.MappedDomain))
                    {
                        restoredTenant.MappedDomain = tenant.MappedDomain;
                    }
                    CoreContext.TenantManager.SaveTenant(restoredTenant);

                    Percentage = 75;

                    File.Delete(tempFile);

                    // sleep until tenants cache expires
                    Thread.Sleep(TimeSpan.FromMinutes(2));

                    Percentage = 100;

                    NotifyHelper.SendAboutRestoreCompleted(restoredTenant.TenantId, Notify);
                }
                catch (Exception error)
                {
                    Log.Error(error);
                    Error = error;

                    if (tenant != null)
                    {
                        tenant.SetStatus(TenantStatus.Active);
                        CoreContext.TenantManager.SaveTenant(tenant);
                    }
                }
                finally
                {
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                    IsCompleted = true;
                }
            }
Ejemplo n.º 4
0
            public void RunJob()
            {
                Tenant tenant   = null;
                var    tempFile = PathHelper.GetTempFileName(TempFolder);

                try
                {
                    NotifyHelper.SendAboutRestoreStarted(TenantId, Notify);

                    var storage = BackupStorageFactory.GetBackupStorage(StorageType, TenantId, StorageParams);
                    storage.Download(StoragePath, tempFile);

                    if (!CoreContext.Configuration.Standalone)
                    {
                        var backupHash = GetBackupHash(tempFile);
                        var repo       = BackupStorageFactory.GetBackupRepository();
                        var record     = repo.GetBackupRecord(backupHash, TenantId);
                        if (record == null)
                        {
                            throw new Exception(BackupResource.BackupNotFound);
                        }
                    }

                    Percentage = 10;

                    tenant = CoreContext.TenantManager.GetTenant(TenantId);
                    tenant.SetStatus(TenantStatus.Restoring);
                    CoreContext.TenantManager.SaveTenant(tenant);

                    var columnMapper = new ColumnMapper();
                    columnMapper.SetMapping("tenants_tenants", "alias", tenant.TenantAlias, ((Guid)Id).ToString("N"));
                    columnMapper.Commit();

                    var restoreTask = new RestorePortalTask(Log, TenantId, configPaths[currentRegion], tempFile, columnMapper, upgradesPath);
                    restoreTask.ProgressChanged += (sender, args) => Percentage = (10d + 0.65 * args.Progress);
                    restoreTask.RunJob();

                    Tenant restoredTenant = null;

                    if (restoreTask.Dump)
                    {
                        AscCache.OnClearCache();
                        if (Notify)
                        {
                            var tenants = CoreContext.TenantManager.GetTenants();
                            foreach (var t in tenants)
                            {
                                NotifyHelper.SendAboutRestoreCompleted(t.TenantId, Notify);
                            }
                        }
                    }
                    else
                    {
                        CoreContext.TenantManager.RemoveTenant(tenant.TenantId);

                        restoredTenant = CoreContext.TenantManager.GetTenant(columnMapper.GetTenantMapping());
                        restoredTenant.SetStatus(TenantStatus.Active);
                        restoredTenant.TenantAlias = tenant.TenantAlias;
                        restoredTenant.PaymentId   = string.Empty;
                        if (string.IsNullOrEmpty(restoredTenant.MappedDomain) && !string.IsNullOrEmpty(tenant.MappedDomain))
                        {
                            restoredTenant.MappedDomain = tenant.MappedDomain;
                        }
                        CoreContext.TenantManager.SaveTenant(restoredTenant);

                        // sleep until tenants cache expires
                        Thread.Sleep(TimeSpan.FromMinutes(2));

                        NotifyHelper.SendAboutRestoreCompleted(restoredTenant.TenantId, Notify);
                    }

                    Percentage = 75;

                    File.Delete(tempFile);

                    Percentage = 100;
                }
                catch (Exception error)
                {
                    Log.Error(error);
                    Error = error;

                    if (tenant != null)
                    {
                        tenant.SetStatus(TenantStatus.Active);
                        CoreContext.TenantManager.SaveTenant(tenant);
                    }
                }
                finally
                {
                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                    IsCompleted = true;
                }
            }