protected void btnBackUp_Click(object sender, EventArgs e) { Timer1.Enabled = true; SetBtnEnable(false); SetDownloadFileDisplay(false); BackUpStatus bus = new BackUpStatus(); Session["DtStatus"] = bus; TransferRule tr = RulesPool.FindRuleByName(ddlAllRules.SelectedItem.Text); if (tr != null) { if (tr.GetNeedTimeFilter()) { DateTime startTime; DateTime endTime; if (!DateTime.TryParse(txtStartTime.Text, out startTime) || !DateTime.TryParse(txtEndTime.Text, out endTime)) { lblMessage.Text = _TimeNeed; Message.Visible = true; return; } TryRunBackUp(startTime, endTime, bus); } else { TryRunBackUp(null, null, bus); } } }
private void TryRunBackUp(DateTime?startTime, DateTime?endTime, BackUpStatus bs) { try { TransferService.BackUpData(ddlAllRules.SelectedItem.Text, startTime, endTime, bs); } catch (ApplicationException ae) { lblMessage.Text = ae.Message; } }
public void Test2() { //备份 BackUpStatus bs = new BackUpStatus(); bs.AddStatusChangeObserver(new MockInfoObserver()); TransferService.BackUpData("测试筛选式数据迁移", new DateTime(2008, 12, 1), new DateTime(2009, 3, 1), bs); Thread.Sleep(30000); Console.WriteLine(string.Format("状态:{0} 下载文件地址:{1}", bs.Status, bs.SuccessFileName)); Console.WriteLine(string.Format("起始时间:{0} 结束时间:{1}", bs.StartTime, bs.EndTime)); Assert.AreEqual(bs.Status, Status.Success); Assert.IsFalse(string.IsNullOrEmpty(bs.SuccessFileName)); //清空待还原的数据库 DeleteAllTableData(_Db1); Assert.AreEqual(0, GetCountOfTable("TApplication", _Db1)); Assert.AreEqual(0, GetCountOfTable("TApplicationEmployee", _Db1)); Assert.AreEqual(0, GetCountOfTable("TApplicationFlow", _Db1)); Assert.AreEqual(0, GetCountOfTable("TEmployee", _Db1)); DeleteAllTableData(_Db2); Assert.AreEqual(0, GetCountOfTable("TCustomer", _Db2)); //还原 RestoreStatus rs = new RestoreStatus(); rs.AddStatusChangeObserver(new MockInfoObserver()); TransferService.RestoreData(bs.SuccessFullFileName, rs); Thread.Sleep(30000); Console.WriteLine(string.Format("状态:{0}", rs.Status)); Console.WriteLine(string.Format("起始时间:{0} 结束时间:{1}", rs.StartTime, rs.EndTime)); Assert.AreEqual(rs.Status, Status.Success); Assert.AreEqual(118, GetCountOfTable("TEmployee", _Db1)); Assert.AreEqual(1052, GetCountOfTable("TCustomer", _Db2)); Assert.AreEqual(169, GetCountOfTable("TApplication", _Db1)); Assert.AreEqual(227, GetCountOfTable("TApplicationEmployee", _Db1)); Assert.AreEqual(343, GetCountOfTable("TApplicationFlow", _Db1)); _MockITransferDataLog.PrintLogs(); _MockITransferDataLog.ClearLogs(); }
protected void Timer1_Tick(object sender, EventArgs e) { BackUpStatus bus = Session["DtStatus"] as BackUpStatus; if (bus != null) { lblRunningStatus.Text = RunningStatus.StatusToString(bus.Status); txtRunningDetails.Text = bus.RunningDetails; if (bus.Status != Status.Running) { Timer1.Enabled = false; SetBtnEnable(true); } if (bus.Status == Status.Success) { hlDownloadFile.NavigateUrl = @"~\DownLoadDirectory\" + bus.SuccessFileName; SetDownloadFileDisplay(true); } } }
public void Test1() { //备份 BackUpStatus bs = new BackUpStatus(); bs.AddStatusChangeObserver(new MockInfoObserver()); TransferService.BackUpData("测试全覆盖式数据迁移", null, null, bs); Thread.Sleep(40000); Console.WriteLine(string.Format("状态:{0} 下载文件地址:{1}", bs.Status, bs.SuccessFileName)); Console.WriteLine(string.Format("起始时间:{0} 结束时间:{1}", bs.StartTime, bs.EndTime)); Assert.AreEqual(bs.Status, Status.Success); Assert.IsFalse(string.IsNullOrEmpty(bs.SuccessFileName)); //清空待还原的数据库 DeleteAllTableData(_Db1); DeleteAllTableData(_Db2); Assert.AreEqual(0, GetCountOfTable("TEmployee", _Db1)); Assert.AreEqual(0, GetCountOfTable("TCustomer", _Db2)); //还原数据 RestoreStatus rs = new RestoreStatus(); rs.AddStatusChangeObserver(new MockInfoObserver()); TransferService.RestoreData(bs.SuccessFullFileName, rs); Thread.Sleep(30000); Console.WriteLine(string.Format("状态:{0}", rs.Status)); Console.WriteLine(string.Format("起始时间:{0} 结束时间:{1}", rs.StartTime, rs.EndTime)); Assert.AreEqual(Status.Success, rs.Status); //测试数据是否还原成功 Assert.AreEqual(118, GetCountOfTable("TEmployee", _Db1)); Assert.AreEqual(1052, GetCountOfTable("TCustomer", _Db2)); _MockITransferDataLog.PrintLogs(); _MockITransferDataLog.ClearLogs(); }