public Result Analyse() { Result result = new Result(); try { _log.Debug("Starting analysis..."); Stopwatch watch = Stopwatch.StartNew(); // get applications for analysis IEnumerable <ApplicationInfo> applicationsForAnalysis = _applicationRepository.GetAppInfoList(); _log.Debug($"'{applicationsForAnalysis?.Count()}' applications for analysis"); foreach (ApplicationInfo application in applicationsForAnalysis) { string appNumber = application.AppNumber; try { _log.Debug($"Start '{appNumber}'"); var oldFsResult = _fsService.CheckOnFs(appNumber, _oldFS); application.IsOnOldFs = oldFsResult.Item1; application.OldFsSize = oldFsResult.Item2; var newFsResult = _fsService.CheckOnFs(appNumber, _newFS); application.IsOnNewFs = newFsResult.Item1; application.NewFsSize = newFsResult.Item2; application.AnalyseStatus = "DONE"; _applicationRepository.UpdateAnalyseInfo(application); } catch (Exception ex) { _log.Error($"Ex for '{appNumber}': {ex.GetBaseException()}"); application.AnalyseStatus = "ERR"; application.AnalyseMessage = ex.GetBaseException().Message; _applicationRepository.UpdateAnalyseInfo(application); } } result.IsOk = true; result.Message = $"Done for '{applicationsForAnalysis.Count()}'."; _log.Debug($"Ending analysis -> for '{applicationsForAnalysis.Count()}' elapsed '{watch.Elapsed}'"); } catch (Exception ex) { _log.Error($"Global Ex occured: {ex.GetBaseException()}"); result.Message = ex.GetBaseException().ToString(); } return(result); }
public RescueAppResult StartMoving(int appCount) { RescueAppResult result = new RescueAppResult(); string source = _mainFs; string destination = _newFs; try { _log.Debug($"Starting moving for '{appCount}' apps..."); Stopwatch watch = Stopwatch.StartNew(); // get applications for moving IEnumerable <ApplicationInfo> applicationsForMoving = _applicationRepository.GetApplicationsForMoving(appCount); decimal totalMegabytesMoved = 0; int processedApplication = 1; int applicationsForMovingCount = applicationsForMoving?.Count() ?? 0; _log.Debug($"'{applicationsForMovingCount}' for moving"); foreach (ApplicationInfo application in applicationsForMoving) { string appNumber = application.AppNumber; try { _log.Debug($"{processedApplication}/{applicationsForMovingCount} - Start '{appNumber}'"); Duplex <bool, decimal?> destinationFsResult = _fsService.CheckOnFs(appNumber, destination); if (destinationFsResult.Item1 == true) { // exists on destination FS _log.Error($"'{appNumber}' exists on destination FS -> '{destination}'"); application.MoveStatus = "ERR"; application.MoveMessage = "Exists on destination FS"; _applicationRepository.UpdateMoveInfo(application); result.Applications.Add(new WniosekResult { ExistedOnOldFS = true, Message = application.MoveMessage, ApplicationNumber = appNumber }); } else { // local copy of directory //_fsService.CopyDirectory(appNumber, source, _localAppDir); // move from source FS to destination FS _fsService.MoveDirectory(appNumber, source, destination); // check size on destination FS after moving destinationFsResult = _fsService.CheckOnFs(appNumber, destination); decimal megabytesMoved = destinationFsResult.Item2 ?? 0; application.IsMoved = true; application.MoveStatus = "DONE"; application.MovedMb = megabytesMoved; totalMegabytesMoved += megabytesMoved; _applicationRepository.UpdateMoveInfo(application); result.Applications.Add(new WniosekResult { IsOk = true, Message = "OK", ApplicationNumber = appNumber }); } _log.Debug($"End for '{appNumber}'"); } catch (Exception ex) { string logErrorMsg = PrepareErrorMsg(ex, appNumber); _log.Error(logErrorMsg); application.MoveStatus = "ERR"; application.MoveMessage = logErrorMsg; _applicationRepository.UpdateMoveInfo(application); result.Applications.Add(new WniosekResult { Message = ex.GetBaseException().Message, ApplicationNumber = appNumber }); _notifyService.AddError(ex.GetBaseException().Message, ex.GetBaseException().StackTrace, $"{nameof(StartMoving)} Exception for appNumber = '{appNumber}': {logErrorMsg}"); } processedApplication++; } TimeSpan elapsed = watch.Elapsed; string logMsg = $"Moving ended for '{applicationsForMovingCount}' applications - correct '{result.Applications.Where(x => x.IsOk == true).Count()}' - elapsed '{elapsed}' - moved {totalMegabytesMoved} MB"; _log.Debug(logMsg); result.IsOk = true; result.Message = $"Ended successfully - moved {totalMegabytesMoved} MB!"; result.Elapsed = elapsed; _notifyService.AddError(result.Message, logMsg, logMsg); } catch (Exception ex) { _log.Error($"Global Ex occured: {ex.GetBaseException()}"); result.Message = ex.GetBaseException().ToString(); _notifyService.AddError(ex.GetBaseException().Message, ex.GetBaseException().StackTrace, $"{nameof(StartMoving)} Exception for source = '{source}' and destination = '{destination}'"); } return(result); }