public override async Task Restore(DbRestorOptions opt, IProgressBarProvider progressBarProvider, Action additionalCallbackOnCompleted) { await Task.Run(() => { var srv = new Server(opt.SqlServerInstName); if (srv.Databases.Contains(opt.TargetDbName)) { srv.KillDatabase(opt.TargetDbName); } var res = new Restore(); srv.ConnectionContext.StatementTimeout = 0; res.Devices.AddDevice(opt.SrcPath, DeviceType.File); res.Database = opt.TargetDbName; res.Action = RestoreActionType.Database; res.PercentCompleteNotification = 1; res.ReplaceDatabase = true; res.Complete += (sender, args) => { if (res.AsyncStatus.ExecutionStatus == ExecutionStatus.Failed) { progressBarProvider.OnError(args.Error.ToString()); return; } progressBarProvider.OnCompleted(FinishedRestore); additionalCallbackOnCompleted?.Invoke(); }; res.PercentComplete += (sender, args) => { if (res.AsyncStatus.ExecutionStatus == ExecutionStatus.Failed) { progressBarProvider.OnError(res.AsyncStatus.LastException.ToString()); } // give 10% for the recovering which happens after restoring. const double weightOfRestoring = 90.0 / 100.0; progressBarProvider.ReportProgress((int)(args.Percent *weightOfRestoring)); }; var fileList = res.ReadFileList(srv); var dataFile = new RelocateFile( logicalFileName: fileList.Rows[0][0].ToString(), physicalFileName: opt.RelocateMdfTo ); var logFile = new RelocateFile( logicalFileName: fileList.Rows[1][0].ToString(), physicalFileName: opt.RelocateLdfTo ); res.RelocateFiles.Add(dataFile); res.RelocateFiles.Add(logFile); res.ContinueAfterError = false; progressBarProvider.Start(true, "Restoring..."); res.SqlRestoreAsync(srv); }); }
public SqlInstancesVm(ISqlServerUtil util, IProgressBarProvider progressBarProvider, IUserPreferencePersist userPreference) { Instances = new ObservableCollection <string>(); DbNames = new ObservableCollection <string>(); _util = util; _ProgressBarProvider = progressBarProvider; _userPreference = userPreference; }
public void Setup() { _sqlServerUtil = Substitute.For <ISqlServerUtil>(); _sqlServerUtil.GetSqlInstances().Returns(Instances); _progressBarProvider = Substitute.For <IProgressBarProvider>(); _userPrefPersist = Substitute.For <IUserPreferencePersist>(); _userPrefPersist.LoadPreference().Returns(new UserPreference()); _vm = new SqlInstancesVm(_sqlServerUtil, _progressBarProvider, _userPrefPersist); }
public void Setup() { _progressBarProvider = Substitute.For <IProgressBarProvider>(); _userPrefPersist = Substitute.For <IUserPreferencePersist>(); _userPrefPersist.LoadPreference().Returns(new UserPreference()); }
public void Restore(ISqlServerUtil.DbRestorOptions opt, IProgressBarProvider progressBarProvider, Action additionalCallbackOnCompleted) { _sqlUtil.Restore(opt, progressBarProvider, additionalCallbackOnCompleted); }
public abstract Task Restore(DbRestorOptions dbRestorOptions, IProgressBarProvider progressBarProvider, Action additionalCallbackOnCompleted);