public ActionResult ExecuteVerify(PreservationVerifyIndexModel postedModel) { return(ActionResultHelper.TryCatchWithLogger(() => { PreservationVerifyExecuteModel model = new PreservationVerifyExecuteModel { fromDate = postedModel.fromDate, toDate = postedModel.toDate }; //crea l'elenco dei job di verifica 1 per conservazione chiusa List <PreservationVerifyJob> jobs = new List <PreservationVerifyJob>(); foreach (Guid idArchive in postedModel.selectedArchives.Select(s => Guid.Parse(s))) { //conservazioni chiuse per archivio DocumentArchive archive = ArchiveService.GetArchive(idArchive); IList <Preservation> preservations = _preservationService.ArchivePreservationClosedInDate(idArchive, postedModel.fromDate, postedModel.toDate.AddDays(1).AddSeconds(-1)); if (preservations.Count > 0) { jobs.AddRange(preservations.Select(p => new PreservationVerifyJob { idArchive = idArchive.ToString(), idPreservation = p.IdPreservation.ToString(), archiveName = archive.Name })); } else { jobs.Add(new PreservationVerifyJob { idArchive = idArchive.ToString(), idPreservation = Guid.Empty.ToString(), archiveName = archive.Name }); } } model.jobs = jobs.ToArray(); return View(model); }, _loggerService)); }
public async Task <ActionResult> DoVerify(PreservationVerifyExecuteModel model, CancellationToken cancellationToken) { return(await Task.Factory.StartNew(() => { return ActionResultHelper.TryCatchWithLogger(() => { ICollection <PreservationVerifyJob> jobResults = new List <PreservationVerifyJob>(); string cacheKey = $"{User.Identity.Name}_{model.executionId}"; if (!_cache_jobs.TryAdd(cacheKey, jobResults)) { _loggerService.Error("E' avvenuto un errore nella fase di inizializzazione della cache per i risultati di verifica conservazione"); throw new Exception("Errore in inizializzazione cache risultati"); } if (model == null || model.jobs == null || model.jobs.Length == 0) { _loggerService.Warn("Nessuna conservazione da verificare nel periodo indicato"); return Json(string.Empty); } ExecutePreservationVerifyInteractor interactor; ExecutePreservationVerifyRequestModel requestModel; foreach (PreservationVerifyJob job in model.jobs) { Preservation currentPreservation = _preservationService.GetPreservation(Guid.Parse(job.idPreservation), false); if (currentPreservation == null) { jobResults.Add(new PreservationVerifyJob() { idArchive = job.idArchive, archiveName = job.archiveName, idPreservation = job.idPreservation.ToString(), preservationLabel = "Nessuna conservazione da verificare nel periodo indicato", verifyTitle = string.Empty, result = "ok", errors = string.Empty }); _cache_jobs.AddOrUpdate(cacheKey, jobResults, (key, existingValue) => jobResults); continue; } interactor = new ExecutePreservationVerifyInteractor(_loggerService); requestModel = new ExecutePreservationVerifyRequestModel() { IdPreservation = Guid.Parse(job.idPreservation) }; ExecutePreservationVerifyResponseModel responseModel = interactor.Process(requestModel); jobResults.Add(new PreservationVerifyJob { idArchive = job.idArchive, archiveName = job.archiveName, idPreservation = responseModel.IdPreservation.ToString(), preservationLabel = $"Conservazione {currentPreservation.Label}", verifyTitle = responseModel.VerifyTitle, result = responseModel.Status == PreservationVerifyStatus.Ok ? "ok" : "bad", errors = string.Join("<br />", responseModel.Errors) }); _cache_jobs.AddOrUpdate(cacheKey, jobResults, (key, existingVal) => jobResults); } CreatePreservationVerifyReportInteractor reportInteractor = new CreatePreservationVerifyReportInteractor(_loggerService); model.jobs = jobResults.ToArray(); PreservationVerifyReportRequestModel reportRequestModel = new PreservationVerifyReportRequestModel() { VerifyModel = model }; PreservationVerifyReportResponseModel reportResponseModel = reportInteractor.Process(reportRequestModel); return Json(new { Jobs = jobResults, Response = reportResponseModel }); }, _loggerService); })); }