public static BackupServiceClient logIn(string username, string password, out string token) { BackupServiceClient server = new BackupServiceClient(); AuthenticationData ad; token = null; try { ad = server.authStep1(username); } catch(FaultException) { throw new LoginExcpetion("Username doesn't exist!"); }catch { throw new LoginExcpetion("No internet connection!Check it and retry"); } try { token = server.authStep2(ad.token, username, AuthenticationPrimitives.hashPassword(password, ad.salt, ad.token)); } catch (FaultException) { throw new LoginExcpetion("Wrong password!"); } catch { throw new LoginExcpetion("No internet connection!Check it and retry"); } return server; }
public BackupProgress StartBackup(BackupStorageType storageType, StorageParams storageParams, bool backupMail) { DemandPermissions(); var backupRequest = new StartBackupRequest { TenantId = GetCurrentTenantId(), UserId = SecurityContext.CurrentAccount.ID, BackupMail = backupMail, StorageType = storageType }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: backupRequest.StorageBasePath = storageParams.FolderId; break; case BackupStorageType.CustomCloud: ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection(new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); break; } using (var service = new BackupServiceClient()) { return service.StartBackup(backupRequest); } }
public static void SetTenantData(string language) { try { using (var backupClient = new BackupServiceClient()) { int tenantID = CoreContext.TenantManager.GetCurrentTenant().TenantId; BackupResult result = null; do { if (result == null) { result = backupClient.RestorePortal(tenantID, language); } else { result = backupClient.GetRestoreStatus(tenantID); } Thread.Sleep(TimeSpan.FromSeconds(5)); } while (!result.Completed); //Thread.Sleep(TimeSpan.FromSeconds(15)); // wait to invalidate users cache... } var apiServer = new ApiServer(); apiServer.CallApiMethod(SetupInfo.WebApiBaseUrl + "/crm/settings", "PUT"); } catch (Exception error) { LogManager.GetLogger("ASC.Web").Error("Can't set default data", error); } }
private BackupServiceClient logIn(string username, string password, out string token) { BackupServiceClient server = new BackupServiceClient(); AuthenticationData ad; try { ad = server.authStep1(username); } catch { MessageBox.Show(this, "Username doesn't exist.", "Wrong username", MessageBoxButton.OK); token = null; return null; } try { token = server.authStep2(ad.token, username, AuthenticationPrimitives.hashPassword(password, ad.salt, ad.token)); } catch { MessageBox.Show(this, "Wrong Password", "", MessageBoxButton.OK); token = null; return null; } return server; }
public List <BackupHistoryRecord> GetBackupHistory() { DemandPermissionsBackup(); using (var service = new BackupServiceClient()) { return(service.GetBackupHistory(GetCurrentTenantId())); } }
public void DeleteSchedule() { DemandPermissionsBackup(); using (var service = new BackupServiceClient()) { service.DeleteSchedule(GetCurrentTenantId()); } }
public BackupProgress GetBackupProgress() { DemandPermissionsBackup(); using (var service = new BackupServiceClient()) { return(service.GetBackupProgress(GetCurrentTenantId())); } }
public void DeleteBackup(Guid id) { DemandPermissionsBackup(); using (var service = new BackupServiceClient()) { service.DeleteBackup(id); } }
public ProgressInfo GetRestoreStatus() { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.GetRestoreStatus(GetCurrentTenantId()); return ToProgressInfo(response); } }
public ProgressInfo StartRestore(string filename) { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.RestorePortal(GetCurrentTenantId(), filename); return ToProgressInfo(response); } }
public ProgressInfo StartBackup() { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.CreateBackup(GetCurrentTenantId(), SecurityContext.CurrentAccount.ID); return ToProgressInfo(response); } }
public ProgressInfo StartBackup() { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.CreateBackup(GetCurrentTenantId(), SecurityContext.CurrentAccount.ID); return(ToProgressInfo(response)); } }
public ProgressInfo GetRestoreStatus() { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.GetRestoreStatus(GetCurrentTenantId()); return(ToProgressInfo(response)); } }
public ProgressInfo StartRestore(string filename) { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.RestorePortal(GetCurrentTenantId(), filename); return(ToProgressInfo(response)); } }
private async void Button_Click(object sender, RoutedEventArgs e) { string username = this.usernameTxtBox.Text; string password = this.paswordTxtBox.Password; if (username.Equals("")) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Missing username! Username field cannot be empty."); return; } if (password.Equals("")) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Missing password! Password field cannot be empty."); return; } string token; BackupServiceClient server = null; try { if (Const <BackupServiceClient> .Instance().get() == null) { server = logIn(username, password, out token); } } catch (LoginExcpetion ex) { UsefullMethods.setLabelAlert("danger", this.errorBox, ex.Message); } if (server != null) { Const <BackupServiceClient> .Instance().set(server); UsefullMethods.setLabelAlert("success", this.errorBox, "Log in succeed!"); conf.userName.set(this.usernameTxtBox.Text); await Task.Delay(500); this.Hide(); string targetPath = conf.targetPath.get(); // if the path is not setted a windows for selecting the path must be shown if (targetPath == null) { WelcomeWindows ww = new WelcomeWindows(); ww.parent = this; ww.Show(); ww.Activate(); } else { TrayiconMode.Instance(); } } }
private ControlView() { this.server = Const<BackupServiceClient>.Instance().get(); InitializeComponent(); targetPath = conf.targetPath.get(); se.threadCallback += ThreadMonitor; buildGraphic(); versionView.MouseDoubleClick += VersionView_MouseDoubleClick; revertList.MouseDoubleClick += VersionView_MouseDoubleClick; versionView.SelectedItemChanged += VersionView_SelectedItemChanged; }
private ControlView() { this.server = Const <BackupServiceClient> .Instance().get(); InitializeComponent(); targetPath = conf.targetPath.get(); se.threadCallback += ThreadMonitor; buildGraphic(); versionView.MouseDoubleClick += VersionView_MouseDoubleClick; revertList.MouseDoubleClick += VersionView_MouseDoubleClick; versionView.SelectedItemChanged += VersionView_SelectedItemChanged; }
public BackupProgress GetRestoreProgress() { BackupProgress result; var tenant = CoreContext.TenantManager.GetCurrentTenant(); using (var service = new BackupServiceClient()) { result = service.GetRestoreProgress(tenant.TenantId); } return(result); }
private async void RegisterButton_Click(object sender, RoutedEventArgs e) { string username = this.usernameTxtBox.Text; string password = this.passwordTxtBox.Password; Config conf = Config.Instance(); if (username.Equals("")) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Missing username! Username field cannot be empty."); return; } if (password.Equals("")) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Missing password! Password field cannot be empty."); return; } BackupServiceClient server = new BackupServiceClient(); string salt; try { salt = server.registerStep1(username); } catch { UsefullMethods.setLabelAlert("danger", this.errorBox, "No internet connection! Check it and retry"); return; } if (salt == null) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Username already choosen! Try another!"); return; } if (server.registerStep2(username, AuthenticationPrimitives.hashPassword(password, salt), salt)) { conf.targetPath.set(null); conf.userName.set(username); UsefullMethods.setLabelAlert("success", this.errorBox, "Registration succeed. You can log in now."); await Task.Delay(500); this.Hide(); this.parent.Activate(); this.parent.Show(); } else { UsefullMethods.setLabelAlert("danger", this.errorBox, "Registration procedure failed!"); } }
private static List <TransferRegion> GetRegions() { try { using (var backupClient = new BackupServiceClient()) { return(backupClient.GetTransferRegions()); } } catch { return(new List <TransferRegion>()); } }
public BackupProgress StartTransfer(string targetRegion, bool notifyUsers, bool transferMail) { DemandPermissions(); using (var service = new BackupServiceClient()) { return(service.StartTransfer( new StartTransferRequest { TenantId = GetCurrentTenantId(), TargetRegion = targetRegion, BackupMail = transferMail, NotifyUsers = notifyUsers })); } }
private void RegisterButton_Click(object sender, RoutedEventArgs e) { string username = this.usernameTxtBox.Text; string password = this.passwordTxtBox.Password; if (username.Equals("")) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Missing username! Username field cannot be empty."); return; } if (password.Equals("")) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Missing password! Password field cannot be empty."); return; } BackupServiceClient server = new BackupServiceClient(); string salt; try { salt = server.registerStep1(username); } catch { UsefullMethods.setLabelAlert("danger", this.errorBox, "No internet connection!Check it and retry"); return; } if (salt == null) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Username already choosen! Try another!"); return; } if (server.registerStep2(username, AuthenticationPrimitives.hashPassword(password, salt), salt)) { UsefullMethods.setLabelAlert("danger", this.errorBox, "Registration succeed. You can log in now."); Thread.Sleep(500); this.Hide(); this.parent.Activate(); this.parent.Show(); } else { UsefullMethods.setLabelAlert("danger", this.errorBox, "Registration procedure failed!"); } }
public void CreateSchedule(BackupStorageType storageType, StorageParams storageParams, int backupsStored, CronParams cronParams, bool backupMail) { DemandPermissionsBackup(); DemandSize(); if (!SetupInfo.IsVisibleSettings("AutoBackup")) { throw new InvalidOperationException(Resource.ErrorNotAllowedOption); } ValidateCronSettings(cronParams); var scheduleRequest = new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = backupMail, Cron = cronParams.ToString(), NumberOfBackupsStored = backupsStored, StorageType = storageType }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: scheduleRequest.StorageBasePath = storageParams.FolderId; break; case BackupStorageType.CustomCloud: ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection( new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); break; } using (var service = new BackupServiceClient()) { service.CreateSchedule(scheduleRequest); } }
public ProgressInfo StartTransfer(string targetRegion, bool notifyOnlyOwner, bool transferMail) { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.TransferPortal( new TransferRequest { TenantId = GetCurrentTenantId(), TargetRegion = targetRegion, BackupMail = transferMail, NotifyUsers = !notifyOnlyOwner }); return(ToProgressInfo(response)); } }
public BackupProgress StartTransfer(string targetRegion, bool notifyUsers, bool transferMail) { DemandPermissionsTransfer(); MessageService.Send(HttpContext.Current.Request, MessageAction.StartTransferSetting); using (var service = new BackupServiceClient()) { return(service.StartTransfer( new StartTransferRequest { TenantId = GetCurrentTenantId(), TargetRegion = targetRegion, BackupMail = transferMail, NotifyUsers = notifyUsers })); } }
public void CreateSchedule(BackupStorageType storageType, Dictionary <string, string> storageParams, int backupsStored, CronParams cronParams, bool backupMail) { DemandPermissionsBackup(); DemandSize(); if (!SetupInfo.IsVisibleSettings("AutoBackup")) { throw new InvalidOperationException(Resource.ErrorNotAllowedOption); } ValidateCronSettings(cronParams); var scheduleRequest = new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = backupMail, Cron = cronParams.ToString(), NumberOfBackupsStored = backupsStored, StorageType = storageType, StorageParams = storageParams }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: scheduleRequest.StorageBasePath = storageParams["folderId"]; break; case BackupStorageType.Local: if (!CoreContext.Configuration.Standalone) { throw new Exception("Access denied"); } scheduleRequest.StorageBasePath = storageParams["filePath"]; break; } using (var service = new BackupServiceClient()) { service.CreateSchedule(scheduleRequest); } }
private SyncEngine() { status = "Idle"; this.server = Const<BackupServiceClient>.Instance().get(); String dirPath = conf.targetPath.get(); threadCallback = new ThreadStatus(this.ThreadMonitor); watcher = new FileSystemWatcher(); watcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnChanged); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnChanged); watcher.Path = dirPath; // Begin watching. watcher.EnableRaisingEvents = true; //Directory.SetCurrentDirectory(dirPath); vb = new FBVersionBuilder(dirPath); }
public BackupRequest RequestBackup() { try { CheckPermission(); using (var client = new BackupServiceClient()) { var result = client.CreateBackup( TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID); return ToBackupRequest(result); } } catch (Exception e) { return new BackupRequest { Status = BackupRequestStatus.Error, FileLink = e.Message }; } }
public string CheckTransferProgress(string tenantID) { SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings); if (string.IsNullOrEmpty(tenantID)) { return(ToJsonSuccess(new BackupResult())); } try { using (var backupClient = new BackupServiceClient()) { BackupResult status = backupClient.GetTransferStatus(Convert.ToInt32(tenantID)); return(ToJsonSuccess(status)); } } catch (Exception error) { return(ToJsonError(error.Message)); } }
private SyncEngine() { status = "Idle"; this.server = Const <BackupServiceClient> .Instance().get(); String dirPath = conf.targetPath.get(); threadCallback = new ThreadStatus(this.ThreadMonitor); watcher = new FileSystemWatcher(); watcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnChanged); watcher.Deleted += new FileSystemEventHandler(OnChanged); watcher.Renamed += new RenamedEventHandler(OnChanged); watcher.IncludeSubdirectories = true; watcher.Path = dirPath; // Begin watching. watcher.EnableRaisingEvents = true; vb = new FBVersionBuilder(dirPath); }
public BackupProgress StartBackup(BackupStorageType storageType, StorageParams storageParams, bool backupMail) { DemandPermissionsBackup(); DemandSize(); var backupRequest = new StartBackupRequest { TenantId = GetCurrentTenantId(), UserId = SecurityContext.CurrentAccount.ID, BackupMail = backupMail, StorageType = storageType }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: backupRequest.StorageBasePath = storageParams.FolderId; break; case BackupStorageType.CustomCloud: backupRequest.StorageBasePath = storageParams.FilePath; ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection(new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); break; } MessageService.Send(HttpContext.Current.Request, MessageAction.StartBackupSetting); using (var service = new BackupServiceClient()) { return(service.StartBackup(backupRequest)); } }
private static List <TransferRegionWithName> GetRegions() { try { using (var backupClient = new BackupServiceClient()) { return(backupClient.GetTransferRegions() .Select(x => new TransferRegionWithName { Name = x.Name, IsCurrentRegion = x.IsCurrentRegion, BaseDomain = x.BaseDomain, FullName = TransferResourceHelper.GetRegionDescription(x.Name) }) .ToList()); } } catch { return(new List <TransferRegionWithName>()); } }
public void TestInitialize() { CleanUp(); String token; String username = "******"; String password = "******"; server = new BackupServiceClient(); server = MainWindow.logIn(username,password,out token); Const<BackupServiceClient>.Instance().set(server); if (!Directory.Exists(path)) { conf.targetPath.set(path); Directory.CreateDirectory(path); Directory.CreateDirectory(path+"\\ciao"); Directory.CreateDirectory(path + "\\ciao\\ciao"); string[] lines = { "First line", "Second line", "Third line" }; string[] lines1 = { "First line", "Second line", "Third lines" }; System.IO.File.WriteAllLines(path+"\\ciao\\uno.txt", lines); System.IO.File.WriteAllLines(path+"\\ciao\\due.txt", lines1); System.IO.File.WriteAllLines(path+"\\ciao\\ciao\\due.txt", lines); } }
public BackupRequest GetBackupStatus(string id) { try { CheckPermission(); using (var client = new BackupServiceClient()) { var result = client.GetBackupStatus(id); if (result == null) { throw GenerateException(HttpStatusCode.NotFound, "Not found", new Exception("item not found")); } return ToBackupRequest(result); } } catch (Exception e) { return new BackupRequest { Status = BackupRequestStatus.Error, FileLink = e.Message }; } }
public BackupRequest RequestBackup() { try { CheckPermission(); using (var client = new BackupServiceClient()) { var result = client.CreateBackup( TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID); return(ToBackupRequest(result)); } } catch (Exception e) { return(new BackupRequest { Status = BackupRequestStatus.Error, FileLink = e.Message }); } }
public BackupProgress StartRestore(string backupId, BackupStorageType storageType, StorageParams storageParams, bool notify) { DemandPermissionsRestore(); var restoreRequest = new StartRestoreRequest { TenantId = GetCurrentTenantId(), NotifyAfterCompletion = notify }; Guid guidBackupId; if (Guid.TryParse(backupId, out guidBackupId)) { restoreRequest.BackupId = guidBackupId; } else { restoreRequest.StorageType = storageType; restoreRequest.FilePathOrId = storageParams.FilePath; if (storageType == BackupStorageType.CustomCloud) { ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection(new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); } } using (var service = new BackupServiceClient()) { return(service.StartRestore(restoreRequest)); } }
public Schedule GetSchedule() { DemandPermissionsBackup(); using (var service = new BackupServiceClient()) { var response = service.GetSchedule(GetCurrentTenantId()); if (response == null) { return(null); } var schedule = new Schedule { StorageType = response.StorageType, StorageParams = new StorageParams(), CronParams = new CronParams(response.Cron), BackupMail = response.BackupMail, BackupsStored = response.NumberOfBackupsStored, LastBackupTime = response.LastBackupTime }; if (response.StorageType == BackupStorageType.CustomCloud) { var amazonSettings = CoreContext.Configuration.GetSection <AmazonS3Settings>(); schedule.StorageParams.AccessKeyId = amazonSettings.AccessKeyId; schedule.StorageParams.SecretAccessKey = amazonSettings.SecretAccessKey; schedule.StorageParams.Bucket = amazonSettings.Bucket; schedule.StorageParams.Region = amazonSettings.Region; } else { schedule.StorageParams.FolderId = response.StorageBasePath; } return(schedule); } }
public BackupProgress StartBackup(BackupStorageType storageType, Dictionary <string, string> storageParams, bool backupMail) { DemandPermissionsBackup(); DemandSize(); var backupRequest = new StartBackupRequest { TenantId = GetCurrentTenantId(), UserId = SecurityContext.CurrentAccount.ID, BackupMail = backupMail, StorageType = storageType, StorageParams = storageParams }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: backupRequest.StorageBasePath = storageParams["folderId"]; break; case BackupStorageType.Local: if (!CoreContext.Configuration.Standalone) { throw new Exception("Access denied"); } backupRequest.StorageBasePath = storageParams["filePath"]; break; } MessageService.Send(HttpContext.Current.Request, MessageAction.StartBackupSetting); using (var service = new BackupServiceClient()) { return(service.StartBackup(backupRequest)); } }
public override string Check(int tenantId) { try { log.Debug("CheckBackupState"); using (var backupServiceClient = new BackupServiceClient()) { var status = backupServiceClient.StartBackup(new StartBackupRequest { TenantId = tenantId, StorageType = BackupStorageType.DataStore }); try { while (!status.IsCompleted) { Thread.Sleep(1000); status = backupServiceClient.GetBackupProgress(tenantId); } } catch (Exception ex) { log.ErrorFormat("Backup is failed! {0} {1} {2}", status.Error, ex.Message, ex.StackTrace); return(HealthCheckResource.BackupServiceWorksIncorrectMsg); } log.Debug("Backup is OK!"); return(string.Empty); } } catch (Exception ex) { log.ErrorFormat("Backup is failed! {0} {1} {2}", ex.Message, ex.StackTrace, ex.InnerException != null ? ex.InnerException.Message : string.Empty); return(HealthCheckResource.BackupServiceWorksIncorrectMsg); } }
private void RegisterButton_Click(object sender, RoutedEventArgs e) { string username = this.usernameTxtBox.Text; string password = this.passwordTxtBox.Password; if (username.Equals("")) { MessageBox.Show(this, "Username cannot be empty!", "Missing username", MessageBoxButton.OK); return; } if (password.Equals("")) { MessageBox.Show(this, "Password cannot be empty!", "Missing password", MessageBoxButton.OK); return; } BackupServiceClient server = new BackupServiceClient(); string salt = server.registerStep1(username); if (salt == null) { MessageBox.Show(this, "Username already choosen! Try another!", "Registration problem", MessageBoxButton.OK); return; } if (server.registerStep2(username, AuthenticationPrimitives.hashPassword(password, salt), salt)) { MessageBox.Show(this, "Registration succeed. You can log in now.", "Registration succeed!", MessageBoxButton.OK); this.Hide(); this.parent.Activate(); this.parent.Show(); } else { MessageBox.Show(this, "Registration procedure failed!", "Error", MessageBoxButton.OK); } }
public BackupRequest GetBackupStatus(string id) { try { CheckPermission(); using (var client = new BackupServiceClient()) { var result = client.GetBackupStatus(id); if (result == null) { throw GenerateException(HttpStatusCode.NotFound, "Not found", new Exception("item not found")); } return(ToBackupRequest(result)); } } catch (Exception e) { return(new BackupRequest { Status = BackupRequestStatus.Error, FileLink = e.Message }); } }
private static List<TransferRegionWithName> GetRegions() { try { using (var backupClient = new BackupServiceClient()) { return backupClient.GetTransferRegions() .Select(x => new TransferRegionWithName { Name = x.Name, IsCurrentRegion = x.IsCurrentRegion, BaseDomain = x.BaseDomain, FullName = TransferResourceHelper.GetRegionDescription(x.Name) }) .ToList(); } } catch { return new List<TransferRegionWithName>(); } }
public void DeleteSchedule() { DemandPermissions(); using (var service = new BackupServiceClient()) { service.DeleteSchedule(GetCurrentTenantId()); } }
public string StartTransfer(string targetRegion, bool notify, bool backupmail) { SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings); if (!EnableMigration) return null; if (CurrentRegion.Equals(targetRegion, StringComparison.OrdinalIgnoreCase)) return ToJsonError(Resource.ErrorTransferPortalInRegion); try { using (var backupClient = new BackupServiceClient()) { var transferRequest = new TransferRequest { TenantId = TenantProvider.CurrentTenantID, TargetRegion = targetRegion, NotifyUsers = notify, BackupMail = backupmail }; return ToJsonSuccess(backupClient.TransferPortal(transferRequest)); } } catch (Exception error) { return ToJsonError(error.Message); } }
public BackupProgress StartTransfer(string targetRegion, bool notifyUsers, bool transferMail) { DemandPermissions(); using (var service = new BackupServiceClient()) { return service.StartTransfer( new StartTransferRequest { TenantId = GetCurrentTenantId(), TargetRegion = targetRegion, BackupMail = transferMail, NotifyUsers = notifyUsers }); } }
public Schedule GetSchedule() { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.GetSchedule(GetCurrentTenantId()); if (response == null) { return null; } var schedule = new Schedule { StorageType = response.StorageType, StorageParams = new StorageParams(), CronParams = new CronParams(response.Cron), BackupMail = response.BackupMail, BackupsStored = response.NumberOfBackupsStored, LastBackupTime = response.LastBackupTime }; if (response.StorageType == BackupStorageType.CustomCloud) { var amazonSettings = CoreContext.Configuration.GetSection<AmazonS3Settings>(); schedule.StorageParams.AccessKeyId = amazonSettings.AccessKeyId; schedule.StorageParams.SecretAccessKey = amazonSettings.SecretAccessKey; schedule.StorageParams.Bucket = amazonSettings.Bucket; schedule.StorageParams.Region = amazonSettings.Region; } else { schedule.StorageParams.FolderId = response.StorageBasePath; } return schedule; } }
public ProgressInfo StartTransfer(string targetRegion, bool notifyOnlyOwner, bool transferMail) { DemandPermissions(); using (var service = new BackupServiceClient()) { var response = service.TransferPortal( new TransferRequest { TenantId = GetCurrentTenantId(), TargetRegion = targetRegion, BackupMail = transferMail, NotifyUsers = !notifyOnlyOwner }); return ToProgressInfo(response); } }
private bool CheckStartupEnabled(TenantQuota currentQuota, TenantQuota startupQuota, out string errorMessage) { errorMessage = string.Empty; if (!currentQuota.Trial) { errorMessage = UserControlsCommonResource.SaasTariffErrorTrial; return(false); } if (TenantStatisticsProvider.GetUsersCount() > startupQuota.ActiveUsers) { errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorUsers, startupQuota.ActiveUsers); return(false); } if (TenantStatisticsProvider.GetVisitorsCount() > 0) { errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorGuests, 0); return(false); } var currentTenant = CoreContext.TenantManager.GetCurrentTenant(); var admins = WebItemSecurity.GetProductAdministrators(Guid.Empty); if (admins.Any(admin => admin.ID != currentTenant.OwnerId)) { errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorAdmins, 1); return(false); } if (TenantStatisticsProvider.GetUsedSize() > startupQuota.MaxTotalSize) { errorMessage = string.Format(UserControlsCommonResource.SaasTariffErrorStorage, FileSizeComment.FilesSizeToString(startupQuota.MaxTotalSize)); return(false); } var authServiceList = new AuthorizationKeys().AuthServiceList.Where(x => x.CanSet); foreach (var service in authServiceList) { if (service.Props.Any(r => !string.IsNullOrEmpty(r.Value))) { errorMessage = UserControlsCommonResource.SaasTariffErrorThirparty; return(false); } } if (!TenantWhiteLabelSettings.Load().IsDefault) { errorMessage = UserControlsCommonResource.SaasTariffErrorWhiteLabel; return(false); } if (!string.IsNullOrEmpty(currentTenant.MappedDomain)) { errorMessage = UserControlsCommonResource.SaasTariffErrorDomain; return(false); } var accountLinker = new AccountLinker("webstudio"); foreach (var user in CoreContext.UserManager.GetUsers(EmployeeStatus.All)) { var linkedAccounts = accountLinker.GetLinkedProfiles(user.ID.ToString()); if (linkedAccounts.Any()) { errorMessage = UserControlsCommonResource.SaasTariffErrorOauth; return(false); } } if (SsoSettingsV2.Load().EnableSso) { errorMessage = UserControlsCommonResource.SaasTariffErrorSso; return(false); } if (ActiveDirectory.Base.Settings.LdapSettings.Load().EnableLdapAuthentication) { errorMessage = UserControlsCommonResource.SaasTariffErrorLdap; return(false); } using (var service = new BackupServiceClient()) { var scheduleResponse = service.GetSchedule(currentTenant.TenantId); if (scheduleResponse != null) { errorMessage = UserControlsCommonResource.SaasTariffErrorAutoBackup; return(false); } } return(true); }
public BackupProgress StartRestore(string backupId, BackupStorageType storageType, StorageParams storageParams, bool notify) { DemandPermissions(); var restoreRequest = new StartRestoreRequest { TenantId = GetCurrentTenantId(), NotifyAfterCompletion = notify }; Guid guidBackupId; if (Guid.TryParse(backupId, out guidBackupId)) { restoreRequest.BackupId = guidBackupId; } else { restoreRequest.StorageType = storageType; restoreRequest.FilePathOrId = storageParams.FilePath; if (storageType == BackupStorageType.CustomCloud) { ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection(new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); } } using (var service = new BackupServiceClient()) { return service.StartRestore(restoreRequest); } }
public Schedule GetSchedule() { DemandPermissionsBackup(); ScheduleResponse response; using (var service = new BackupServiceClient()) { response = service.GetSchedule(GetCurrentTenantId()); if (response == null) { return(null); } } var schedule = new Schedule { StorageType = response.StorageType, StorageParams = response.StorageParams ?? new Dictionary <string, string>(), CronParams = new CronParams(response.Cron), BackupMail = response.BackupMail, BackupsStored = response.NumberOfBackupsStored, LastBackupTime = response.LastBackupTime }; if (response.StorageType == BackupStorageType.CustomCloud) { var amazonSettings = CoreContext.Configuration.GetSection <AmazonS3Settings>(); var consumer = ConsumerFactory.GetByName <DataStoreConsumer>("S3"); if (!consumer.IsSet) { consumer["acesskey"] = amazonSettings.AccessKeyId; consumer["secretaccesskey"] = amazonSettings.SecretAccessKey; consumer["bucket"] = amazonSettings.Bucket; consumer["region"] = amazonSettings.Region; } schedule.StorageType = BackupStorageType.ThirdPartyConsumer; schedule.StorageParams = consumer.AdditionalKeys.ToDictionary(r => r, r => consumer[r]); schedule.StorageParams.Add("module", "S3"); using (var service = new BackupServiceClient()) { service.CreateSchedule(new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = schedule.BackupMail, Cron = schedule.CronParams.ToString(), NumberOfBackupsStored = schedule.BackupsStored, StorageType = schedule.StorageType, StorageParams = schedule.StorageParams }); } } else if (response.StorageType != BackupStorageType.ThirdPartyConsumer) { schedule.StorageParams["folderId"] = response.StorageBasePath; } return(schedule); }
public void DeleteBackup(Guid id) { DemandPermissions(); using (var service = new BackupServiceClient()) { service.DeleteBackup(id); } }
public void CreateSchedule(BackupStorageType storageType, StorageParams storageParams, int backupsStored, CronParams cronParams, bool backupMail) { DemandPermissions(); ValidateCronSettings(cronParams); var scheduleRequest = new CreateScheduleRequest { TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId, BackupMail = backupMail, Cron = cronParams.ToString(), NumberOfBackupsStored = backupsStored, StorageType = storageType }; switch (storageType) { case BackupStorageType.ThridpartyDocuments: case BackupStorageType.Documents: scheduleRequest.StorageBasePath = storageParams.FolderId; break; case BackupStorageType.CustomCloud: ValidateS3Settings(storageParams.AccessKeyId, storageParams.SecretAccessKey, storageParams.Bucket, storageParams.Region); CoreContext.Configuration.SaveSection( new AmazonS3Settings { AccessKeyId = storageParams.AccessKeyId, SecretAccessKey = storageParams.SecretAccessKey, Bucket = storageParams.Bucket, Region = storageParams.Region }); break; } using (var service = new BackupServiceClient()) { service.CreateSchedule(scheduleRequest); } }
public BackupProgress GetBackupProgress() { using (var service = new BackupServiceClient()) { return service.GetBackupProgress(GetCurrentTenantId()); } }
public List<BackupHistoryRecord> GetBackupHistory() { DemandPermissions(); using (var service = new BackupServiceClient()) { return service.GetBackupHistory(GetCurrentTenantId()); } }
public string CheckTransferProgress(string tenantID) { SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings); if (string.IsNullOrEmpty(tenantID)) return ToJsonSuccess(new BackupResult()); try { using (var backupClient = new BackupServiceClient()) { BackupResult status = backupClient.GetTransferStatus(Convert.ToInt32(tenantID)); return ToJsonSuccess(status); } } catch (Exception error) { return ToJsonError(error.Message); } }