public IHttpActionResult Restore(DataRestore dti) { var tempLog = db.BackupRestoreLogs.ToList(); BackupRestoreLog bkrs = new BackupRestoreLog(); bkrs.OriDisk = dti.bk.OriDisk; bkrs.TimeBackup = dti.bk.TimeBackup; bkrs.Type = 2; bkrs.UserName = HttpContext.Current.User.Identity.Name; bkrs.TimeRestore = DateTime.Now; if (dti.dtb) { if (!File.Exists(dti.bk.LinkDatabase)) { return(BadRequest("Tệp tin sao lưu cơ sở dữ liệu không tồn tại. Vui lòng kiểm tra lại!")); } ExeRestoreDatabase(dti.bk.LinkDatabase); ReSaveLog(tempLog); bkrs.LinkDatabase = dti.bk.LinkDatabase; } if (dti.hsncc) { if (!NormalizePath(dti.bk.LinkDataNCC).EndsWith("DataNCC")) { return(BadRequest("Đường dẫn đến dữ liệu Hồ sơ NCC không hợp lệ! Đường dẫn phải kết thúc bởi thư mục DataNCC")); } if (!Directory.Exists(dti.bk.LinkDataNCC)) { return(BadRequest("Thư mục sao lưu hồ sơ người có công không tồn tại. Vui lòng kiểm tra lại!")); } DirectoryInfo src = new DirectoryInfo(dti.bk.LinkDataNCC); DirectoryInfo des = new DirectoryInfo(folderNCC); fileCopy = 0; ExeRestoreDataNCC(src, des); bkrs.LinkDataNCC = dti.bk.LinkDataNCC; } db.BackupRestoreLogs.Add(bkrs); db.SaveChanges(); return(Ok(new { fileCopy })); }
private async void StartRestore(string _user, string _TargetPath, CancellationToken token) { mtlstbxRestore.Items.Clear(); try { if (settings.SharedDevices) { ISharedResourceHelper regVal = new SharedResourceHelper(); regVal.OnNetworkPrintersRestoreStart += RegVal_OnNetworkPrintersRestoreStart; regVal.OnNetworkPrintersRestoreCompleted += RegVal_OnNetworkPrintersRestoreCompleted; regVal.OnNetworkSharesRestoreStart += RegVal_OnNetworkSharesRestoreStart; regVal.OnNetworkSharesRestoreCompleted += RegVal_OnNetworkSharesRestoreCompleted; regVal.OnRestoreStateChange += RegVal_OnRestoreStateChange; regVal.OnRestoreStateError += RegVal_OnRestoreStateError; await regVal.SetResourcesAsync(_user, _TargetPath, token); } IDataRestore dRval = new DataRestore(); dRval.OnDataRestoreStart += DRval_OnDataRestoreStart; dRval.OnDataRestoreComplete += DRval_OnDataRestoreComplete; dRval.OnCalculationStart += DRval_OnCalculationStart; dRval.OnAtomicCurrentCopyStatus += DRval_OnAtomicCurrentCopyStatus; dRval.OnAtomicTotalCounts += DRval_OnAtomicTotalCounts; switch (settings.BROperationType) { case "Auto": settings.ResourceUtilization = settings.ResourceUtilization; break; case "Full": switch (settings.ResourceUtilization) { case 4: settings.ResourceUtilization = 1; break; case 5: settings.ResourceUtilization = 2; break; case 6: settings.ResourceUtilization = 3; break; default: settings.ResourceUtilization = settings.ResourceUtilization; break; } break; case "Difference": switch (settings.ResourceUtilization) { case 1: settings.ResourceUtilization = 4; break; case 2: settings.ResourceUtilization = 5; break; case 3: settings.ResourceUtilization = 6; break; default: settings.ResourceUtilization = settings.ResourceUtilization; break; } break; } switch (settings.ResourceUtilization) { case 1: await dRval.RestoreAsync(regions, _TargetPath, _user, settings.LogOptions, settings.LogType, LogOperation.RestoreOperation, token); break; case 2: await dRval.RestorePartialParallelAsync(regions, _TargetPath, _user, settings.LogOptions, settings.LogType, LogOperation.RestoreOperation, token); break; case 3: await dRval.RestoreParallelAsync(regions, _TargetPath, _user, settings.LogOptions, settings.LogType, LogOperation.RestoreOperation, token); break; case 4: await dRval.DifferenceRestoreAsync(regions, _TargetPath, _user, settings.LogOptions, settings.LogType, LogOperation.RestoreOperation, token); break; case 5: await dRval.DifferenceRestorePartialParallelAsync(regions, _TargetPath, _user, settings.LogOptions, settings.LogType, LogOperation.RestoreOperation, token); break; case 6: await dRval.DifferenceRestoreParallelAsync(regions, _TargetPath, _user, settings.LogOptions, settings.LogType, LogOperation.RestoreOperation, token); break; default: await dRval.DifferenceRestoreAsync(regions, _TargetPath, _user, settings.LogOptions, settings.LogType, LogOperation.RestoreOperation, token); break; } } catch (OperationCanceledException OEx) { InitiatlizeUICancelled(OEx.Message); } catch (Exception Ex) { InitializeUIException(Ex.Message); } }