protected override void RunInternal() { var config = BackupConfigurationSection.GetSection(); var pathToWebConfig = FileUtility.GetRootedPath(config.WebConfigs.GetCurrentConfig()); var tempFolderPath = FileUtility.GetRootedPath(config.TempFolder); if (!pathToWebConfig.EndsWith(".config", StringComparison.InvariantCultureIgnoreCase)) pathToWebConfig = Path.Combine(pathToWebConfig, "web.config"); if (!Directory.Exists(tempFolderPath)) Directory.CreateDirectory(tempFolderPath); var backupFile = CreateBackupFilePath(tempFolderPath); try { var backuper = new BackupManager(backupFile, pathToWebConfig); backuper.ProgressChanged += (sender, args) => { if (args.Progress > 0) { Progress = Math.Max(0, Math.Min((int)args.Progress/2, 50)); } }; backuper.Save(TenantId); using (var stream = new FileStream(backupFile, FileMode.Open)) using (var progressStream = new ProgressStream(stream)) { progressStream.OnReadProgress += (sender, args) => { Progress = Math.Max(0, Math.Min(100, 50 + args / 2)); }; ExpirationDate = DateTime.UtcNow + config.ExpirePeriod; var storage = StorageFactory.GetStorage(pathToWebConfig, "backupfiles", "backup"); Link = storage.SavePrivate(string.Empty, Path.GetFileName(backupFile), progressStream, ExpirationDate); } NotifyHelper.SendAboutBackupCompleted(TenantId, notificationReceiverId, Link, ExpirationDate); } finally { File.Delete(backupFile); } }
public void RunJob() { var filename = Path.Combine(tmpfolder, Id + ".tbm"); try { if (!Directory.Exists(tmpfolder)) { Directory.CreateDirectory(tmpfolder); } var backuper = new BackupManager(filename, currentWebConfigPath); backuper.ProgressChanged += (o, e) => { Percentage = Math.Max(0, Math.Min((int)e.Progress / 2, 50)); }; backuper.Save(Tenant); using (var stream = new FileStream(filename, FileMode.Open)) using (var progressStream = new ProgressStream(stream)) { progressStream.OnReadProgress += (o, e) => { Percentage = Math.Max(0, Math.Min(100, 50 + e / 2)); }; var uploadname = string.Format("{0}-{1:yyyyMMdd-HHmmss}.zip", CoreContext.TenantManager.GetTenant(Tenant).TenantDomain, DateTime.UtcNow).ToLowerInvariant(); ExpireDate = DateTime.UtcNow.Add(expire); Status = GetStore().SavePrivate(string.Empty, uploadname, progressStream, ExpireDate); } IsCompleted = true; Percentage = 100; NotifyHelper.SendAboutBackupCompleted(Tenant, userId, (string)Status, ExpireDate); } catch (Exception e) { Error = e; log.Error(e); } finally { try { if (File.Exists(filename)) { File.Delete(filename); } } catch (Exception e) { log.Error(e); } } }